Ejemplo n.º 1
0
 public DependencyResult(object instance, bool isNewInstance)
 {
     instance.EnsureNotNull(nameof(instance));
     //
     _instance        = instance;
     _isNewInstance   = isNewInstance;
     _redirectHandler = null;
 }
Ejemplo n.º 2
0
 public DependencyResult(IDependencyHandler2 redirectHandler)
 {
     redirectHandler.EnsureNotNull(nameof(redirectHandler));
     //
     _redirectHandler = redirectHandler;
     _instance        = null;
     _isNewInstance   = false;
 }
 public DefaultDependencyExporter(IDependencyHandler2 handler, bool ownsHandler = default)
 {
     handler.EnsureNotNull(nameof(handler));
     //
     _dependencies       = null;
     _handlerChain       = new IVh <IDependencyHandler2>[] { handler.ToValueHolder(ownsValue: ownsHandler) };
     _exportDependencies = P_ExportDependencies_FromHandlerChain;
 }
Ejemplo n.º 4
0
 public virtual IDependencyHandler2[] GetInvolvedHandlerChain()
 {
     return
         (ReadDA(ref _involvedHandlerSpinLock)
          .Invoke(
              () => {
         var locInvolvedHandlerChain = ReadDA(ref _involvedHandlerChain);
         var locResult = new IDependencyHandler2[locInvolvedHandlerChain.Count];
         if (locResult.Length > 0)
         {
             locInvolvedHandlerChain.CopyTo(array: locResult, arrayIndex: 0);
         }
         return locResult;
     }));
 }
Ejemplo n.º 5
0
 DependencyResult(object instance, bool isNewInstance, IDependencyHandler2 redirectHandler)
 {
     _instance        = instance;
     _isNewInstance   = isNewInstance;
     _redirectHandler = redirectHandler;
 }
 public bool Remove(IDependencyHandler2 handler)
 => throw new EonException(FormatXResource(typeof(InvalidOperationException), "CanNotModifyObjectDueReadOnly", this));
 public bool Contains(IDependencyHandler2 handler)
 => handler is null ? false : ReadDA(ref _handlerUniqueSet).Contains(handler);
 public void Add(IDependencyHandler2 handler)
 {
     handler.EnsureNotNull(nameof(handler));
     //
     throw new EonException(FormatXResource(typeof(InvalidOperationException), "CanNotModifyObjectDueReadOnly", this));
 }
 public DependencyResolutionModel(IDependencyHandler2 handler = default, bool ownsHandler = default)
     : this(handlerChainSource : handler is null ? null : new[] { handler.ToValueHolder(ownsHandler) })
 {
 }
Ejemplo n.º 10
0
        public virtual bool TryInvolveHandler(IDependencyHandler2 handler, IDependencyHandler2 referrer = null)
        {
            handler.EnsureNotNull(nameof(handler));
            //
            var involvedExecutorsCounters = ReadDA(ref _involvedHandlerCounters);
            var involvedExecutorsChain    = ReadDA(ref _involvedHandlerChain);
            var spinLock = ReadDA(ref _involvedHandlerSpinLock);
            //
            var result = default(bool);
            var error  = default(Exception);

            try {
                result =
                    spinLock.Invoke(
                        () => {
                    EnsureNotDisposeState(considerDisposeRequest: true);
                    //
                    if (involvedExecutorsCounters.ContainsKey(handler))
                    {
                        if (involvedExecutorsCounters[handler] >= ExecutionsCountLimitPerExecutor)
                        {
                            return(false);
                        }
                        else
                        {
                            involvedExecutorsCounters[handler] += 1;
                        }
                    }
                    else
                    {
                        involvedExecutorsCounters.Add(handler, 1);
                    }
                    involvedExecutorsChain.Add(handler);
                    return(true);
                });
            }
            catch (Exception exception) {
                error = exception;
                throw;
            }
            finally {
                if (_isAdvancedLoggingEnabled)
                {
                    string contextDetailsText;
                    using (var acquiredBuffer = EonStringBuilderUtilities.AcquireBuffer()) {
                        var sb = acquiredBuffer.StringBuilder;
                        sb.AppendLine("Параметры разрешения функциональной зависимости:");
                        sb.AppendLine(Specs.ToString().IndentLines());
                        sb.AppendLine("Область функциональной зависимости:");
                        sb.AppendLine(Scope.ToString().IndentLines());
                        contextDetailsText = sb.ToString();
                    }
#if !DO_NOT_USE_EON_LOGGING_API
                    if (error is null)
                    {
                        this.IssueInformation(
                            $"Разрешение функциональной зависимости (ИД контекста '{_sequentialId:d}').",
                            $"Операция '{nameof(TryInvolveExecutor)}'.{Environment.NewLine}\tПараметры операции:{Environment.NewLine}\t\t{nameof(executor)}:{Environment.NewLine}{executor.ToString().IndentLines(indentSize: 3)}{Environment.NewLine}\t\t{nameof(referrer)}:{Environment.NewLine}{referrer.TextView().IndentLines(indentSize: 3)}{Environment.NewLine}\tКонтекст:{Environment.NewLine}{contextDetailsText.IndentLines(indentSize: 2)}{Environment.NewLine}\tРезультат: {result}");
                    }
                    else
                    {
                        try {
                            this.IssueError(
                                $"Разрешение функциональной зависимости (ИД контекста '{_sequentialId:d}').",
                                $"Операция '{nameof(TryInvolveExecutor)}'. Ошибка выполнения операции.{Environment.NewLine}\tПараметры операции:{Environment.NewLine}\t\t{nameof(executor)}:{Environment.NewLine}{executor.ToString().IndentLines(indentSize: 3)}{Environment.NewLine}\t\t{nameof(referrer)}:{Environment.NewLine}{referrer.TextView().IndentLines(indentSize: 3)}{Environment.NewLine}\tКонтекст:{Environment.NewLine}{contextDetailsText.IndentLines(indentSize: 2)}",
                                error,
                                severityLevel: SeverityLevel.High);
                        }
                        catch (Exception firstException) {
                            throw new AggregateException(error, firstException);
                        }
                    }
#endif
                }
            }
            //
            return(result);
        }
Ejemplo n.º 11
0
 public virtual bool HasHandlerInvolved(IDependencyHandler2 handler)
 {
     handler.EnsureNotNull(nameof(handler));
     //
     return(ReadDA(ref _involvedHandlerSpinLock).Invoke(() => ReadDA(ref _involvedHandlerCounters).ContainsKey(handler)));
 }