Exemplo n.º 1
0
        /// <summary>
        /// Executes a <see cref="Task"/>
        /// </summary>
        /// <param name="processor"><see cref="Processor"/></param>
        /// <param name="action">The task to execute</param>
        /// <returns><see cref="IResponse"/></returns>
        public static IResponse Process(this Processor processor, Func <Task> action)
        {
            if (processor == null)
            {
                var processNullMessage = $"The provided {nameof(processor)} is null.";
                SweetAlerts.Alert(HelperMethods.GetCurrentlyActiveForm(), string.Empty, processNullMessage, AlertButtons.Ok, AlertType.Error);
                return(ResponseFactory.Error(processNullMessage, ErrorResponseStatus.BadRequest));
            }

            try
            {
                using (var form = new ActionExecutorTask
                {
                    ParentControl = processor.ParentControl,
                    FormTitle = processor.OperationTitle,
                    CanRetry = processor.CanRetry,
                    ShowSuccessMessage = processor.ReportSuccess,
                    IgnoreResponseMessage = processor.IgnoreResponseMessage,
                    SuccessMessage = processor.SuccessMessage,
                    Action = action,
                    CancellationTokenSource = processor.CancellationTokenSource,
                    FormImage = Properties.Resources.rolling,
                    ProgressObject = processor.ProgressObject
                })
                {
                    form.ShowDialog(HelperMethods.GetCurrentlyActiveForm());
                    return(form.Response);
                }
            }
            catch (Exception ex)
            {
                return(ResponseFactory.Exception(ex));
            }
        }
 /// <summary>
 /// Executes an action
 /// </summary>
 /// <param name="operationTitle">The title of the messagbox</param>
 /// <param name="action">The action to execute</param>
 /// <param name="retryable">A flag to allow asking to retry when execution fails</param>
 /// <param name="showSuccessMessage">Show message when execution passes</param>
 /// <param name="ignoreResponseMessage">Ignore messages <see cref="IResponse.Messages"/> returned by the response</param>
 /// <param name="successMessage">The message to show when execution passes</param>
 /// <returns><see cref="IResponse"/></returns>
 public static IResponse ProcessAsync(string operationTitle, Func <Task> action, bool retryable = true,
                                      bool showSuccessMessage = false, bool ignoreResponseMessage = false,
                                      string successMessage   = "Processed successfully")
 {
     using (var form = new ActionExecutorTask(operationTitle, retryable,
                                              showSuccessMessage, ignoreResponseMessage,
                                              successMessage).SetAction(action).SetDetail(operationTitle))
     {
         form.ShowDialog();
         return(form.Response);
     }
 }
 public static IResponse ProcessAsync(string operationTitle, Func <Task> action, bool retryable = true,
                                      bool showSuccessMessage = false, bool ignoreResponseMessage = false,
                                      string successMessage   = "Processed successfully")
 {
     using (var form = new ActionExecutorTask
     {
         FormTitle = operationTitle,
         CanRetry = retryable,
         ShowSuccessMessage = showSuccessMessage,
         IgnoreResponseMessage = ignoreResponseMessage,
         SuccessMessage = successMessage,
         Action = action,
         FormImage = Properties.Resources.rolling
     })
     {
         form.ShowDialog(HelperMethods.GetCurrentlyActiveForm());
         return(form.Response);
     }
 }