Chia contains HelperFunctions for reporting. Chia contains some Azure Storage functions, logging features and some excel utils.
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" AzureYou 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 msgHelper 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 connectedHelper to create a Azure blobs:
First create your blob container:
open Chia.CreateBlob
let containerInfo = { StorageConnString = StorageConnString = StorageAccount.storageConnString
ContainerName = "ContainerName"}
let myContainer = getContainer containerInfoNow you can get a list of all you blobs in the container like this:
let blobItems = getBlobs myContainerHelper 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) azureTableGet 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 azureTableYou can also get all values by one rowKey like this:
let valuesByRowKey = getValuesByRowKey rowKey mapper azureTableIf 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) azureTableHelper 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 getPlantsMini Helper to start and ExcelApp using the EPPlus package:
Start your excel app like this:
let excelPackage = startExcelApp ()