/// <summary>
        /// Executes a function
        /// </summary>
        /// <param name="processor">The <see cref="Processor"/></param>
        /// <param name="func">The function to execute</param>
        /// <returns><see cref="IResponse"/></returns>
        public static IResponse Process(this Processor processor, Func <IResponse> 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.Error(processNullMessage, ErrorResponseStatus.BadRequest));
            }

            try
            {
                using (var form = new FuncOutputResponseExecutor
                {
                    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);
                }
            }
            catch (Exception ex)
            {
                return(ResponseFactory.Exception(ex));
            }
        }
        /// <summary>
        /// Executes a <see cref="Func{Task}"/> which returns a <see cref="Task{TOutput}"/>
        /// </summary>
        /// <param name="processor"><see cref="Processor"/></param>
        /// <param name="func">The function to execute</param>
        /// <returns><see cref="IResponse"/></returns>
        public static IResponse <TOutput> Process <TOutput>(this Processor processor, Func <Task <TOutput> > func)
        {
            if (processor == null)
            {
                var processNullMessage = $"The provided {nameof(processor)} is null.";
                SweetAlerts.Alert(string.Empty, processNullMessage, AlertButtons.Ok, AlertType.Error);
                return(ResponseFactory <TOutput> .Error(processNullMessage, ErrorResponseStatus.BadRequest));
            }

            try
            {
                using (var form = new FuncOutputExecutorTask <TOutput>
                {
                    ParentControl = 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();
                    return(form.Response as IResponse <TOutput>);
                }
            }
            catch (Exception ex)
            {
                return(ResponseFactory <TOutput> .Exception(ex));
            }
        }
Beispiel #3
0
        private async Task ExecuteAsync()
        {
            while (true)
            {
                Response = await ExecuteRequestAsync();

                if (!Response.Success)
                {
                    if (Retryable)
                    {
                        var retrySelection = SweetAlerts.Alert(OperationTitle, Response.Messages.ToList(), AlertButtons.RetryCancel, AlertType.Error);
                        if (retrySelection != DialogResult.Retry)
                        {
                            return;
                        }
                        continue;
                    }
                }

                SweetAlerts.AlertResponse(OperationTitle, Response, ShowSuccessMessage, IgnoreResponseMessage, SuccessMessage);
                break;
            }
        }