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); } } }
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 }); } }
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>()); } //} }
/// <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 }); } } }
private void Rescue(TException exception) { var rescueResult = new SequentialResult(this.rescue(exception).GetEnumerator()); rescueResult.Completed += this.RescueCompleted; rescueResult.Execute(this.context); }
public static void ExecuteSequential(this IEnumerable <IResult> result, object target = null) { var sr = new SequentialResult(result.GetEnumerator()); sr.Execute(new ActionExecutionContext { Target = target }); }
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()); }
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); } }
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); } }
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); } } }