コード例 #1
0
        void Evaluate(bool result)
        {
            finalResult = finalResult && result;

            if (!enumerator.MoveNext() || !result)
            {
                callback(finalResult, new List <IWorkspace>());
            }
            else
            {
                var current   = enumerator.Current;
                var conductor = current as IConductor;
                if (conductor != null)
                {
                    var tasks = conductor.GetChildren()
                                .OfType <IHaveShutdownTask>()
                                .Select(x => x.GetShutdownTask())
                                .Where(x => x != null);

                    var sequential = new SequentialResult(tasks.GetEnumerator());
                    sequential.Completed += (s, e) => {
                        if (!e.WasCancelled)
                        {
                            Evaluate(!e.WasCancelled);
                        }
                    };
                    sequential.Execute(new ActionExecutionContext());
                }
                else
                {
                    Evaluate(true);
                }
            }
        }
コード例 #2
0
        void Rescue(TException exception)
        {
            var sb = new StringBuilder();

            sb.AppendFormat("Rescued {0}", exception.GetType().FullName).AppendLine();
            sb.AppendLine(exception.Message);
            sb.AppendLine(exception.StackTrace);
            Log.Info(sb.ToString());

            IResult rescueResult;

            try {
                rescueResult = new SequentialResult(rescue(exception).GetEnumerator());
            }
            catch (Exception ex) {
                OnCompleted(new ResultCompletionEventArgs {
                    Error = ex
                });
                return;
            }

            try {
                rescueResult.Completed += RescueCompleted;
                rescueResult.Execute(context);
            }
            catch (Exception ex) {
                RescueCompleted(rescueResult, new ResultCompletionEventArgs {
                    Error = ex
                });
            }
        }
コード例 #3
0
        void Evaluate(bool result)
        {
            finalResult = finalResult && result;

            //if (!enumerator.MoveNext() || !result) // if last object or something was cancelled
            //    callback(finalResult, new List<IScreen>());
            //else
            //{

            if (toclose.Any())
            {
                var tasks = toclose      //conductor.GetChildren()
                            .OfType <IHaveShutdownTask>()
                            .Select(x => x.GetShutdownTask())
                            .Where(x => x != null);

                var sequential = new SequentialResult(tasks.GetEnumerator());
                sequential.Completed += (s, e) =>
                {
                    callback(!e.WasCancelled, new List <IScreen>());
                    //if(!e.WasCancelled)
                    //Evaluate(!e.WasCancelled);
                };
                sequential.Execute(new CoroutineExecutionContext());
            }
            else
            {
                callback(true, new List <IScreen>());
            }
            //}
        }
コード例 #4
0
        /// <summary>
        /// Called when the execution of the decorated result has completed.
        /// </summary>
        /// <param name="innerResult">The decorated result.</param>
        /// <param name="args">The <see cref="ResultCompletionEventArgs" /> instance containing the event data.</param>
        protected override void OnInnerResultCompleted(IResult innerResult, ResultCompletionEventArgs args)
        {
            if (args.Error != null || !args.WasCancelled)
            {
                OnCompleted(new ResultCompletionEventArgs {
                    Error = args.Error
                });
            }
            else
            {
                Log.Info(string.Format("Executing coroutine because {0} was cancelled", innerResult.GetType().Name));

                IResult cancelResult;
                try {
                    cancelResult = new SequentialResult(coroutine().GetEnumerator());
                }
                catch (Exception ex) {
                    OnCompleted(new ResultCompletionEventArgs {
                        Error = ex
                    });
                    return;
                }

                try {
                    cancelResult.Completed += HandleCancelCompleted;
                    cancelResult.Execute(context);
                }
                catch (Exception ex) {
                    HandleCancelCompleted(cancelResult, new ResultCompletionEventArgs {
                        Error = ex
                    });
                }
            }
        }
コード例 #5
0
        private void Rescue(TException exception)
        {
            var rescueResult = new SequentialResult(this.rescue(exception).GetEnumerator());

            rescueResult.Completed += this.RescueCompleted;

            rescueResult.Execute(this.context);
        }
コード例 #6
0
        public static void ExecuteSequential(this IEnumerable <IResult> result, object target = null)
        {
            var sr = new SequentialResult(result.GetEnumerator());

            sr.Execute(new ActionExecutionContext {
                Target = target
            });
        }
コード例 #7
0
ファイル: ErrorHandler.cs プロジェクト: pirvudoru/winbugfreak
        private void OnNewError(object sender,ObservableList<PendingReport>.ListChangedEventArgs e)
        {
            var item = _errorQueue.Dequeue();
            var report = ErrorReport.FromException(item.Exception);

            var storageLocations = GlobalConfig.ServiceLocator.GetServices<IErrorReportStorage>();
            var result = new SequentialResult(storageLocations.Select(storage => new ErrorReportSaveResult(storage, report)).Cast<IResult>());
            result.Completed += (o, args) => OnReportingCompleted(e, args);
            result.Execute(new ExecutionContext());
        }
