Пример #1
0
        public FilterActionInvoker(
            [NotNull] ActionContext actionContext,
            [NotNull] IReadOnlyList <IFilterProvider> filterProviders,
            [NotNull] IReadOnlyList <IInputFormatter> inputFormatters,
            [NotNull] IReadOnlyList <IOutputFormatter> outputFormatters,
            [NotNull] IReadOnlyList <IModelBinder> modelBinders,
            [NotNull] IReadOnlyList <IModelValidatorProvider> modelValidatorProviders,
            [NotNull] IReadOnlyList <IValueProviderFactory> valueProviderFactories,
            [NotNull] IActionBindingContextAccessor actionBindingContextAccessor,
            [NotNull] ILogger logger,
            [NotNull] TelemetrySource telemetry,
            int maxModelValidationErrors)
        {
            ActionContext = actionContext;

            _filterProviders              = filterProviders;
            _inputFormatters              = inputFormatters;
            _outputFormatters             = outputFormatters;
            _modelBinders                 = modelBinders;
            _modelValidatorProviders      = modelValidatorProviders;
            _valueProviderFactories       = valueProviderFactories;
            _actionBindingContextAccessor = actionBindingContextAccessor;
            _logger    = logger;
            _telemetry = telemetry;
            _maxModelValidationErrors = maxModelValidationErrors;
        }
Пример #2
0
        private void EnsureServices(HttpContext context)
        {
            if (_actionContextAccessor == null)
            {
                _actionContextAccessor = context.RequestServices.GetRequiredService <IActionContextAccessor>();
            }

            if (_actionInvokerFactory == null)
            {
                _actionInvokerFactory = context.RequestServices.GetRequiredService <IActionInvokerFactory>();
            }

            if (_actionSelector == null)
            {
                _actionSelector = context.RequestServices.GetRequiredService <IActionSelector>();
            }

            if (_logger == null)
            {
                var factory = context.RequestServices.GetRequiredService <ILoggerFactory>();
                _logger = factory.CreateLogger <MvcRouteHandler>();
            }

            if (_telemetry == null)
            {
                _telemetry = context.RequestServices.GetRequiredService <TelemetrySource>();
            }
        }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Telemetry"/> class.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="level">The level.</param>
 /// <param name="body">The body.</param>
 public Telemetry(
     TelemetrySource source
     , TelemetryLevel level
     , TelemetryBody body
     )
     : this(source, level, body, null)
 {
 }
Пример #4
0
        // Subscription implementation
        /// <summary>
        /// Add a subscriber, Dispose the returned value to unsubscribe.  Every
        /// subscribers will have their IsEnabled and WriteData methods called
        /// whenever a producer is needs to cause a notification.
        /// </summary>
        public IDisposable Subscribe(TelemetrySource subscriber)
        {
            Subscription newSubscription = new Subscription()
            {
                Subscriber = subscriber, Owner = this, Next = m_subscriptions
            };

            while (Interlocked.CompareExchange(ref m_subscriptions, newSubscription, newSubscription.Next) != newSubscription.Next)
            {
                newSubscription.Next = m_subscriptions;
            }
            return(newSubscription);
        }
Пример #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Telemetry"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="level">The level.</param>
        /// <param name="body">The body.</param>
        /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
        public Telemetry(
            TelemetrySource source
            , TelemetryLevel level
            , TelemetryBody body
            , IDictionary <string, object> arbitraryKeyValuePairs = null
            )
            : base(arbitraryKeyValuePairs)
        {
            Assumption.AssertNotNull(body, nameof(body));

            this.Timestamp = DateTimeUtil.ConvertToUnixTimestampInMilliseconds(DateTime.UtcNow);
            this.Source    = source;
            this.Level     = level;
            this.Type      = body.Type;
            this.Body      = body;

            Validate();
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Telemetry"/> class.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="level">The level.</param>
        /// <param name="body">The body.</param>
        /// <param name="arbitraryKeyValuePairs">The arbitrary key value pairs.</param>
        public Telemetry(
            TelemetrySource source
            , TelemetryLevel level
            , TelemetryBody body
            , IDictionary <string, object> arbitraryKeyValuePairs = null
            )
            : base(arbitraryKeyValuePairs)
        {
            Assumption.AssertNotNull(body, nameof(body));

            this.Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalMilliseconds;
            this.Source    = source;
            this.Level     = level;
            this.Type      = body.Type;
            this.Body      = body;

            Validate();
        }
Пример #7
0
    static void Main()
    {
        // This allows EventSources to listen to notifications.
        // TODO this seems counterintuitive/unnecessary.
        TelemetryEventSource.LogForDefaultNotificationHub.Touch();

        // To set up a sink for notifications IObserver and hook up.
        var consoleObserver = new ConsoleObserver("Default");

        using (var subscription = TelemetryListener.Default.Subscribe(consoleObserver, consoleObserver.IsEnabled))
        {
            // This simulates an application that is creating Dispatcher/Notifier pairs for instantiable in-process contexts.
            // The child hubs each cross-talk with the default hub, but do not cross-talk with each other
            using (var island1 = new TelemetryListener("Island1"))
                using (var island2 = new TelemetryListener("Island2"))
                    using (island1.Subscribe(new ConsoleObserver(island1.Name)))
                        using (island2.Subscribe(new ConsoleObserver(island2.Name)))
                        {
                            // Here we simulate what might happen in the class library where we don't use dependency injection.
                            // You can also get you iNotifier by asking IServiceProvider which might make one per tenant.
                            TelemetrySource defaultSource = TelemetrySource.Default;
                            TelemetrySource islandSource1 = island1;
                            TelemetrySource islandSource2 = island2;

                            // Normally this would be in code that was receiving the HttpRequestResponse
                            HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Get, "http://localhost/");

                            // Here we log for simple cases as show below we don't need to do the ShuldNotify, but we are
                            // showing the general case where there might be significant work setting up the payload.
                            if (defaultSource.IsEnabled("OutgoingHttpRequestReturns"))
                            {
                                // Here we are assuming we would like to log both to EventSource and direct subscribers to
                                // NotificationHub.   Because of this the payload class contains both serializable fields (like
                                // ReqeustUri which we resolve to a string), as well as rich objects (like Message) that are
                                // stripped from EventSource serialization.
                                defaultSource.WriteTelemetry("OutgoingHttpRequestReturns", new { RequestUri = message.RequestUri.ToString(), Message = message });
                            }

                            islandSource1.WriteTelemetry("TalkingOnIsland", "Island One");
                            islandSource2.WriteTelemetry("TalkingOnIsland", "Island Two");
                        }
        }
    }
