/// <summary> /// Executes a <see cref="Func{Task}"/> which returns an <see cref="IResponse"/> /// </summary> /// <param name="processor"><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 <Task <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 FuncOutputResponseExecutorTask { 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(HelperMethods.GetCurrentlyActiveForm()); return(form.Response); } } catch (Exception ex) { return(ResponseFactory.Exception(ex)); } }
/// <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">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 <TOutput> ProcessAsync <TOutput>(string operationTitle, Func <Task <IResponse <TOutput> > > func, bool retryable = true, bool showSuccessMessage = false, bool ignoreResponseMessage = false, string successMessage = "Processed successfully") { using (var form = new FuncOutputResponseExecutorTask <TOutput>(operationTitle, retryable, showSuccessMessage, ignoreResponseMessage, successMessage).SetAction(func).SetDetail(operationTitle)) { form.ShowDialog(); return(form.Response as IResponse <TOutput>); } }
public static IResponse <TOutput> ProcessAsync <TOutput>(string operationTitle, Func <Task <IResponse <TOutput> > > func, bool retryable = true, bool showSuccessMessage = false, bool ignoreResponseMessage = false, string successMessage = "Processed successfully") { using (var form = new FuncOutputResponseExecutorTask <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>); } }