コード例 #8
0
ファイル: RescueAttribute.cs プロジェクト: hispafox/CMContrib
        public override IEnumerable<IResult> Decorate(IEnumerable<IResult> coroutine, ActionExecutionContext context)
        {
            var targetType = context.Target.GetType();

            Func<Exception, IEnumerable<IResult>> handler = CreateHandler(context, targetType);

            var sequentialResult = new SequentialResult(coroutine.GetEnumerator());

            yield return sequentialResult
                .Rescue().Execute(handler);
        }
コード例 #9
0
        public override IEnumerable <IResult> Decorate(IEnumerable <IResult> coroutine, ActionExecutionContext context)
        {
            var targetType = context.Target.GetType();

            Func <Exception, IEnumerable <IResult> > handler = CreateHandler(context, targetType);

            var sequentialResult = new SequentialResult(coroutine.GetEnumerator());

            yield return(sequentialResult
                         .Rescue().Execute(handler));
        }
コード例 #10
0
        private IResult Populate(IPopulableViewModel populableViewModel)
        {
            IResult result;

            try
            {
                result = new SequentialResult(populableViewModel.Populate().GetEnumerator());
            }
            catch (Exception ex)
            {
                result = UiService.ShowMessageBox(ex.Message, GlobalStrings.ErrorCaption);

                TryClose();
            }

            return(result);
        }
コード例 #11
0
        protected override void InnerCompleted(object sender, ResultCompletionEventArgs args)
        {
            base.InnerCompleted(sender, args);

            if (args.Error != null || !args.WasCancelled)
            {
                OnCompleted(new ResultCompletionEventArgs {Error = args.Error});
            }
            else
            {
                Log.Info(string.Format("Executing coroutine because {0} was cancelled", Inner.GetType().Name));

                var cancelResult = new SequentialResult(_coroutine().GetEnumerator());
                cancelResult.Completed += HandleCancelCompleted;

                cancelResult.Execute(_context);
            }
        }
コード例 #12
0
        public override IEnumerable<IResult> Decorate(IEnumerable<IResult> coroutine, ActionExecutionContext context)
        {
            var inner = new SequentialResult(coroutine.GetEnumerator());
          
            if (!String.IsNullOrWhiteSpace(Message))
            {
                var busyDecorator = new BusyResultDecorator(inner, Message);
                if (BusyIndicatorImplementation != null)
                {
                    busyDecorator.In(BusyIndicatorImplementation);
                }

                yield return busyDecorator;
            }
            else
            {
                yield return new WorkerThreadResultDecorator(inner);
            }
        }
コード例 #13
0
        public override IEnumerable <IResult> Decorate(IEnumerable <IResult> coroutine, ActionExecutionContext context)
        {
            var inner = new SequentialResult(coroutine.GetEnumerator());

            if (!String.IsNullOrWhiteSpace(Message))
            {
                var busyDecorator = new BusyResultDecorator(inner, Message);
                if (BusyIndicatorImplementation != null)
                {
                    busyDecorator.In(BusyIndicatorImplementation);
                }

                yield return(busyDecorator);
            }
            else
            {
                yield return(new WorkerThreadResultDecorator(inner));
            }
        }
コード例 #14
0
        protected override void InnerCompleted(object sender, ResultCompletionEventArgs args)
        {
            base.InnerCompleted(sender, args);

            if (args.Error != null || !args.WasCancelled)
            {
                OnCompleted(new ResultCompletionEventArgs {
                    Error = args.Error
                });
            }
            else
            {
                Log.Info(string.Format("Executing coroutine because {0} was cancelled", Inner.GetType().Name));

                var cancelResult = new SequentialResult(_coroutine().GetEnumerator());
                cancelResult.Completed += HandleCancelCompleted;

                cancelResult.Execute(_context);
            }
        }
コード例 #15
0
        void Evaluate(bool result)
        {
            _finalResult = _finalResult && result;

            if (!_enumerator.MoveNext() || !result)
            {
                _callback(_finalResult, new List <IClientModule>());
            }
            else
            {
                var current = _enumerator.Current;
                // ReSharper disable once SuspiciousTypeConversion.Global
                var conductor = current as IConductor;
                if (conductor != null)
                {
                    var tasks = conductor.GetChildren()
                                .OfType <IHaveShutdownTask>()
                                .Select(x => x.GetShutdownTask())
                                .Where(x => x != null);

                    var sequential = new SequentialResult(tasks.GetEnumerator());
                    sequential.Completed += (s, e) =>
                    {
                        if (!e.WasCancelled)
                        {
                            Evaluate(!e.WasCancelled);
                        }
                    };
                    sequential.Execute(new CoroutineExecutionContext());
                }
                else
                {
                    Evaluate(true);
                }
            }
        }