/// <summary> /// 変換を行います。 /// </summary> /// <param name="parameter">変換パラメーター。</param> public ConvertResultType Convert(IConvertParameter parameter) { var cea = new CancelEventArgs(); cea.Cancel = false; Prepare?.Invoke(parameter, cea); if (cea.Cancel) { var r = new ConvertResultType(); r = ConvertResultType.Cancelled; var ccea = new ConvertCompleteEventArgs(); ccea.Result = ConvertResultType.Cancelled; ConvertCompleted?.Invoke(parameter, ccea); return(r); } try { return(onConvert(parameter)); } catch (Exception e) { var result = new ConvertCompleteEventArgs(); result.Result = ConvertResultType.Failed; result.Error = e; ConvertCompleted?.Invoke(parameter, result); return(result.Result); } }
/// <summary> /// Производит единичную попытку выполнить действие работы, /// выполняет подготовительный и непосредственный этапы работы /// </summary> /// <param name="input">Входные данные для подготовительного этапа</param> /// <returns></returns> internal virtual TOutput ExecuteInternal(TInput input) { Prepare?.Invoke(input); Log.Warn(Description); return(Process.Invoke()); }
/// <summary> /// 変換を行います。 /// </summary> /// <param name="parameter">変換パラメーター。</param> /// <returns>ConvertResult のタスク。</returns> public async Task <ConvertResultType> ConvertAsync(IConvertParameter parameter) { var e = new CancelEventArgs(); e.Cancel = false; Prepare?.Invoke(parameter, e); if (e.Cancel) { var r = new ConvertResultType(); r = ConvertResultType.Cancelled; var cea = new ConvertCompleteEventArgs(); cea.Result = ConvertResultType.Cancelled; ConvertCompleted?.Invoke(parameter, cea); return(r); } var result = await onConvertTask(parameter); return(result); }
/// <summary> /// 変換を行う。 /// </summary> /// <param name="parameter">変換パラメーター。</param> /// <param name="token">キャンセルトークン。</param> /// <returns>変換結果。</returns> private ConvertResultType Convert(T parameter, CancellationToken token) { Parameter = parameter; var cea = new CancelEventArgs(); cea.Cancel = false; Prepare?.Invoke(parameter, cea); if (cea.Cancel) { var ccea = new ConvertCompleteEventArgs(); ccea.Result = ConvertResultType.Cancelled; Completed?.Invoke(parameter, ccea); return(ConvertResultType.Cancelled); } try { token.ThrowIfCancellationRequested(); var result = DoConvert(parameter, token); Completed?.Invoke(parameter, result); return(result.Result); } catch (OperationCanceledException ex) { var result = new ConvertCompleteEventArgs(); result.Result = ConvertResultType.Cancelled; result.Error = ex; Completed?.Invoke(parameter, result); return(result.Result); } catch (Exception ex) { var result = new ConvertCompleteEventArgs(); result.Result = ConvertResultType.Failed; result.Error = ex; Completed?.Invoke(parameter, result); return(result.Result); } }
public PREPARED Prepare(INPUT input) { return(prepare != null?prepare.Invoke(input) : default(PREPARED)); }
protected override void OnStart() { Prepare?.Invoke(this, EventArgs.Empty); OnTimerStart(); }