Ejemplo n.º 1
0
        // TODO: Put strings into the resources.
        //
        Task <IXAppScopeInstance> P_ResetComponentAsync(Func <IContext, bool> breakCondition = default, ITriggerSignalProperties triggerSignalProps = default, bool doFailureResponse = default, IContext ctx = default)
        {
            try {
                if (breakCondition is null)
                {
                    breakCondition =
                        (locContext) => {
                        locContext.ThrowIfCancellationRequested();
                        return(!IsActive || HasDeactivationRequested);
                    }
                }
                ;
                //
                var      startTimestamp = StopwatchUtilities.GetTimestampAsTimeSpan();
                IContext locCtx         = default;
                try {
                    var resetNumber        = Interlocked.Increment(ref _resetCounter);
                    var failureResponseDlg = ReadIA(ref _resetFailureResponseDelegate, isNotRequired: true, locationName: nameof(_resetFailureResponseDelegate));
                    var state = new P_ResetState();
                    locCtx = CreateScopedContext(outerCtx: ctx, localTag: state);
                    var logMessagePrologue = $"{(resetNumber == 0 ? "Установка компонента." : $"Замена (переустановка) компонента. Порядковый номер замены: {resetNumber:d}.")} ИД корреляции: {locCtx.FullCorrelationId}.{(triggerSignalProps is null ? string.Empty : $"{Environment.NewLine}\tСобытие-инициатор:{triggerSignalProps.FmtStr().GNLI2()}")}";
                    if (locCtx.IsCancellationRequested())
                    {
                        return(Task.FromCanceled <IXAppScopeInstance>(cancellationToken: locCtx.Ct()));
                    }
                    var resetTask = TaskUtilities.RunOnDefaultScheduler(factory: async() => await doResetAsync(locCtx: locCtx).ConfigureAwait(false));
                    // Вывод результатов ресета в лог.
                    //
#if !DO_NOT_USE_EON_LOGGING_API
                    resetTask
                    .ContinueWith(
                        continuationAction:
                        locTask => {
                        var locDuration = StopwatchUtilities.GetTimestampAsTimeSpan().Subtract(ts: startTimestamp);
                        if (locTask.IsFaulted)
                        {
                            this
                            .IssueError(
                                messagePrologue: logMessagePrologue,
                                message: $"Длительность:{locDuration.ToString("c").FmtStr().GNLI()}{Environment.NewLine}Сбой.",
                                error: locTask.Exception,
                                includeErrorInIssueFaultException: true,
                                severityLevel: locTask.Exception.GetMostHighSeverityLevel(baseLevel: SeverityLevel.Medium));
                            locTask.Exception.MarkAsObserved();
                        }
                        else if (locTask.IsCanceled)
                        {
                            this
                            .IssueWarning(
                                messagePrologue: logMessagePrologue,
                                message: $"Длительность:{locDuration.ToString("c").FmtStr().GNLI()}{Environment.NewLine}Отменено или прервано.",
                                severityLevel: SeverityLevel.Medium);
                        }
                        else
                        {
                            this
                            .IssueInformation(
                                messagePrologue: logMessagePrologue,
                                message: $"Длительность:{locDuration.ToString("c").FmtStr().GNLI()}{Environment.NewLine}Успешно выполнено.{Environment.NewLine}\tНовый экземпляр компонента:{locTask.Result.FmtStr().GNLI2()}",
                                severityLevel: SeverityLevel.Medium);
                        }
                    },
                        continuationOptions: TaskContinuationOptions.ExecuteSynchronously);
#endif
                    // Обработка сбоя ресета.
                    //
                    Task failureResponseTask;
                    if (doFailureResponse && !(failureResponseDlg is null))
                    {
                        failureResponseTask =
                            resetTask
                            .ContinueWith(
                                continuationFunction:
                                locTask => {
                            if (!(state.PreviousComponent is null))
                            {
                                // Корректирующие действие сбоя ресета выполняется только в случае именно замены компонента.
                                //
                                return
                                (doFailureCorrectiveAsync(
                                     locFailure: locTask.Exception,
                                     responseDlg: failureResponseDlg,
                                     locCtx: locCtx,
                                     logMessagePrologue: logMessagePrologue));
                            }
                            else
                            {
                                return(TaskUtilities.FromCanceled());
                            }
                        },
                                continuationOptions: TaskContinuationOptions.PreferFairness | TaskContinuationOptions.OnlyOnFaulted)
                            .Unwrap();
                        // Вывод результатов обработки сбоя в лог.
                        //
#if !DO_NOT_USE_EON_LOGGING_API
                        failureResponseTask
                        .ContinueWith(
                            continuationAction:
                            locTask => {
                            if (locTask.IsFaulted)
                            {
                                this
                                .IssueError(
                                    messagePrologue: logMessagePrologue,
                                    message: $"Корректирующее действие при сбое замены (переустановки) компонента.{Environment.NewLine}Сбой корректирующего действия.",
                                    error: locTask.Exception,
                                    includeErrorInIssueFaultException: true,
                                    severityLevel: locTask.Exception.GetMostHighSeverityLevel(baseLevel: SeverityLevel.High));
                            }
                            else
                            {
                                this
                                .IssueInformation(
                                    messagePrologue: logMessagePrologue,
                                    message: $"Корректирующее действие при сбое замены (переустановки) компонента.{Environment.NewLine}Корректирующее действие успешно выполнено.",
                                    severityLevel: SeverityLevel.Medium);
                            }
                        },
                            continuationOptions: TaskContinuationOptions.ExecuteSynchronously | TaskContinuationOptions.NotOnCanceled);
#endif
                    }
Ejemplo n.º 2
0
            // TODO: Put strings into the resources.
            //
            void P_OnTriggerSignalReceived(ITriggerSignalProperties signalProps)
            {
                var unhandledExceptionObserver = TryReadDA(ref _unhandledExceptionObserver);

                if (!IsDisposeRequested)
                {
                    try {
                        Exception signalCaughtException = default;
                        try {
                            OnSignal(signalProps: signalProps);
                        }
                        catch (Exception exception) {
                            signalCaughtException = new EonException(message: $"Ошибка обработчика сигнала триггера по подписке.{Environment.NewLine}\tСигнал:{signalProps.FmtStr().GNLI2()}", innerException: exception);
                        }
                        try { P_SubscribeToNextSignal(); }
                        catch (Exception exception) {
                            if (signalCaughtException is null)
                            {
                                throw;
                            }
                            else
                            {
                                throw new AggregateException(signalCaughtException, exception);
                            }
                        }
                    }
                    catch (Exception exception) {
                        if (!unhandledExceptionObserver.ObserveException(exception: exception, component: signalProps))
                        {
                            throw;
                        }
                    }
                }
            }