// TODO: Put strings into the resources. // internal static Exception Internal_CreateNullValueException(bool isPropertyValue, string name, ExceptionFactoryDelegate2 exceptionFactory = default) { var exceptionMessage = isPropertyValue ? $"Не указано значение свойства '{name}'." : $"Значение не может быть '{FormatStringUtilitiesCoreL0.GetNullValueText()}'."; return (exceptionFactory?.Invoke(message: exceptionMessage) ?? new ArgumentNullException(message: exceptionMessage, paramName: name)); }
public override string ToString() => Value?.ToString() ?? FormatStringUtilitiesCoreL0.GetNullValueText();
// TODO: Put strings into the resources. // static void P_ProvideResult(P_SessionObject session, TaskCompletionSource <TResult> resultConsumer, IContext ctx = default) { session.EnsureNotNull(nameof(session)); resultConsumer.EnsureNotNull(nameof(resultConsumer)); // var unhandledExceptionObserver = session.P_UnhandledExceptionObserver; var ct = ctx.Ct(); var ctRegistration = default(CancellationTokenRegistration?); resultConsumer.Task.ContinueWith(continuationAction: locTask => itrlck.Or(ref session._executionStateFlag, __ExecutionStateFlag_Completed), continuationOptions: TaskContinuationOptions.ExecuteSynchronously); resultConsumer.Task.ContinueWith(continuationAction: locTask => ctRegistration?.Dispose(), continuationOptions: TaskContinuationOptions.PreferFairness); // var previousExecutionStateFlag = itrlck.Or(location: ref session._executionStateFlag, value: __ExecutionStateFlag_AboutExecution); if (previousExecutionStateFlag == __ExecutionStateFlag_None) { // Флаг отмены до начала выполнения не был установлен. // if (ct.IsCancellationRequested) { if (session.P_TrySetResultAsCanceled(ct)) { resultConsumer.TrySetCanceled(); } } else { if (ct.CanBeCanceled) { ctRegistration = ct.Register(callback: () => { if (session.P_TrySetResultAsCanceled(ct)) { resultConsumer.TrySetCanceled(); } }); } // var factoryTask = Task .Factory .StartNew( function: () => { // Собственно, здесь выполняется делегат операции, указанный одним из конструкторов AsyncOperator`1. // var locFactoryTask = session.P_Factory(arg: ctx); if (locFactoryTask is null) { throw new EonException(message: $"Factory method has returned invalid result '{FormatStringUtilitiesCoreL0.GetNullValueText()}'.{Environment.NewLine}\tMethod:{session.P_Factory.FmtStr().GNLI2()}"); } return(locFactoryTask); }, cancellationToken: ct, creationOptions: TaskCreationOptions.PreferFairness, scheduler: TaskScheduler.Default) .Unwrap(); var factoryTaskResultHandlingTask = factoryTask .ContinueWith( continuationAction: locTask => { if (locTask.IsCanceled) { if (session.P_TrySetResultAsCanceled(ct: CancellationToken.None)) { resultConsumer.TrySetCanceled(cancellationToken: CancellationToken.None); } } else if (locTask.IsFaulted) { var locTaskException = locTask.Exception.Flatten(); try { if (session.P_TrySetResultAsFaulted(locTaskException)) { resultConsumer.TrySetException(locTaskException); return; } } catch (Exception locException) { throw new AggregateException(locTaskException, locException); } throw new AggregateException(locTaskException); } else if (session.P_TrySetOrDisposeResult(locTask.Result)) { resultConsumer.TrySetResult(locTask.Result); } }, cancellationToken: CancellationToken.None, continuationOptions: TaskContinuationOptions.PreferFairness, scheduler: TaskScheduler.Default); if (!(unhandledExceptionObserver is null || ReferenceEquals(objA: unhandledExceptionObserver, objB: NopUnhandledExceptionObserver.Instance))) { factoryTaskResultHandlingTask .ContinueWith( continuationAction: locTask => { var locTaskException = locTask.Exception.Flatten(); try { if (unhandledExceptionObserver.ObserveException(exception: locTaskException, component: session, message: $"An exception was thrown by async operator ({nameof(AsyncOperator<TResult>)}) session.", exceptionCtx: ctx)) { return; } } catch (Exception locException) { throw new AggregateException(locTaskException, locException); } throw new AggregateException(locTaskException); }, continuationOptions: TaskContinuationOptions.OnlyOnFaulted, cancellationToken: default,
#pragma warning disable IDE0060 // Remove unused parameter public static string GetNullValueText(IFormatProvider formatProvider) #pragma warning restore IDE0060 // Remove unused parameter => FormatStringUtilitiesCoreL0.GetNullValueText();
public static string GetNullValueText() => FormatStringUtilitiesCoreL0.GetNullValueText();
public static string Status(this FormatStringUtilitiesHandle <HttpResponseMessage> hnd) => hnd.Object is null?FormatStringUtilitiesCoreL0.GetNullValueText() : $"Статус-код:{Environment.NewLine}{hnd.Object.StatusCode.FmtStr().G().IndentLines()}{Environment.NewLine}Сообщение ({nameof(hnd.Object.ReasonPhrase)}):{hnd.Object.ReasonPhrase.FmtStr().GNLI()}";
public static string H(this FormatStringUtilitiesHandle <byte?> hnd) => hnd.Object.HasValue ? "0x" + hnd.Object.Value.ToString("x2", provider: CultureInfo.InvariantCulture) : FormatStringUtilitiesCoreL0.GetNullValueText();