public async Task <FoxyResponse <FoxyWorkflowSession> > StoreSessionCommandResult(
            Guid sessionId, Guid commandId, Guid resultEntityId, string partitionKey, CommandStatus status)
        {
            try
            {
                var workflowSession = await WorkflowsDbGateway.LoadFoxyWorkflowSession(sessionId, partitionKey);

                var commandResult = workflowSession.AwaitableCommandResults.SingleOrDefault(r => r.CommandId == commandId);

                if (commandResult == null)
                {
                    throw new Exception($"Unable to find command result {commandId}");
                }

                commandResult.CommandStatus    = status;
                commandResult.ResultIdentifier = resultEntityId;

                workflowSession = await WorkflowsDbGateway.UpdateCommandResult(workflowSession);

                return(FoxyResponse <FoxyWorkflowSession> .Success(workflowSession));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <FoxyWorkflowSession> .Failure("There was a problem while updating operation status"));
            }
        }
 public async Task <FoxyResponse <SendGridMessage> > CreateAnalysisCompletedEmail(string userEmail, ImageAnalysisData analysisResult)
 {
     try
     {
         var message = SendGridMessageFactory.CreateAnalysisCompletedMessage(userEmail, analysisResult);
         return(FoxyResponse <SendGridMessage> .Success(message));
     }
     catch (Exception e)
     {
         ErrorReporting.StoreExceptionDetails(e, analysisResult.id);
         return(FoxyResponse <SendGridMessage> .Failure("Could not store image analysis results"));
     }
 }
Esempio n. 3
0
        public async Task <FoxyResponse <ImageData> > LoadImage(Guid imageId, Guid sessionId, string partitionKey)
        {
            try
            {
                var imageData = await ImagesDbGateway.GetImageById(imageId, partitionKey);

                return(FoxyResponse <ImageData> .Success(imageData));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <ImageData> .Failure("Unable to load image from the data store"));
            }
        }
Esempio n. 4
0
        public async Task <FoxyResponse <ImageAnalysisData> > AnalyseImage(ImageData imageData, Guid sessionId)
        {
            try
            {
                var analysisResult = await VisionApiGateway.AnalyzeBytes(imageData.Bytes, sessionId);

                return(FoxyResponse <ImageAnalysisData> .Success(analysisResult));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <ImageAnalysisData> .Failure("There was a problem while analysing the image"));
            }
        }
Esempio n. 5
0
        public async Task <FoxyResponse <ImageAnalysisData> > LoadImagaAnalysisData(Guid analysisResultId, string partitionKey)
        {
            try
            {
                var analysisResult = await AnalysisDbGateway.LoadImagaAnalysisData(analysisResultId, partitionKey);

                return(FoxyResponse <ImageAnalysisData> .Success(analysisResult));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, analysisResultId);
                return(FoxyResponse <ImageAnalysisData> .Failure("There was a problem while retreiving operation status"));
            }
        }
        public async Task <FoxyResponse <FoxyWorkflowSession> > StoreSession(FoxyWorkflowSession workflowSession)
        {
            try
            {
                workflowSession = await WorkflowsDbGateway.StoreWorkflowSession(workflowSession);

                return(FoxyResponse <FoxyWorkflowSession> .Success(workflowSession));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, Guid.Empty);
                return(FoxyResponse <FoxyWorkflowSession> .Failure("There was a problem while storing workflow session"));
            }
        }
        public async Task <FoxyResponse <AwaitableCommandResult> > LoadSessionCommandResult(Guid sessionId, Guid commandId, string partitionKey)
        {
            try
            {
                var workflowSession = await WorkflowsDbGateway.LoadFoxyWorkflowSession(sessionId, partitionKey);

                var requestedCommand = workflowSession.AwaitableCommandResults.Single(r => r.CommandId == commandId);
                return(FoxyResponse <AwaitableCommandResult> .Success(requestedCommand));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <AwaitableCommandResult> .Failure("There was a problem while retreiving operation status"));
            }
        }
        public async Task <FoxyResponse <AwaitableCommandResult> > CreateAwaitableCommandResultsInScopeOfSession(FoxyWorkflowSession workflowSession)
        {
            try
            {
                var awaitableCommandResult = AwaitableCommandResult.Create(workflowSession.id);
                workflowSession.AwaitableCommandResults.Add(awaitableCommandResult);

                return(FoxyResponse <AwaitableCommandResult> .Success(awaitableCommandResult));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, workflowSession.id);
                return(FoxyResponse <AwaitableCommandResult> .Failure("There was a problem while preparing workflow session"));
            }
        }
Esempio n. 9
0
        public async Task <FoxyResponse <ImageAnalysisData> > StoreAnalysisData(ImageAnalysisData imageAnalysisData, Guid imageId, Guid sessionId, string partitionKey)
        {
            try
            {
                imageAnalysisData.RelatedImageObjectId = imageId;
                imageAnalysisData.partitionKey         = partitionKey;
                var storeResult = await AnalysisDbGateway.StoreAnalysisData(imageAnalysisData);

                return(FoxyResponse <ImageAnalysisData> .Success(storeResult));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <ImageAnalysisData> .Failure("Could not store image analysis results"));
            }
        }
Esempio n. 10
0
        public FoxyResponse <ImageData> ExtractSingleImageFromRequest(HttpRequest request, Guid sessionId)
        {
            try
            {
                var result   = new ImageData();
                var formFile = request.Form.Files[0];

                result.Name = ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim().Value;
                using (var reader = new BinaryReader(formFile.OpenReadStream()))
                {
                    result.Bytes = reader.ReadBytes(Convert.ToInt32(formFile.Length));
                }

                return(FoxyResponse <ImageData> .Success(result));
            }
            catch (Exception e)
            {
                ErrorReporting.StoreExceptionDetails(e, sessionId);
                return(FoxyResponse <ImageData> .Failure("Unable to extract image from the request body"));
            }
        }