예제 #1
0
        private void CompleteNewStatesRegistration(HttpClient client, Guid folderSessionId, Guid processId, string errorMessage)
        {
            Entities.CommandKey.ValidationActionType currentActionType = this.ActionTypeName;

            OpenAPIService.StatusClient status = new OpenAPIService.StatusClient(WebApi.ToString(), client);

            //add 2 records (started/failed) for state
            var startStateResponse = status.StartAsync(processId).GetAwaiter().GetResult();

            if (startStateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Start state registration returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            OnNotify(new NotificationEvent {
                Client = client, Id = folderSessionId, Result = NotificationEvent.State.Started
            });

            var failedStateResponse = status.FailedAsync(processId, new BodyMessage {
                Message = errorMessage
            }).GetAwaiter().GetResult();

            if (failedStateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Failed state registration returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            SummaryItem summaryObj = new SummaryItem {
                Accepted = 0, Processed = 0, Rejected = 1, Start = DateTimeOffset.Now, End = DateTimeOffset.Now
            };
            string summaryStr = JsonConvert.SerializeObject(summaryObj);
            //final update
            var finalUpdateResponse = status.UpdateAsync(processId, new BodyUpdate {
                Result = "Failed", Summary = summaryStr
            }).GetAwaiter().GetResult();

            if (finalUpdateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Final update status returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            OnNotify(new NotificationEvent {
                Client = client, Id = folderSessionId, Result = NotificationEvent.State.CompletedOrFailed
            });
        }
예제 #2
0
        private void CompleteNewActionRegistration(HttpClient client, Guid folderSessionId, string errorMessage)
        {
            Entities.CommandKey.ValidationActionType currentActionType = this.ActionTypeName;

            OpenAPIService.StatusClient status = new OpenAPIService.StatusClient(WebApi.ToString(), client);
            //add new
            Guid processId = Guid.Empty;

            status.ProcessResponse += (object sender, Entities.Event.CallEvents e) =>
            {
                dynamic actionRegistration = JsonConvert.DeserializeObject <dynamic>(e.ResponseMessage);
                object  id       = actionRegistration.processId;
                bool    isParsed = Guid.TryParse(id == null ? "" : id.ToString(), out processId);
            };

            var addNewActionResponse = status.NewAsync(folderSessionId, new BodyNewAction
            {
                Name        = currentActionType.ToString(),
                Description = "Action created by WorkerService.",
                Result      = null
            }).GetAwaiter().GetResult();

            if (processId == Guid.Empty)
            {
                throw new ApplicationException("Parsing process (action) ID failed!");
            }

            if (addNewActionResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("New action registration returned a bad response (not 200 code)! Action ID {0}, Folder/Session ID {1}.", processId, folderSessionId));
            }
            //add 2 records (started/failed) for state
            var startStateResponse = status.StartAsync(processId).GetAwaiter().GetResult();

            if (startStateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Start state registration returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            OnNotify(new NotificationEvent {
                Client = client, Id = folderSessionId, Result = NotificationEvent.State.Started
            });

            var failedStateResponse = status.FailedAsync(processId, new BodyMessage {
                Message = errorMessage
            }).GetAwaiter().GetResult();

            if (failedStateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Failed state registration returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            SummaryItem summaryObj = new SummaryItem {
                Accepted = 0, Processed = 0, Rejected = 1, Start = DateTimeOffset.Now, End = DateTimeOffset.Now
            };
            string summaryStr = JsonConvert.SerializeObject(summaryObj);
            //final update
            var finalUpdateResponse = status.UpdateAsync(processId, new BodyUpdate {
                Result = "Failed", Summary = summaryStr
            }).GetAwaiter().GetResult();

            if (finalUpdateResponse.StatusCode != 200)
            {
                throw new ApplicationException(String.Format("Final update status returned a bad response (not 200 code)! Action ID {0}, Folder / Session ID {1}.", processId, folderSessionId));
            }

            OnNotify(new NotificationEvent {
                Client = client, Id = folderSessionId, Result = NotificationEvent.State.CompletedOrFailed
            });
        }