Esempio n. 1
0
        public static async Task Run(
            [QueueTrigger("transmission-faults", Connection = "AzureWebJobsStorage")] string fault,
            IBinder blobFaultBinder,
            ILogger log)
        {
            TransmissionFaultMessage faultData = JsonConvert.DeserializeObject <TransmissionFaultMessage>(fault);

            CloudBlockBlob blobReader = await blobFaultBinder.BindAsync <CloudBlockBlob>(
                new BlobAttribute($"transmission-faults/{faultData.id}", FileAccess.ReadWrite));

            string json = await blobReader.DownloadTextAsync();

            try
            {
                List <string> faultMessages = await Task <List <string> > .Factory.StartNew(() => JsonConvert.DeserializeObject <List <string> >(json));

                await Utils.SendEvents(faultMessages, log);
            }
            catch
            {
                log.LogError($"FaultProcessor failed to send: {faultData.id}");
                return;
            }

            await blobReader.DeleteAsync();

            log.LogInformation($"C# Queue trigger function processed: {faultData.id}");
        }
        private static async Task LogFailuresToAzureStuff <T>(IBinder blobFaultBinder, Binder queueFaultBinder, ILogger log, List <string> parsedMessages, Exception exEmit)
        {
            string id = Guid.NewGuid().ToString();

            log.LogError($"Failed to write the fault queue: {id}. {exEmit}");

            try
            {
                CloudBlockBlob blobWriter = await blobFaultBinder.BindAsync <CloudBlockBlob>(new BlobAttribute($"transmission-faults/{id}", FileAccess.ReadWrite));

                string json = await Task <string> .Factory.StartNew(() => JsonConvert.SerializeObject(parsedMessages));

                await blobWriter.UploadTextAsync(json);
            }
            catch (Exception exFaultBlob)
            {
                log.LogError($"Failed to write the fault blob: {id}. {exFaultBlob}");
            }

            try
            {
                TransmissionFaultMessage qMsg = new TransmissionFaultMessage {
                    id = id, type = typeof(T).ToString()
                };
                string qMsgJson = JsonConvert.SerializeObject(qMsg);

                CloudQueue queueWriter = await queueFaultBinder.BindAsync <CloudQueue>(new QueueAttribute("transmission-faults"));

                await queueWriter.AddMessageAsync(new CloudQueueMessage(qMsgJson));
            }
            catch (Exception exFaultQueue)
            {
                log.LogError($"Failed to write the fault queue: {id}. {exFaultQueue}");
            }
        }