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

            try
            {
                using (var form = new FuncOutputExecutor <TOutput>()
                {
                    ParentControl = HelperMethods.GetCurrentlyActiveForm(processor.ParentControl),
                    FormTitle = processor.OperationTitle,
                    CanRetry = processor.CanRetry,
                    ShowSuccessMessage = processor.ReportSuccess,
                    IgnoreResponseMessage = processor.IgnoreResponseMessage,
                    SuccessMessage = processor.SuccessMessage,
                    Func = func,
                    CancellationTokenSource = processor.CancellationTokenSource,
                    FormImage = Properties.Resources.rolling,
                    ProgressObject = processor.ProgressObject
                })
                {
                    form.ShowDialog(HelperMethods.GetCurrentlyActiveForm(processor.ParentControl));
                    return(form.Response as IResponse <TOutput>);
                }
            }
            catch (Exception ex)
            {
                return(ResponseFactory <TOutput> .Exception(ex));
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Executes a function
 /// </summary>
 /// <param name="operationTitle">The title of the messagbox</param>
 /// <param name="func">The function 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">When return type id <see cref="IResponse"/>, Ignore 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 <TOutput> Process <TOutput>(string operationTitle, Func <TOutput> func,
                                                     bool retryable, bool showSuccessMessage = false,
                                                     bool ignoreResponseMessage = false, string successMessage = "Processed successfully")
 {
     using (var form = new FuncOutputExecutor <TOutput>(operationTitle, retryable,
                                                        showSuccessMessage, ignoreResponseMessage,
                                                        successMessage).SetAction(func).SetDetail(operationTitle))
     {
         form.ShowDialog();
         return(form.Response as IResponse <TOutput>);
     }
 }
 public static IResponse <TOutput> Process <TOutput>(string operationTitle, Func <TOutput> func,
                                                     bool retryable             = true, bool showSuccessMessage = false,
                                                     bool ignoreResponseMessage = false, string successMessage  = "Processed successfully")
 {
     using (var form = new FuncOutputExecutor <TOutput>
     {
         FormTitle = operationTitle,
         CanRetry = retryable,
         ShowSuccessMessage = showSuccessMessage,
         IgnoreResponseMessage = ignoreResponseMessage,
         SuccessMessage = successMessage,
         Func = func,
         FormImage = Properties.Resources.rolling
     })
     {
         form.ShowDialog(HelperMethods.GetCurrentlyActiveForm());
         return(form.Response as IResponse <TOutput>);
     }
 }