protected override async Task SendMQ(MQEpep mq) { string text = mq.Content == null ? "" : Encoding.UTF8.GetString(mq.Content); if (string.IsNullOrEmpty(text)) { using (var scope = new TransactionScope()) { text = GenerateXml(mq); mq.Content = Encoding.UTF8.GetBytes(text); repo.Update(mq); repo.SaveChanges(); scope.Complete(); } } var response = await requester.PostAsyncTextXml(uploadUrl.AbsoluteUri, text); if (response.IsSuccessStatusCode) { var content = await response.Content.ReadAsStringAsync(); XElement result = null; if (!string.IsNullOrEmpty(content)) { XDocument message = XDocument.Parse(content); result = message?.Element("response")?.Element("success"); } else { content = "Получен е празен резултат от ИСПН"; } if (result != null) { mq.IntegrationStateId = IntegrationStates.TransferOK; mq.DateTransfered = DateTime.Now; mq.Content = Encoding.UTF8.GetBytes(text); repo.Update(mq); repo.SaveChanges(); if (caseMq != null) { var mqHash = caseMq.FirstOrDefault(x => x.Id == mq.Id); mqHash.Content = mq.Content; mqHash.IntegrationStateId = mq.IntegrationStateId; } string fileName = $"Ispn_{mq.Id}_{ DateTime.Today:dd.MM.yyyy}.xml"; CdnUploadRequest request = new CdnUploadRequest() { ContentType = System.Net.Mime.MediaTypeNames.Text.Html, FileContentBase64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(content)), FileName = fileName, SourceId = mq.ParentSourceId.ToString(), SourceType = SourceTypeSelectVM.Integration_ISPN, Title = $"Отговор към { DateTime.Today:dd.MM.yyyy}" }; if (!(await cdnService.MongoCdn_AppendUpdate(request))) { logger.LogError("Error in SaveContent ISPN mqId {mq.Id}!", mq.Id.ToString()); } } else { SetErrorToMQ(mq, IntegrationStates.DataContentError, content); } } else { throw new Exception($"Error {response.StatusCode} : {response.ReasonPhrase} sending message ISPN!"); } }