public async Task <List <SendMpiResponse> > SendMigrationsAsync(SendManifestPackageDTO sendTo, MgsMessageBag messageBag) { var responses = new List <SendMpiResponse>(); var client = Client ?? new HttpClient(); int sendCound = 0; int count = 0; int total = messageBag.Messages.Count; DomainEvents.Dispatch(new MgsStatusNotification(sendTo.ExtractId, ExtractStatus.Sending)); foreach (var message in messageBag.Messages) { count++; try { var msg = JsonConvert.SerializeObject(message); var response = await client.PostAsJsonAsync(sendTo.GetUrl($"{_endPoint.HasToEndsWith("/")}migrations"), message); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsJsonAsync <SendMpiResponse>(); responses.Add(content); var sentIds = message.Migrations.Select(x => x.Id).ToList(); sendCound += sentIds.Count; DomainEvents.Dispatch(new MgsExtractSentEvent(sentIds, SendStatus.Sent, sendTo.ExtractName)); } else { var error = await response.Content.ReadAsStringAsync(); DomainEvents.Dispatch(new MgsExtractSentEvent(message.Migrations.Select(x => x.Id).ToList(), SendStatus.Failed, sendTo.ExtractName, error)); throw new Exception(error); } } catch (Exception e) { Log.Error(e, $"Send Manifest Error"); throw; } DomainEvents.Dispatch(new MgsSendNotification(new SendProgress("Migration", Common.GetProgress(count, total), sendCound))); } DomainEvents.Dispatch(new MgsSendNotification(new SendProgress("Migration", Common.GetProgress(count, total), sendCound, true))); DomainEvents.Dispatch(new MgsStatusNotification(sendTo.ExtractId, ExtractStatus.Sent, sendCound)); return(responses); }
public Task <List <SendMpiResponse> > SendMigrationsAsync(SendManifestPackageDTO sendTo) { return(SendMigrationsAsync(sendTo, MgsMessageBag.Create(_packager.GenerateMigrations().ToList()))); }