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); }
public IActionResult SendNotification([FromBody] BodyEventMessageBody message) { if (message == null) { return(Problem("POST body JSON object is null!")); } var settings = new JsonSerializerSettings { ContractResolver = new DefaultContractResolver { NamingStrategy = new CamelCaseNamingStrategy() }, Formatting = Formatting.Indented, NullValueHandling = NullValueHandling.Ignore }; object state = null; bool parse = Enum.TryParse(typeof(PreingestActionStates), message.State, out state); if (!parse) { return(Problem("Parsing state failed!")); } //trigger full events _eventHub.Clients.All.SendAsync(nameof(IEventHub.SendNoticeEventToClient), JsonConvert.SerializeObject(new EventHubMessage { EventDateTime = message.EventDateTime, SessionId = message.SessionId, Name = message.Name, State = (PreingestActionStates)state, Message = message.Message, Summary = message.HasSummary ? new PreingestStatisticsSummary { Accepted = message.Accepted, Processed = message.Processed, Rejected = message.Rejected, Start = message.Start.Value, End = message.End.Value } : null }, settings)).GetAwaiter().GetResult(); if ((PreingestActionStates)state == PreingestActionStates.Started || (PreingestActionStates)state == PreingestActionStates.Failed || (PreingestActionStates)state == PreingestActionStates.Completed) { //notify client update collections status string collectionsData = JsonConvert.SerializeObject(_preingestCollection.GetCollections(), settings); _eventHub.Clients.All.SendAsync(nameof(IEventHub.CollectionsStatus), collectionsData).GetAwaiter().GetResult(); //notify client collection /{ guid} status string collectionData = JsonConvert.SerializeObject(_preingestCollection.GetCollection(message.SessionId), settings); _eventHub.Clients.All.SendAsync(nameof(IEventHub.CollectionStatus), message.SessionId, collectionData).GetAwaiter().GetResult(); if ((PreingestActionStates)state == PreingestActionStates.Failed || (PreingestActionStates)state == PreingestActionStates.Completed) { _eventHub.Clients.All.SendAsync(nameof(IEventHub.SendNoticeToWorkerService), message.SessionId, collectionData).GetAwaiter().GetResult(); } } return(Ok()); }