void ChildCompleted(object sender, ResultCompletionEventArgs args) {
            if(args.Error != null || args.WasCancelled) {
                OnComplete(args.Error, args.WasCancelled);
                return;
            }

            var previous = sender as IResult;

            if(previous != null)
                previous.Completed -= ChildCompleted;

            var moveNextSucceeded = false;
            try {
                moveNextSucceeded = enumerator.MoveNext();
            }
            catch(Exception ex) {
                OnComplete(ex, false);
                return;
            }

            if(moveNextSucceeded) {
                try {
                    var next = enumerator.Current;
                    IoC.BuildUp(next);
                    next.Completed += ChildCompleted;
                    next.Execute(context);
                }
                catch(Exception ex) {
                    OnComplete(ex, false);
                    return;
                }
            }
            else OnComplete(null, false);
        }
Пример #2
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(ActionExecutionContext context)
        {
            if (string.IsNullOrEmpty(LastFmDataAccess.ApiKey))
            {
                var args = new ResultCompletionEventArgs
                {
                    Error = new Exception("Can't execute query. No API-Key found."),
                    WasCancelled = true
                };
                Completed(this, args);
                EventAgg.Publish(new ErrorMessage(args));
            }

            var stopWatch = new StopWatch(10000);
            var webClient = new WebClient();

            webClient.OpenReadCompleted += (sender, e) =>
            {
                stopWatch.Stop();
                if (e.Error == null)
                {
                    XDocument doc = XDocument.Load(e.Result);
                    XElement ee = doc.Descendants("error").FirstOrDefault();

                    if (ee != null)
                    {
                        stopWatch.Stop();
                        Completed(this, new ResultCompletionEventArgs
                        {
                            Error = new Exception(ee.Value),
                            WasCancelled = false
                        });
                        return;
                    }
                    XmlResult = doc.Root;

                    if (repository != null && addToRepository != LastFmRepository.RepositoryTypes.None)
                        repository.AddData(XmlResult, addToRepository);


                    Completed(this, new ResultCompletionEventArgs());
                    return;
                }
                var args = new ResultCompletionEventArgs { Error = e.Error, WasCancelled = false };
                Completed(this, args);
                EventAgg.Publish(new ErrorMessage(args));
            };
            stopWatch.StopWatchEnded += (sender, e) =>
            {
                var args = new ResultCompletionEventArgs
                {
                    Error = new TimeoutException("Timeout of " + GetType().Name),
                    WasCancelled = false
                };
                EventAgg.Publish(new ErrorMessage(args));
                Completed(this, args);
            };
            stopWatch.Start();
            webClient.OpenReadAsync(new Uri(searchString));
        }
        void IResult.Execute(ActionExecutionContext context)
        {
            var dialog = CreateDialog();

            if (dialog.ShowDialog() != true)
            {
                this.OnCompleted(new ResultCompletionEventArgs
                {
                    WasCancelled = this._IgnoreUserCancel == false
                });
                return;
            }

            var resultArgs = new ResultCompletionEventArgs();

            this.FileNames = dialog.FileNames;

            if (this._FileAction != null)
            {
                try
                {
                    this._FileAction(FileNames);
                }
                catch (Exception e)
                {
                    resultArgs.Error = e;
                }
            }

            this.OnCompleted(resultArgs);
        }
Пример #4
0
 protected virtual void OnCompleted(ResultCompletionEventArgs e)
 {
     var handler = this.Completed;
     if (handler != null)
     {
         handler(this, e);
     }
 }
 private void OnComplete(Exception error, bool wasCancelled)
 {
     this.enumerator.Dispose();
     ResultCompletionEventArgs e = new ResultCompletionEventArgs {
         Error = error,
         WasCancelled = wasCancelled
     };
     this.Completed(this, e);
 }
 /// <summary>
 /// Called when the execution of the decorated result has completed.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="innerResult">The decorated result.</param>
 /// <param name="args">The <see cref="ResultCompletionEventArgs" /> instance containing the event data.</param>
 protected override void OnInnerResultCompleted(CoroutineExecutionContext context, 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));
         Continue(context);
     }
 }
Пример #7
0
        public void Execute(ActionExecutionContext context)
        {
            var windowManager = IoC.Get<IWindowManager>();
            windowManager.ShowDialog(_question);

            var args = new ResultCompletionEventArgs();
            args.WasCancelled = _cancelAnswer.HasValue && _question.GivenAnswer == _cancelAnswer.Value;

            Completed(this, args);
        }
Пример #8
0
        private static async void CoroutineOnCompleted(object sender,
                                                       ResultCompletionEventArgs resultCompletionEventArgs)
        {
            var exception = resultCompletionEventArgs.Error as AggregateException;

            if (exception != null)
            {
                await Task.Yield();
                throw exception.Flatten().InnerException;
            }
        }
