예제 #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();
                }
            }
        }
예제 #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();
                    }
                }
        }
예제 #3
0
 protected virtual void ExecuteOnError(Exception e, AsyncActionErrorArgs args) { }
예제 #4
0
 protected virtual void ExecuteOnError(Exception e, AsyncActionErrorArgs args)
 {
 }