Exemple #1
0
        public static void Run([EventGridTrigger] EventGridEvent eventGridEvent, ILogger log)
        {
            // todo: break into private methods for readability + maybe wrapper for this if not succesful report client pattern
            var imageStoredEvent   = EventGridService.MapToEventType <ImageStoredEvent>(eventGridEvent);
            var repositoryResponse = ImagesStorageService.LoadImage(imageStoredEvent.ObjectId, imageStoredEvent.SessionId, imageStoredEvent.PartitionKey).Result;

            if (!repositoryResponse.WasSuccessful)
            {
                ErrorReporting.ReportErrorToClient(repositoryResponse.Message);
            }

            var analysisResponse = AnalysisService.AnalyseImage(repositoryResponse.Content, imageStoredEvent.SessionId).Result;

            if (!analysisResponse.WasSuccessful)
            {
                ErrorReporting.ReportErrorToClient(analysisResponse.Message);
            }

            var analysisStorageResponse = AnalysisService.StoreAnalysisData(analysisResponse.Content, imageStoredEvent.ObjectId, imageStoredEvent.SessionId, imageStoredEvent.PartitionKey).Result;

            if (!analysisStorageResponse.WasSuccessful)
            {
                ErrorReporting.ReportErrorToClient(analysisStorageResponse.Message);
            }

            var raiseAnalysisSompletedEvent = AnalysisService.RaiseAnalysisCompleteEvent(
                analysisStorageResponse.Content, imageStoredEvent.SessionId, imageStoredEvent.CommandId, imageStoredEvent.PartitionKey).Result;

            if (!raiseAnalysisSompletedEvent.WasSuccessful)
            {
                ErrorReporting.ReportErrorToClient(raiseAnalysisSompletedEvent.Message);
            }

            var workflowUpdateResult = WorkflowSessionService.StoreSessionCommandResult(
                imageStoredEvent.SessionId, imageStoredEvent.CommandId, analysisStorageResponse.Content.id,
                imageStoredEvent.PartitionKey, CommandStatus.CompletedSuccesfully).Result;

            if (!workflowUpdateResult.WasSuccessful)
            {
                ErrorReporting.ReportErrorToClient(workflowUpdateResult.Message);
            }
        }