public static async Task <IActionResult> CognitivePipelineSyncProcessing(NewRequest <SmartDoc> newSmartDocRequest) { log.LogInformation($"***Starting Sync CognitivePipelineSyncProcessing***"); IActionResult executionResult = null; if (newSmartDocRequest.Instructions.Contains(InstructionFlag.AnalyzeText.ToString())) { var stepName = InstructionFlag.AnalyzeText.ToString(); log.LogInformation($"***Starting {stepName}***"); string funcUri = GlobalSettings.GetKeyValue("FunctionBaseUrl") + "/NewCognitiveOCR"; var content = new StringContent(JsonConvert.SerializeObject(newSmartDocRequest), Encoding.UTF8, "application/json"); try { executionResult = await FunctionExecuter.CallFunction(funcUri, content); if (executionResult is OkObjectResult) { //TODO: Update the request processing step var result = executionResult as OkObjectResult; string updatedDocJson = result.Value.ToString(); NewRequest <SmartDoc> updatedDoc = JsonConvert.DeserializeObject <NewRequest <SmartDoc> >(updatedDocJson); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(updatedDoc.RequestItem.CognitivePipelineActions[0]); } else { //TODO: Better error information to be implemented newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } catch (Exception ex) { log.LogError($"***EXCEPTION*** in {stepName}: {ex.Message}, {ex.StackTrace}"); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = InstructionFlag.AnalyzeText.ToString() }); } } if (newSmartDocRequest.Instructions.Contains(InstructionFlag.FaceAuthentication.ToString())) { var stepName = InstructionFlag.FaceAuthentication.ToString(); log.LogInformation($"***Starting {stepName}***"); CognitivePipeline.SharedModels.Models.User owner = await usersDbClient.GetItemAsync(newSmartDocRequest.OwnerId); string funcUri = GlobalSettings.GetKeyValue("FunctionBaseUrl") + $"/NewCognitiveFaceAuth/{owner.FacePersonId}"; var content = new StringContent(JsonConvert.SerializeObject(newSmartDocRequest), Encoding.UTF8, "application/json"); try { executionResult = await FunctionExecuter.CallFunction(funcUri, content); if (executionResult is OkObjectResult) { //TODO: Update the request processing step var result = executionResult as OkObjectResult; string updatedDocJson = result.Value.ToString(); NewRequest <SmartDoc> updatedDoc = JsonConvert.DeserializeObject <NewRequest <SmartDoc> >(updatedDocJson); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(updatedDoc.RequestItem.CognitivePipelineActions[0]); } else { //TODO: Better error information to be implemented newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } catch (Exception ex) { log.LogError($"***EXCEPTION*** in {stepName}: {ex.Message}, {ex.StackTrace}"); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } if (newSmartDocRequest.Instructions.Contains(InstructionFlag.ShelfCompliance.ToString())) { var stepName = InstructionFlag.ShelfCompliance.ToString(); log.LogInformation($"***Starting {stepName}***"); string funcUri = GlobalSettings.GetKeyValue("FunctionBaseUrl") + "/NewCognitiveShelfCompliance"; var content = new StringContent(JsonConvert.SerializeObject(newSmartDocRequest), Encoding.UTF8, "application/json"); try { executionResult = await FunctionExecuter.CallFunction(funcUri, content); if (executionResult is OkObjectResult) { //TODO: Update the request processing step var result = executionResult as OkObjectResult; string updatedDocJson = result.Value.ToString(); NewRequest <SmartDoc> updatedDoc = JsonConvert.DeserializeObject <NewRequest <SmartDoc> >(updatedDocJson); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(updatedDoc.RequestItem.CognitivePipelineActions[0]); } else { //TODO: Better error information to be implemented newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } catch (Exception ex) { log.LogError($"***EXCEPTION*** in {stepName}: {ex.Message}, {ex.StackTrace}"); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } if (newSmartDocRequest.Instructions.Contains(InstructionFlag.Thumbnail.ToString())) { var stepName = InstructionFlag.Thumbnail.ToString(); log.LogInformation($"***Starting {stepName}***"); //Currently the 2 Thumbnail sizes are loaded from Functions settings. var thumbnailConfig = GlobalSettings.GetKeyValue("CognitiveServices-Thumbnail-Config").Split(','); string funcUri = GlobalSettings.GetKeyValue("FunctionBaseUrl") + $"/NewCognitiveThumbnail/{thumbnailConfig[0]}/{thumbnailConfig[1]}/{thumbnailConfig[2]}/{thumbnailConfig[3]}"; var content = new StringContent(JsonConvert.SerializeObject(newSmartDocRequest), Encoding.UTF8, "application/json"); try { executionResult = await FunctionExecuter.CallFunction(funcUri, content); if (executionResult is OkObjectResult) { //TODO: Update the request processing step var result = executionResult as OkObjectResult; string updatedDocJson = result.Value.ToString(); NewRequest <SmartDoc> updatedDoc = JsonConvert.DeserializeObject <NewRequest <SmartDoc> >(updatedDocJson); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(updatedDoc.RequestItem.CognitivePipelineActions[0]); } else { //TODO: Better error information to be implemented newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } catch (Exception ex) { log.LogError($"***EXCEPTION*** in {stepName}: {ex.Message}, {ex.StackTrace}"); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } if (newSmartDocRequest.Instructions.Contains(InstructionFlag.AnalyzeImage.ToString())) { var stepName = InstructionFlag.AnalyzeImage.ToString(); log.LogInformation($"***Starting {stepName}***"); string funcUri = GlobalSettings.GetKeyValue("FunctionBaseUrl") + $"/NewCognitiveAnalyzeImage"; var content = new StringContent(JsonConvert.SerializeObject(newSmartDocRequest), Encoding.UTF8, "application/json"); try { executionResult = await FunctionExecuter.CallFunction(funcUri, content); if (executionResult is OkObjectResult) { //TODO: Update the request processing step var result = executionResult as OkObjectResult; string updatedDocJson = result.Value.ToString(); NewRequest <SmartDoc> updatedDoc = JsonConvert.DeserializeObject <NewRequest <SmartDoc> >(updatedDocJson); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(updatedDoc.RequestItem.CognitivePipelineActions[0]); } else { //TODO: Better error information to be implemented newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = InstructionFlag.AnalyzeImage.ToString() }); } } catch (Exception ex) { log.LogError($"***EXCEPTION*** in {stepName}: {ex.Message}, {ex.StackTrace}"); newSmartDocRequest.RequestItem.CognitivePipelineActions.Add(new ProcessingStep { LastUpdatedAt = DateTime.UtcNow, Status = SmartDocStatus.ProcessedUnsuccessfully.ToString(), StepName = stepName }); } } //Validate cognitive processing and return relevant details log.LogInformation($"***Final Results Processing***"); var processedResult = await CognitivePipelineResultProcessor.ProcessFinalResult(newSmartDocRequest, smartDocsDbClient, usersDbClient); if (!string.IsNullOrEmpty(processedResult)) { return((ActionResult) new OkObjectResult(processedResult)); } else { return((ActionResult) new BadRequestObjectResult(processedResult)); } }
private object view_ViewAction(ViewEventType type, ViewEventArgs args) { switch (type) { case ViewEventType.Exit: { alive = false; break; } case ViewEventType.StartSolving1: { string fname = args.Parameters[0].ToString(); string curveName = args.Parameters[1].ToString(); var fe = new FunctionExecuter(typeof(Functions), fname); var r = new Random(); double y0 = z1min + r.NextDouble() * (z1max - z1min); var rk = new RKVectorForm(fe, curveName, t0, t1, new Vector(1, y0)); rk.OnResultGenerated += rk_OnResultGenerated; rk.SolveWithConstH(rkN, RKMetodType.RK4_1); break; } case ViewEventType.StartSolving2: { string fname = args.Parameters[0].ToString(); var curveNames = args.Parameters[1] as string[, ]; var fe = new FunctionExecuter(typeof(Functions), fname); double h1 = (z1max - z1min) / (randN); double h2 = (z2max - z2min) / (randN); var results = new Dictionary <string, RKResults>(); for (int i = 0; i < randN; i++) { for (int j = 0; j < randN; j++) { double z00 = z1min + i * h1; double z01 = z2min + j * h2; var rk = new RKVectorForm(fe, curveNames[i, j], t0, t1, new Vector(2, z00, z01)); rk.OnSolvingDone += rk_OnSolvingDone; RKResults res = rk.SolveWithConstH(rkN, RKMetodType.RK4_1); results.Add(curveNames[i, j], res); } } break; } case ViewEventType.SolvePodhod2Type1: { string fname = args.Parameters[0].ToString(); string curveName = args.Parameters[1].ToString(); var fe = new FunctionExecuter(typeof(Functions), fname); var rk = new RKVectorForm(fe, curveName, t0, t1, new Vector(1, y0)); rk.OnResultGenerated += rk_OnResultGenerated; rk.OnSolvingDone += rk_OnSolvingDoneType1; rk.SolveWithConstH(rkN, RKMetodType.RK4_1); break; } case ViewEventType.SolovePodhod2Type2: { string fname = args.Parameters[0].ToString(); string curveName = args.Parameters[1].ToString(); var fe = new FunctionExecuter(typeof(Functions), fname); var rk = new RKVectorForm(fe, curveName, t0, t1, new Vector(2, y00, y01)); rk.OnResultGenerated += rk_OnResGenForType2; rk.OnSolvingDone += rk_OnSolvingDoneType2; rk.SolveWithConstH(rkN, RKMetodType.RK4_1); break; } case ViewEventType.SolovePodhod2Type2Mass: { string fname = args.Parameters[0].ToString(); var curveNames = args.Parameters[1] as string[, ]; var fe = new FunctionExecuter(typeof(Functions), fname); double h1 = (z1max - z1min) / (randN); double h2 = (z2max - z2min) / (randN); var results = new Dictionary <string, RKResults>(); for (int i = 0; i < randN; i++) { for (int j = 0; j < randN; j++) { double z00 = z1min + i * h1; double z01 = z2min + j * h2; var rk = new RKVectorForm(fe, curveNames[i, j], t0, t1, new Vector(2, z00, z01)); //rk.OnResultGenerated += new RKResultGeneratedDelegate(rk_OnResGenForType2); //rk.OnSolvingDone += new RKSolvingDoneDelegate(rk_OnSolvingDoneType2); RKResults res = rk.SolveWithConstH(rkN, RKMetodType.RK4_1); results.Add(curveNames[i, j], res); } } view.SendSolvingResultType2Mass(results, fe); break; } case ViewEventType.UpdateParams: { t0 = (double)args.Parameters[0]; t1 = (double)args.Parameters[1]; y0 = (double)args.Parameters[2]; y00 = (double)args.Parameters[3]; y01 = (double)args.Parameters[4]; rkN = Convert.ToInt32(args.Parameters[5]); randN = Convert.ToInt32(args.Parameters[6]); z1min = (double)args.Parameters[7]; z1max = (double)args.Parameters[8]; z2min = (double)args.Parameters[9]; z2max = (double)args.Parameters[10]; break; } } return(null); }