public async Task Handle(UserRestartedWorkItemMessage message, IMessageHandlerContext context) { log.Info($"MESSAGE: {nameof(UserRestartedWorkItemMessage)}; HANDLED BY: {nameof(WorkItemSaga)}; JID:{message.JobId}; WID:{message.WorkItemId}"); Data.TotalRequests = message.HttpRequests.Count(); await context.SendLocal(new WorkItemRestartedMessage { JobId = message.JobId, WorkItemId = message.WorkItemId, HttpRequests = message.HttpRequests, DateActionTaken = message.DateActionTaken, }); foreach (var item in message.HttpRequests) { await context.SendLocal(new ExecuteHttpRequestMessage { JobId = message.JobId, WorkItemId = message.WorkItemId, HttpRequest = item, CreateDate = DateTime.UtcNow }); } }
private async Task RestartWorkItemsAsync(UserRestartedJobMessage message, IMessageHandlerContext context) { AutomatonDatabaseContext dbContext = new AutomatonDatabaseContext(); var httpRequests = await dbContext.HttpRequestRepository.GetAllByJobIdAndStatusAsync(message.JobId, (short)WorkItemStatusType.Completed); dbContext.Commit(); var workItems = httpRequests.GroupBy(i => i.WorkItemId).Select(i => new { WorkItemId = i.Key, HttpRequests = i.ToList() }); foreach (var workItem in workItems) { var restartMessage = new UserRestartedWorkItemMessage(); restartMessage.JobId = message.JobId; restartMessage.WorkItemId = workItem.WorkItemId; restartMessage.DateActionTaken = message.DateActionTookPlace; List <UserHttpRequest> userHttpRequests = new List <UserHttpRequest>(); foreach (var httpRequest in workItem.HttpRequests) { var request = new UserHttpRequest(); if (httpRequest.AuthenticationConfigInJson != null) { request.AuthenticationConfig = JsonConvert.DeserializeObject <HttpAuthenticationConfig>(httpRequest.AuthenticationConfigInJson); } if (httpRequest.ContentHeadersInJson != null) { request.ContentHeaders = JsonConvert.DeserializeObject <Dictionary <string, string> >(httpRequest.ContentHeadersInJson); } request.ContentType = httpRequest.ContentType; request.HttpRequestId = httpRequest.Id; request.Method = httpRequest.Method; if (httpRequest.RequestHeadersInJson != null) { request.RequestHeaders = JsonConvert.DeserializeObject <Dictionary <string, string> >(httpRequest.RequestHeadersInJson); } request.Url = httpRequest.Url; request.Content = httpRequest.Content; request.UserAgent = httpRequest.UserAgent; userHttpRequests.Add(request); } restartMessage.HttpRequests = userHttpRequests; await context.SendLocal(restartMessage) ; } }