Exemplo n.º 1
0
        public async Task ManageExceptions(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            ILogger logger
            )
        {
            CustomEventData inputEventData =
                ((JObject)eventGridEvent.Data).ToObject <CustomEventData>();

            var correlationId = LoggingHelper.GetCorrelationId(inputEventData);

            #region Logging
            logger.LogInformation(
                new EventId((int)LoggingConstants.EventId.ManageExeceptionsStarted),
                LoggingConstants.Template,
                LoggingConstants.EventId.ManageExeceptionsStarted.ToString(),
                correlationId,
                LoggingConstants.ProcessingFunction.ManageExeceptions.ToString(),
                LoggingConstants.ProcessStatus.Started.ToString(),
                "Execution started"
                );
            #endregion

            await _blobHandler
            .CopyBlobAcrossContainerWithUrlsAsync(inputEventData.ImageUrl, _options.CompensationContainerName)
            .ConfigureAwait(false);

            #region Logging

            logger.LogInformation(
                new EventId((int)LoggingConstants.EventId.ManageExeceptionsFinished),
                LoggingConstants.Template,
                LoggingConstants.EventId.ManageExeceptionsFinished.ToString(),
                correlationId,
                LoggingConstants.ProcessingFunction.ManageExeceptions.ToString(),
                LoggingConstants.ProcessStatus.Finished.ToString(),
                "Execution Finished"
                );
            #endregion
        }
        public async Task DetectAndBlurFaces(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            ILogger logger
            )
        {
            CustomEventData inputEventData =
                ((JObject)eventGridEvent.Data).ToObject <CustomEventData>();

            var correlationId = LoggingHelper.GetCorrelationId(inputEventData);

            #region Logging

            logger.LogInformation(
                new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesStarted),
                LoggingConstants.Template,
                LoggingConstants.EventId.DetectAndBlurFacesStarted.ToString(),
                correlationId,
                LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(),
                LoggingConstants.ProcessStatus.Started,
                "Execution Started"
                );

            #endregion

            CustomEventData outputEventData = new CustomEventData
            {
                ImageUrl             = inputEventData.ImageUrl,
                TicketNumber         = inputEventData.TicketNumber,
                DistrictOfInfraction = inputEventData.DistrictOfInfraction,
                DateOfInfraction     = inputEventData.DateOfInfraction
            };

            try
            {
                var detectedFaces = await _faceHandler
                                    .DetectFacesWithUrlAsync(inputEventData.ImageUrl)
                                    .ConfigureAwait(false);

                var imageBytes = await _blobHandler
                                 .DownloadBlobAsync(inputEventData.ImageUrl)
                                 .ConfigureAwait(false);

                var blurredImageBytes = await _faceHandler
                                        .BlurFacesAsync(imageBytes, detectedFaces.ToList());

                using (MemoryStream ms = new MemoryStream(blurredImageBytes))
                {
                    await _blobHandler.UploadStreamAsBlobAsync(
                        containerName : _options.BlurredImageContainerName,
                        stream : ms,
                        contentType : _options.UploadContentType,
                        blobName : BlobHelper.GetBlobNameWithExtension(inputEventData.TicketNumber)
                        )
                    .ConfigureAwait(false);
                }

                outputEventData.CustomEvent = CustomEvent.FaceDetectionAndBlurringCompleted.ToString();

                #region Logging

                logger.LogInformation(
                    new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesFinished),
                    LoggingConstants.Template,
                    LoggingConstants.EventId.DetectAndBlurFacesFinished.ToString(),
                    correlationId,
                    LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(),
                    LoggingConstants.ProcessStatus.Finished,
                    "Execution Finished"
                    );

                #endregion
            }
            catch (Exception ex)
            {
                outputEventData.CustomEvent = CustomEvent.Exceptioned.ToString();

                #region Logging

                logger.LogInformation(
                    new EventId((int)LoggingConstants.EventId.DetectAndBlurFacesFinished),
                    LoggingConstants.Template,
                    LoggingConstants.EventId.DetectAndBlurFacesFinished.ToString(),
                    correlationId,
                    LoggingConstants.ProcessingFunction.DetectAndBlurFaces.ToString(),
                    LoggingConstants.ProcessStatus.Failed,
                    $"Execution Failed. Reason: {ex.Message}"
                    );

                #endregion
            }


            await _eventhandler.PublishEventToTopicAsync(outputEventData)
            .ConfigureAwait(false);
        }
Exemplo n.º 3
0
        public async Task CreateTicket(
            [EventGridTrigger] EventGridEvent eventGridEvent,
            ILogger logger
            )
        {
            CustomEventData inputEventData =
                ((JObject)eventGridEvent.Data).ToObject <CustomEventData>();

            CustomEventData outputEventData = new CustomEventData
            {
                ImageUrl             = inputEventData.ImageUrl,
                TicketNumber         = inputEventData.TicketNumber,
                DistrictOfInfraction = inputEventData.DistrictOfInfraction,
                DateOfInfraction     = inputEventData.DateOfInfraction
            };

            var correlationId = LoggingHelper.GetCorrelationId(inputEventData);

            #region Logging

            logger.LogInformation(
                new EventId((int)LoggingConstants.EventId.CreateSpeedingTicketStarted),
                LoggingConstants.Template,
                LoggingConstants.EventId.CreateSpeedingTicketStarted.ToString(),
                correlationId,
                LoggingConstants.ProcessingFunction.CreateSpeedingTicket.ToString(),
                LoggingConstants.ProcessStatus.Started.ToString(),
                "Execution Started"
                );

            #endregion


            try
            {
                await _dmvDbHandler
                .CreateSpeedingTicketAsync(
                    ticketNumber : inputEventData.TicketNumber,
                    vehicleRegistrationNumber : inputEventData.VehicleRegistrationNumber,
                    district : inputEventData.DistrictOfInfraction,
                    date : inputEventData.DateOfInfraction
                    )
                .ConfigureAwait(false);

                outputEventData.CustomEvent = CustomEvent.SpeedingTicketCreated.ToString();

                #region Logging

                logger.LogInformation(
                    new EventId((int)LoggingConstants.EventId.CreateSpeedingTicketFinished),
                    LoggingConstants.Template,
                    LoggingConstants.EventId.CreateSpeedingTicketFinished.ToString(),
                    correlationId,
                    LoggingConstants.ProcessingFunction.CreateSpeedingTicket.ToString(),
                    LoggingConstants.ProcessStatus.Finished.ToString(),
                    "Execution Finished"
                    );

                #endregion
            }
            catch (Exception ex)
            {
                outputEventData.CustomEvent = CustomEvent.Exceptioned.ToString();

                #region Logging

                logger.LogInformation(
                    new EventId((int)LoggingConstants.EventId.CreateSpeedingTicketFinished),
                    LoggingConstants.Template,
                    LoggingConstants.EventId.CreateSpeedingTicketFinished.ToString(),
                    correlationId,
                    LoggingConstants.ProcessingFunction.CreateSpeedingTicket.ToString(),
                    LoggingConstants.ProcessStatus.Failed.ToString(),
                    $"Execution Failed. Reason: {ex.Message}"
                    );

                #endregion
            }

            await _eventHandler.PublishEventToTopicAsync(outputEventData)
            .ConfigureAwait(false);
        }