コード例 #1
0
        public Task<AggregateOperationsResult> ProcessQueue(IEnumerable<IOperationViewModel> operations,
            CancellationToken token)
        {
            foreach (var operation in operations)
            {
                // Check if previous previousOperation failed.
                var previousOperation = GetPreviousItem(operations, operation);
                if (token.IsCancellationRequested || !this.CanContinue(previousOperation))
                {
                    break;
                }

                operation.State = OperationState.InProgress;
                eventAggregator.PublishOnUIThread(new LogEntry(operation.Description, LogEntrySeverity.Info,
                    LogEntrySource.UI));

                var result = new OperationResult();

                try
                {
                    token.ThrowIfCancellationRequested();
                    result = operation.Process();

                    LogResultMessages(result);
                    resultHandlershandle[result.State](result, operation);
                }
                catch (OperationCanceledException)
                {
                    resultHandlershandle[OperationResultState.Canceled](result, operation);
                }
                catch (Exception e)
                {
                    eventAggregator.PublishOnUIThread(
                        new LogEntry(string.Format("Unhandled exception occurred: {0}", e.Message),
                            LogEntrySeverity.Error, LogEntrySource.UI));
                }
            }

            return Task.FromResult(CalculateResult(operations));
        }
コード例 #2
0
        private void LogResultMessages(OperationResult result)
        {
            const int maxEntriesToShow = 1500;

            if (result.LogEntries.Count <= maxEntriesToShow)
            {
                this.PublishLogEntries(result.LogEntries);
            }
            else
            {
                var lastEntries =
                    result.LogEntries.AsEnumerable<LogEntry>().Skip(Math.Max(0, result.LogEntries.Count - maxEntriesToShow));

                this.PublishLogEntries(lastEntries);

                eventAggregator.PublishOnUIThread(new LogEntry("The converter returned " + result.LogEntries.Count + " lines.", LogEntrySeverity.Warning, LogEntrySource.UI));
                eventAggregator.PublishOnUIThread(new LogEntry("Only showing the last " + maxEntriesToShow, LogEntrySeverity.Warning, LogEntrySource.UI));
            }
        }
コード例 #3
0
 private void HandleWarning(OperationResult result, IOperationViewModel operation)
 {
     operation.State = OperationState.CompleteWithWarnings;
     eventAggregator.PublishOnUIThread(
         new LogEntry(string.Format("{0} completed with warnings!", operation.Description),
             LogEntrySeverity.Warning, LogEntrySource.UI));
 }
コード例 #4
0
 private void HandleSuccess(OperationResult result, IOperationViewModel operation)
 {
     operation.State = OperationState.Success;
     eventAggregator.PublishOnUIThread(
         new LogEntry(string.Format("{0} completed successfully.", operation.Description), LogEntrySeverity.Info,
             LogEntrySource.UI));
 }
コード例 #5
0
 private void HandleErrors(OperationResult result, IOperationViewModel operation)
 {
     operation.State = OperationState.Failed;
     eventAggregator.PublishOnUIThread(new LogEntry(string.Format("{0} failed!", operation.Description),
         LogEntrySeverity.Error, LogEntrySource.UI));
 }
コード例 #6
0
 private void HandleCancellation(OperationResult result, IOperationViewModel operation)
 {
     eventAggregator.PublishOnUIThread(
         new LogEntry(string.Format("Operation {0} canceled.", operation.Description), LogEntrySeverity.Warning,
             LogEntrySource.UI));
 }