/// <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="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); }
private ConvertResult(ConvertResultType resultType) { ResultType = resultType; }