Пример #9
0
        /// <summary>
        /// Executes the result using the specified context.
        /// </summary>
        /// <param name="context">The context.</param>
        public void Execute(CoroutineExecutionContext context) {
            var eventArgs = new ResultCompletionEventArgs();

            try {
                toExecute();
            }
            catch (Exception ex) {
                eventArgs.Error = ex;
            }

            Completed(this, eventArgs);
        }
Пример #10
0
 private void ChildCompleted(object sender, ResultCompletionEventArgs args)
 {
     IResult result = sender as IResult;
     if (result != null)
     {
         result.Completed -= new EventHandler<ResultCompletionEventArgs>(this.ChildCompleted);
     }
     if ((args.Error != null) || args.WasCancelled)
     {
         this.OnComplete(args.Error, args.WasCancelled);
     }
     else
     {
         Exception exception;
         bool flag = false;
         try
         {
             flag = this.enumerator.MoveNext();
         }
         catch (Exception exception1)
         {
             exception = exception1;
             this.OnComplete(exception, false);
             return;
         }
         if (flag)
         {
             try
             {
                 IResult current = this.enumerator.Current;
                 IoC.BuildUp(current);
                 current.Completed += new EventHandler<ResultCompletionEventArgs>(this.ChildCompleted);
                 current.Execute(this.context);
             }
             catch (Exception exception2)
             {
                 exception = exception2;
                 this.OnComplete(exception, false);
             }
         }
         else
         {
             this.OnComplete(null, false);
         }
     }
 }
        void IResult.Execute(ActionExecutionContext context)
        {
            var result = MessageBox.Show(this._Text, this._Caption, this._Button, this._Icon, this._DefaultResult, this._Options);

            var resultArgs = new ResultCompletionEventArgs();

            this.Result = result;

            if (this._ResultAction != null)
            {
                try
                {
                    this._ResultAction(result);
                }
                catch (Exception e)
                {
                    resultArgs.Error = e;
                }
            }

            this.OnCompleted(resultArgs);
        }
Пример #12
0
 public ErrorMessage(ResultCompletionEventArgs completionEventArgs)
 {
     CompletionEventArgs = completionEventArgs;
 }
Пример #13
0
 public ErrorMessage(ResultCompletionEventArgs eventArgs)
 {
     EventArgs = eventArgs;
 }
Пример #14
0
        protected override void InnerCompleted(object sender, ResultCompletionEventArgs args)
        {
            base.InnerCompleted(sender, args);

            Executer.OnUIThread(() => this.OnCompleted(new ResultCompletionEventArgs { WasCancelled = args.WasCancelled, Error = args.Error }));
        }
Пример #15
0
 /// <summary>
 /// Raises the <see cref="Completed" /> event.
 /// </summary>
 /// <param name="args">The <see cref="ResultCompletionEventArgs"/> instance containing the event data.</param>
 protected void OnCompleted(ResultCompletionEventArgs args) {
     Completed(this, args);
 }
Пример #16
0
 public void DoCompleted(ResultCompletionEventArgs args) {
     this.Completed(this, args);
 }
Пример #17
0
 /// <summary>
 /// Called when the execution of the decorated result has completed.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="innerResult">The decorated result.</param>
 /// <param name="args">The <see cref="ResultCompletionEventArgs"/> instance containing the event data.</param>
 protected abstract void OnInnerResultCompleted(CoroutineExecutionContext context, IResult innerResult, ResultCompletionEventArgs args);
Пример #18
0
 protected virtual void OnCompleted(object sender, ResultCompletionEventArgs e)
 {
     if (Completed != null)
         Completed(sender, e);
 }
Пример #19
0
 protected static void CreateSut(Action action)
 {
     Sut = new DelegateResult(action);
     Sut.Completed += (sender, args) => CompletionArgs = args;
 }
Пример #20
0
 protected virtual void InnerCompleted(object sender, ResultCompletionEventArgs args)
 {
     ((IResult)sender).Completed -= this.InnerCompleted;
 }
Пример #21
0
 protected virtual void OnCompleted(ResultCompletionEventArgs args)
 {
     this.Completed(this, args);
 }
 void ContinueCompleted(object sender, ResultCompletionEventArgs args) {
     ((IResult)sender).Completed -= ContinueCompleted;
     OnCompleted(new ResultCompletionEventArgs {Error = args.Error, WasCancelled = (args.Error == null)});
 }
Пример #23
0
 protected virtual void OnCompleted(ResultCompletionEventArgs e)
 {
     Caliburn.Micro.Execute.OnUIThread(() => Completed(this, e));
 }
Пример #24
0
 private void HandleAvailabilityError(object sender, ResultCompletionEventArgs e)
 {
     events.Publish(BusyState.NotBusy());
     if (e.Error != null)
         events.Publish(new ErrorState(e.Error, "Could not get station availability."));
 }
 private void OnCompleted(ResultCompletionEventArgs args)
 {
     this._Completed(this, args);
 }
Пример #26
0
 void InnerResultCompleted(object sender, ResultCompletionEventArgs args) {
     innerResult.Completed -= InnerResultCompleted;
     OnInnerResultCompleted(context, innerResult, args);
     context = null;
 }