예제 #1
0
        public DynamicInvoker(string diagnosticSourceAssemblyName, Type diagnosticSourceType, Type diagnosticListenerType)
        {
            Validate.NotNull(diagnosticSourceAssemblyName, nameof(diagnosticSourceAssemblyName));

            _diagnosticSourceAssemblyName = diagnosticSourceAssemblyName;
            _diagnosticSourceInvoker      = new DynamicInvoker_DiagnosticSource(diagnosticSourceType);
            _diagnosticListenerInvoker    = new DynamicInvoker_DiagnosticListener(diagnosticListenerType);

            _invalidationListeners = new DynamicInvokerInvalidationListenersCollection(nameof(DynamicInvoker), this);

            _isValid = 1;
        }
        internal static bool TryWrap(object diagnosticSourceInstance, out DiagnosticSourceStub diagnosticSourceStub)
        {
            if (diagnosticSourceInstance == null)
            {
                diagnosticSourceStub = NoOpSingeltons.DiagnosticSourceStub;
                return(true);
            }

            DynamicInvoker_DiagnosticSource invoker = DynamicInvoker.Current.DiagnosticSource;

            if (invoker != null && invoker.TryGetInvokerHandleForInstance(diagnosticSourceInstance, out DynamicInvokerHandle <DynamicInvoker_DiagnosticSource> handle))
            {
                diagnosticSourceStub = new DiagnosticSourceStub(diagnosticSourceInstance, handle);
                return(true);
            }
            else
            {
                diagnosticSourceStub = NoOpSingeltons.DiagnosticSourceStub;
                return(false);
            }
        }
        public void Write(string eventName, object payloadValue)
        {
            Validate.NotNull(eventName, nameof(eventName));
            // payloadValue may be null

            if (_diagnosticSourceInstance == null)
            {
                return;
            }

            DynamicInvoker_DiagnosticSource invoker = null;

            try
            {
                invoker = _dynamicInvokerHandle.GetInvoker();
                invoker.Call.Write(_diagnosticSourceInstance, eventName, payloadValue);
            }
            catch (Exception ex)
            {
                throw LogAndRethrowStubInvocationError(ex, nameof(DynamicInvoker_DiagnosticSource.StubbedApis.Write), isStaticApi: false, invoker?.TargetType);
            }
        }
        public bool IsEnabled(string eventName, object arg1, object arg2)
        {
            Validate.NotNull(eventName, nameof(eventName));
            // arg1 and arg2 may be null

            if (_diagnosticSourceInstance == null)
            {
                return(NoOpSingeltons.IsEnabled);
            }

            DynamicInvoker_DiagnosticSource invoker = null;

            try
            {
                invoker = _dynamicInvokerHandle.GetInvoker();
                return(invoker.Call.IsEnabled(_diagnosticSourceInstance, eventName, arg1, arg2));
            }
            catch (Exception ex)
            {
                throw LogAndRethrowStubInvocationError(ex, nameof(DynamicInvoker_DiagnosticSource.StubbedApis.IsEnabled), isStaticApi: false, invoker?.TargetType);
            }
        }
        public static DiagnosticSourceStub Wrap(object diagnosticSourceInstance)
        {
            if (diagnosticSourceInstance == null)
            {
                return(NoOpSingeltons.DiagnosticSourceStub);
            }

            DynamicInvoker_DiagnosticSource invoker = null;

            try
            {
                invoker = DynamicInvoker.Current.DiagnosticSource;
                DynamicInvokerHandle <DynamicInvoker_DiagnosticSource> handle = invoker.GetInvokerHandleForInstance(diagnosticSourceInstance);
                return(new DiagnosticSourceStub(diagnosticSourceInstance, handle));
            }
            catch (Exception ex)
            {
                throw ErrorUtil.LogAndRethrowStubInvocationError(ErrorUtil.CannotCreateStubMsg,
                                                                 ex,
                                                                 typeof(DynamicInvoker_DiagnosticSource),
                                                                 invoker?.TargetType,
                                                                 diagnosticSourceInstance);
            }
        }
 internal StubbedApis(DynamicInvoker_DiagnosticSource thisInvoker)
 {
     _thisInvoker     = thisInvoker;
     _cashedDelegates = new CashedDelegates();
 }