示例#1
0
        public static async Task RunAsync([QueueTrigger("callbackstoragequeue", Connection = "StorageAccountConnectionString")] string myQueueItem, ILogger log)
        {
            log.LogInformation($"ProcessCallbackItem Started");

            Model.CallbackItem cbItem = JsonSerializer.Deserialize <Model.CallbackItem>(myQueueItem);
            Utilities.ProcessCallbackItem(cbItem);
        }
        public static async void ProcessCallbackItem(Model.CallbackItem cbItem)
        {
            var config = GetConfig();
            var client = await GetHttpClient(config);

            var response = await client.GetStringAsync(cbItem.contentUri);

            Model.AuditItem[] auditItems = JsonSerializer.Deserialize <Model.AuditItem[]>(response);
            var sitesToCapture           = getSitesToCapture();
            var siteDictionary           = new Dictionary <string, string>();

            foreach (var siteToCapture in sitesToCapture)
            {
                siteDictionary.Add(siteToCapture.SiteId, siteToCapture.EventsToCapture);
            }
            QueueClient queueClient = new QueueClient(config["StorageAccountConnectionString"], config["AuditQueueName"]);

            // Create the queue if it doesn't already exist
            queueClient.CreateIfNotExists();

            foreach (Model.AuditItem auditItem in auditItems)
            {
                if (auditItem.Site != null && siteDictionary.ContainsKey(auditItem.Site) && (siteDictionary[auditItem.Site].Contains(auditItem.Operation) || siteDictionary[auditItem.Site] == "*"))
                {
                    if (queueClient.Exists())
                    {
                        queueClient.SendMessage(Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes((string)JsonSerializer.Serialize(auditItem))));
                    }
                }
            }
        }