Esempio n. 1
0
        private void PublishEventsForPreviouslySubmittedFeeds(IFeedSubmissionEntryService feedSubmissionService)
        {
            var previouslySubmittedFeeds = feedSubmissionService.GetAllFromQueueOfFeedsReadyForCallback(_merchantId, _region);

            foreach (var feedSubmissionEntry in previouslySubmittedFeeds)
            {
                try
                {
                    var processingReportContent = ZipHelper.ExtractArchivedSingleFileToStream(feedSubmissionEntry.Details.FeedSubmissionReport);
                    var feedType    = feedSubmissionEntry.FeedType;
                    var handlerId   = feedSubmissionEntry.TargetHandlerId;
                    var handledArgs = feedSubmissionEntry.TargetHandlerArgs == null ? null : new ReadOnlyDictionary <string, object>(JsonConvert.DeserializeObject <Dictionary <string, object> >(feedSubmissionEntry.TargetHandlerArgs));
                    var eventArgs   = new FeedUploadedEventArgs(processingReportContent, feedType, handlerId, handledArgs);

                    _logger.Debug($"Attempting publish FeedUploaded for the next submitted feed in queue : {feedSubmissionEntry.EntryIdentityDescription}");
                    OnFeedUploaded(eventArgs);
                    feedSubmissionService.Delete(feedSubmissionEntry);
                    _logger.Info($"Event publishing has succeeded for {feedSubmissionEntry.EntryIdentityDescription}.");
                }
                catch (SqlException e)
                {
                    _logger.Error($"Event publishing failed for {feedSubmissionEntry.EntryIdentityDescription} due to an internal error '{e.Message}'. The event publishing will be retried at the next poll request", e);
                    feedSubmissionService.Unlock(feedSubmissionEntry, "Unlocking single feed submission entry - an SQL exception occurred while trying to invoke callback.");
                    feedSubmissionService.Update(feedSubmissionEntry);
                }
                catch (Exception e)
                {
                    _logger.Error($"Event publishing failed for {feedSubmissionEntry.EntryIdentityDescription}. Current retry count is :{feedSubmissionEntry.FeedSubmissionRetryCount}. {e.Message}", e);
                    feedSubmissionEntry.InvokeCallbackRetryCount++;
                    feedSubmissionService.Unlock(feedSubmissionEntry, "Unlocking single feed submission entry - an exception occurred while trying to invoke callback.");
                    feedSubmissionService.Update(feedSubmissionEntry);
                }
            }

            feedSubmissionService.SaveChanges();
        }
Esempio n. 2
0
 private void OnFeedUploaded(FeedUploadedEventArgs e) => FeedUploadedInternal?.Invoke(this, e);