Ejemplo n.º 1
0
        public void Register(IDisposable disposable)
        {
            disposable.EnsureNotNull(nameof(disposable));
            //
            var spinLock      = ReadDA(ref _disposablesSpinLock);
            var weakReference = new StrictedWeakReference(target: disposable, trackResurrection: false);

            spinLock
            .Invoke(
                action:
                () => {
                var locRegistry = ReadDA(ref _disposableWeakReferences, considerDisposeRequest: true);
                if (locRegistry.Count % _cleanupThreshold == 0)
                {
                    for (var i = locRegistry.Count - 1; i > -1; i--)
                    {
                        if (!locRegistry[i].TryGetTarget(out _))
                        {
                            locRegistry.RemoveAt(i);
                        }
                    }
                }
                locRegistry.Add(item: weakReference);
            });
        }
Ejemplo n.º 2
0
        // TODO: Put strings into the resources.
        //
        void P_ResetTrigger_OnSignal(ITriggerSignalProperties signalProps, IDisposable subscription)
        {
            signalProps.EnsureNotNull(nameof(signalProps));
            subscription.EnsureNotNull(nameof(subscription));
            //
            var resetTrigger             = TryReadDA(ref _resetTrigger);
            var resetTriggerSubscription = TryReadDA(ref _resetTriggerSignalSubscription, considerDisposeRequest: true);

            if (ReferenceEquals(resetTrigger, signalProps.Trigger) && ReferenceEquals(resetTriggerSubscription, subscription))
            {
                try { if (signalProps.Trigger.IsDisabled)
                      {
                          return;
                      }
                }
                catch (ObjectDisposedException) { return; }
                if (IsActive)
                {
                    TaskUtilities.RunOnDefaultScheduler(factory: () => resetComponentAsync(locTriggerSignalProps: signalProps));
                }
            }
            //
            async Task resetComponentAsync(ITriggerSignalProperties locTriggerSignalProps)
            {
                try {
                    using (var localCtx = ContextUtilities.Create(fullCorrelationId: signalProps.CorrelationId))
                        await P_ResetComponentAsync(triggerSignalProps : locTriggerSignalProps, doFailureResponse : true, ctx : localCtx).ConfigureAwait(false);
                }
                catch (Exception exception) {
                    if (!((exception is ObjectDisposedException && IsDisposeRequested) || exception.HasSingleBaseExceptionOf <OperationCanceledException>() || exception.IsObserved()))
                    {
#if !DO_NOT_USE_EON_LOGGING_API
                        this
                        .IssueError(
                            message: $"Сбой установки (замены) компонента, инициированной триггером.{Environment.NewLine}\tСобытие-инициатор:{locTriggerSignalProps.FmtStr().GNLI2()}",
                            error: exception,
                            includeErrorInIssueFaultException: true,
                            severityLevel: exception.GetMostHighSeverityLevel(baseLevel: SeverityLevel.Medium));
#endif
                    }
                }
            }
        }