示例#1
0
        private void FailedStateRegistration(HttpClient client, Guid folderSessionId, Guid processId, string errorMessage)
        {
            OpenAPIService.StatusClient status = new OpenAPIService.StatusClient(WebApi.ToString(), client);

            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 Notify(HttpClient client, Guid folderSessionId, NotificationEvent.State type)
        {
            Entities.CommandKey.ValidationActionType currentActionType = this.ActionTypeName;

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

            if (type == NotificationEvent.State.Started)
            {
                //notify start
                var startBody = new BodyEventMessageBody
                {
                    Accepted      = 0,
                    Processed     = 0,
                    Rejected      = 0,
                    Name          = currentActionType.ToString(),
                    HasSummary    = true,
                    SessionId     = folderSessionId,
                    State         = "Started",
                    EventDateTime = DateTimeOffset.Now,
                    Start         = DateTimeOffset.Now,
                    End           = DateTimeOffset.Now,
                    Message       = "Event triggered by WorkerService."
                };
                var statusStartResult = status.NotifyAsync(startBody).GetAwaiter().GetResult();
                if (statusStartResult.StatusCode != 200)
                {
                    throw new ApplicationException(String.Format("Failed to notify, returned a bad response (not 200 code)! Folder / Session ID {0}.", folderSessionId));
                }
            }

            if (type == NotificationEvent.State.CompletedOrFailed)
            {
                //notify end
                var failedBody = new BodyEventMessageBody
                {
                    Accepted      = 0,
                    Processed     = 0,
                    Rejected      = 0,
                    Name          = currentActionType.ToString(),
                    HasSummary    = true,
                    SessionId     = folderSessionId,
                    State         = "Failed",
                    EventDateTime = DateTimeOffset.Now,
                    Start         = DateTimeOffset.Now,
                    End           = DateTimeOffset.Now,
                    Message       = "Event triggered by WorkerService."
                };
                var statusFailedResult = status.NotifyAsync(failedBody).GetAwaiter().GetResult();
                if (statusFailedResult.StatusCode != 200)
                {
                    throw new ApplicationException(String.Format("Failed to notify, returned a bad response (not 200 code)! Folder / Session ID {0}.", folderSessionId));
                }
            }

            System.Threading.Thread.Sleep(500);
        }
示例#3
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
            });
        }