public async Task <IActionResult> GetDestinationPointBySourcePointAsync(string sourcePointId) { var retValue = await _destinationService.GetDestinationPointBySourcePoint(Guid.Parse(sourcePointId)); return(Ok(retValue)); }
public void ProcessQueueMessage( [QueueTrigger(Constant.PUBLISH_QUEUE_NAME)] PublishedMessage message, [Table(Constant.PUBLISH_TABLE_NAME)] CloudTable tableBinding, TextWriter log) { try { var retValue = new PublishStatusEntity(message.PublishBatchId.ToString(), message.SourcePointId.ToString(), message.PublishHistoryId.ToString()); var publishHistory = _sourceService.GetPublishHistoryById(message.PublishHistoryId).Result; if (publishHistory != null) { var destinationPoints = _destinationService.GetDestinationPointBySourcePoint(publishHistory.SourcePointId); var groupedDestinationPoints = destinationPoints.Result.GroupBy(o => o.CatalogId); var publishValue = publishHistory.Value; IDictionary <string, Task <DocumentUpdateResult> > tasks = new Dictionary <string, Task <DocumentUpdateResult> >(); foreach (var sameCatalogDestinationPoints in groupedDestinationPoints) { try { var documentId = sameCatalogDestinationPoints.First().Catalog.DocumentId; var points = sameCatalogDestinationPoints.Select(o => o); tasks.Add(documentId, _documentService.UpdateBookmrkValue(documentId, points, publishValue)); } catch (Exception ex) { log.Write($"Publish the source point to file '{message.SourcePointId}' failed due to {ex.ToString()}"); } } Task.WaitAll(tasks.Values.ToArray()); var errorItems = tasks.Where(o => o.Value.Result.IsSuccess == false || o.Value.IsFaulted); retValue.Comments = String.Join("\n\n", tasks.Select(o => $"{o.Key}:\t{String.Join("\n",o.Value.Result.Message)}")); if (errorItems.Count() > 0) { retValue.Status = PublishStatus.Error; retValue.ErrorSummary = $"Update files: {String.Join(";", errorItems.Select(o => o.Key))} failed"; retValue.ErrorDetail = String.Join("\n", errorItems.SelectMany(o => o.Value.Result.Message)); log.Write($"Update the documents {retValue.ErrorSummary} failed due to {retValue.ErrorSummary} "); } else { retValue.Status = PublishStatus.Completed; log.Write($"Update the documents successfully."); } } else { retValue.Status = PublishStatus.Error; retValue.ErrorSummary = "The publish history cannot be found."; log.Write($"The publish history related to the source point: '{message.SourcePointId}' cannot be found."); } tableBinding.Execute(TableOperation.InsertOrReplace(retValue)); log.Write("Publish is finished."); } catch (Exception ex) { log.Write($"Publish the source point: '{message.SourcePointId}' failed due to {ex.ToString()}"); } }