Skip to content
/ Chia Public
forked from DanpowerGruppe/Chia

Chia - HelperFunctions for reporting

License

Notifications You must be signed in to change notification settings

ButA1/Chia

 
 

Repository files navigation

Chia - HelperFunctions for reporting

Build Status

nuget - Chia

nuget - ChiaClient

Chia contains HelperFunctions for reporting. Chia contains some Azure Storage functions, logging features and some excel utils.

FileWriter

Initialize your FileWriter instant with initFileWriter:

open Chia.Domain.Logging
open Chia.Domain.Config
open Chia.FileWriter
let devStatus = Development
let fileWriterInfo = initFileWriter devStatus "ProjectName" Local
let fileWriterInfoAzure = initFileWriter devStatus "PIvy" Azure

You can now use an logOk and logError like this:

logOk fileWriterInfo ("Something went ok!")
try
    let trySomething = unsafe ()
with
| exn ->
    let msg = sprintf  "Your error message: %s" exn.Message
    logError exn fileWriterInfo msg  //or use fileWriterInfoAzure for logging to Azure
    failwith msg

CreateTable

Helper to create a Azure table:

First connect to your storage account:

open Chia.CreateTable
let connected =
    let connection = AzureConnection StorageAccount.storageConnString
    connection.Connect()

Now you can create your Azure table like this:

let azureTable = getTable "TableName" fileWriterInfoAzure connected

CreateBlob

Helper to create a Azure blobs:

First create your blob container:

open Chia.CreateBlob
let containerInfo = {   StorageConnString = StorageConnString = StorageAccount.storageConnString
                        ContainerName = "ContainerName"}
let myContainer = getContainer containerInfo

Now you can get a list of all you blobs in the container like this:

let blobItems = getBlobs myContainer

GetTableEntry

Helper to query a Azure tables:

With the GetTableEntry module you can easily query Azure Tables.

Get just on single tableValue like this:

let value = getValue (request.PartKey, request.RowKey) azureTable

Get all values in a table by using a table mapper. First you have to define you mapper:

type Mapper = {
    PartKey : string
    RowKey : Ids.SortableRowKey
}

let mapper (entity : DynamicTableEntity) : Mapper =
    { PartyKey = entity.PartitionKey
      RowKey = SortableRowKey entity.RowKey

let values = getValues mapper azureTable

You can also get all values by one rowKey like this:

let valuesByRowKey = getValuesByRowKey rowKey mapper azureTable

If you want to create more complex queries you can just parse in a TableQuery Filter.

First define your filter:

let filter partKey = TableQuery.GenerateFilterCondition("PartitionKey", QueryComparisons.Equal, partKey)
let filteredValues partKey = getValuesWithFilter (filter partKey) azureTable

RedisCache

Helper to create or directly query a RedisCache:

To create or read a Redis values with a Redis Key you first have to create a Redis cache info:

let cacheInfo : RedisCache = {
    Cache = Redis.cache
    Key = key
    FileWriterInfo = fileWriterInfo }

To deserialze your Redis values to your pass in a Newtonsoft mapper. You also should pass in a task to receive your data. The function tries to find the cache in Redis. If there is no Redis cache it will create a new cache by executing you task. The following example showes how to reveice a a Plant array directly out of Redis or creates a new cache if theres no existing cache and returns the Plant array.

let! plants = tryGetCachedData JsonConvert.DeserializeObject<Plant[]> cacheInfo getPlants

ExcelUtils

Mini Helper to start and ExcelApp using the EPPlus package:

Start your excel app like this:

let excelPackage = startExcelApp ()

About

Chia - HelperFunctions for reporting

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • F# 99.8%
  • Batchfile 0.2%