Пример #8
0
        public ControllerActionInvoker(
            [NotNull] ActionContext actionContext,
            [NotNull] IReadOnlyList <IFilterProvider> filterProviders,
            [NotNull] IControllerFactory controllerFactory,
            [NotNull] ControllerActionDescriptor descriptor,
            [NotNull] IReadOnlyList <IInputFormatter> inputFormatters,
            [NotNull] IReadOnlyList <IOutputFormatter> outputFormatters,
            [NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder,
            [NotNull] IReadOnlyList <IModelBinder> modelBinders,
            [NotNull] IReadOnlyList <IModelValidatorProvider> modelValidatorProviders,
            [NotNull] IReadOnlyList <IValueProviderFactory> valueProviderFactories,
            [NotNull] IActionBindingContextAccessor actionBindingContextAccessor,
            [NotNull] ILogger logger,
            [NotNull] TelemetrySource telemetry,
            int maxModelValidationErrors)
            : base(
                actionContext,
                filterProviders,
                inputFormatters,
                outputFormatters,
                modelBinders,
                modelValidatorProviders,
                valueProviderFactories,
                actionBindingContextAccessor,
                logger,
                telemetry,
                maxModelValidationErrors)
        {
            _descriptor        = descriptor;
            _controllerFactory = controllerFactory;
            _argumentBinder    = controllerActionArgumentBinder;

            if (descriptor.MethodInfo == null)
            {
                throw new ArgumentException(
                          Resources.FormatPropertyOfTypeCannotBeNull("MethodInfo",
                                                                     typeof(ControllerActionDescriptor)),
                          "descriptor");
            }
        }
 public ControllerActionInvokerProvider(
     IControllerFactory controllerFactory,
     IEnumerable <IFilterProvider> filterProviders,
     IControllerActionArgumentBinder argumentBinder,
     IOptions <MvcOptions> optionsAccessor,
     IActionBindingContextAccessor actionBindingContextAccessor,
     ILoggerFactory loggerFactory,
     TelemetrySource telemetry)
 {
     _controllerFactory            = controllerFactory;
     _filterProviders              = filterProviders.OrderBy(item => item.Order).ToArray();
     _argumentBinder               = argumentBinder;
     _inputFormatters              = optionsAccessor.Value.InputFormatters.ToArray();
     _outputFormatters             = optionsAccessor.Value.OutputFormatters.ToArray();
     _modelBinders                 = optionsAccessor.Value.ModelBinders.ToArray();
     _modelValidatorProviders      = optionsAccessor.Value.ModelValidatorProviders.ToArray();
     _valueProviderFactories       = optionsAccessor.Value.ValueProviderFactories.ToArray();
     _actionBindingContextAccessor = actionBindingContextAccessor;
     _maxModelValidationErrors     = optionsAccessor.Value.MaxModelValidationErrors;
     _logger    = loggerFactory.CreateLogger <ControllerActionInvoker>();
     _telemetry = telemetry;
 }
Пример #10
0
 // Subscription implementation
 /// <summary>
 /// Add a subscriber, Dispose the returned value to unsubscribe.  Every
 /// subscribers will have their IsEnabled and WriteData methods called
 /// whenever a producer is needs to cause a notification.  
 /// </summary>
 public IDisposable Subscribe(TelemetrySource subscriber)
 {
     Subscription newSubscription = new Subscription() { Subscriber = subscriber, Owner = this, Next = m_subscriptions };
     while (Interlocked.CompareExchange(ref m_subscriptions, newSubscription, newSubscription.Next) != newSubscription.Next)
         newSubscription.Next = m_subscriptions;
     return newSubscription;
 }