Exemplo n.º 1
0
        public async Task ExecuteTask(object parameter)
        {
            if (CanExecute == false)
                return;

            using (LogContext.PushProperty("Initiator", GetType().Name))
            using (Log.Logger.BeginTimedOperation("Executing " + GetType().Name, warnIfExceeds: TimeSpan.FromSeconds(5)))
            {
                IsExecuting = true;
                NotifyOfPropertyChange(() => IsExecuting);
                RaiseCanExecuteChanged();

                try
                {
                    await ExecuteAsync(parameter);
                }
                catch (Exception ex)
                {
                    var args = new AsyncActionErrorArgs();
                    ExecuteOnError(ex, args);
                    if (!args.IsHandled)
                        Caliburn.Micro.Execute.BeginOnUIThread(() => { throw new Exception("Failed executing {0}: {1}".FormatWith(GetType().Name, ex.Message), ex); });
                }
                finally
                {
                    IsExecuting = false;
                    NotifyOfPropertyChange(() => IsExecuting);
                    RaiseCanExecuteChanged();
                }
            }
        }
Exemplo n.º 2
0
        public async Task ExecuteTask(object parameter)
        {
            if (CanExecute == false)
            {
                return;
            }

            using (LogContext.PushProperty("Initiator", GetType().Name))
                using (Log.Logger.BeginTimedOperation("Executing " + GetType().Name, warnIfExceeds: TimeSpan.FromSeconds(5)))
                {
                    IsExecuting = true;
                    NotifyOfPropertyChange(() => IsExecuting);
                    RaiseCanExecuteChanged();

                    try
                    {
                        await ExecuteAsync(parameter);
                    }
                    catch (Exception ex)
                    {
                        var args = new AsyncActionErrorArgs();
                        ExecuteOnError(ex, args);
                        if (!args.IsHandled)
                        {
                            Caliburn.Micro.Execute.BeginOnUIThread(() => { throw new Exception("Failed executing {0}: {1}".FormatWith(GetType().Name, ex.Message), ex); });
                        }
                    }
                    finally
                    {
                        IsExecuting = false;
                        NotifyOfPropertyChange(() => IsExecuting);
                        RaiseCanExecuteChanged();
                    }
                }
        }
Exemplo n.º 3
0
 protected virtual void ExecuteOnError(Exception e, AsyncActionErrorArgs args) { }
Exemplo n.º 4
0
 protected virtual void ExecuteOnError(Exception e, AsyncActionErrorArgs args)
 {
 }