Esempio n. 1
0
        public static async Task ProcessAllMessages([ServiceBusTrigger("%ServiceBusTopicName%", "%ServiceBusSubscriptionName%", Connection = "ServiceBusConnectionString")] string mySbMsg,
                                                    [Blob("receipts/all/{rand-guid}.json", FileAccess.Write, Connection = "DestinationStorageConnectionString")] CloudBlockBlob output,
                                                    ILogger log)
        {
            log.LogInformation($"ProcessAllMessagesFunction - ServiceBus topic trigger function processed message: {mySbMsg}");

            ReceiptData receiptInfo = BuildReceipt(mySbMsg);

            // Save receipt JSON to blob
            await output.UploadTextAsync(JsonConvert.SerializeObject(receiptInfo));
        }
Esempio n. 2
0
        private static ReceiptData BuildReceipt(string message)
        {
            dynamic receipt = JObject.Parse(message);

            ReceiptData receiptInfo = new ReceiptData()
            {
                ItemCount     = (int)receipt["ItemCount"],
                LocationId    = (string)receipt["LocationId"],
                SalesDateTime = DateTime.Parse((string)receipt["SalesDateTime"]),
                SalesNumber   = (string)receipt["SalesNumber"],
                TotalCost     = (double)receipt["TotalCost"]
            };

            return(receiptInfo);
        }
Esempio n. 3
0
        public static async Task ProcessFilteredMessages([ServiceBusTrigger("%ServiceBusTopicName%", "%ServiceBusFilteredSubscriptionName%", Connection = "ServiceBusConnectionString")] string mySbMsg,
                                                         [Blob("receipts/high-value/{rand-guid}.json", FileAccess.Write, Connection = "DestinationStorageConnectionString")] CloudBlockBlob output,
                                                         ILogger log)
        {
            log.LogInformation($"ProcessFilteredMessagesFunction - ServiceBus topic trigger function processed message: {mySbMsg}");

            ReceiptData receiptInfo = BuildReceipt(mySbMsg);

            dynamic receipt    = JObject.Parse(mySbMsg);
            string  receiptUrl = (string)receipt["ReceiptUrl"];

            byte[] receiptBytes = await GetReceiptFromUrl(receiptUrl);

            receiptInfo.ReceiptImageBase64 = Convert.ToBase64String(receiptBytes);

            // Save receipt JSON to blob
            await output.UploadTextAsync(JsonConvert.SerializeObject(receiptInfo));
        }