Exemple #1
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            if (environment.GetRouteInformation().RoutedTo != null)
            {
                await _next(environment).ConfigureAwait(false);

                return;
            }

            var path   = environment.GetRequest().Path + "?" + environment.GetRequest().QueryString;
            var method = environment.GetRequest().Method;

            var routeEngine = environment.GetRouteEngine();

            var routeData = new RouteData {
                Environment = environment
            };
            var walker = routeEngine.Walker();
            var data   = walker.WalkRoute(path, method, routeData);

            var endpoint = environment.GetRouteForEndpoint(data.Response);

            await environment.PushDiagnosticsData(DiagnosticsCategories.RequestsFor(environment), DiagnosticsTypes.RequestExecution, environment.GetCurrentChain().RequestId, new Tuple <string, IDictionary <string, object> >("RequestRouted", new Dictionary <string, object>
            {
                { "RoutedTo", data.Response ?? "" },
                { "Url", environment.GetRequest().Uri },
                { "Found", data.Response != null }
            })).ConfigureAwait(false);

            environment.SetRouteDestination(data.Response, endpoint != null ? endpoint.InputTypes : new List <Type>(), (IDictionary <string, object>)data.Parameters);

            await _next(environment).ConfigureAwait(false);
        }
        public Task <IEndThings> Begin(IDictionary <string, object> environment, Type middleWareType)
        {
            var key       = DiagnosticsCategories.RequestsFor(environment);
            var requestId = environment.GetCurrentChain().RequestId;

            if (string.IsNullOrEmpty(requestId) || !environment.GetSettings <DiagnosticsSettings>().IsKeyAllowed(key))
            {
                return(Task.FromResult <IEndThings>(new FakeDisposable()));
            }

            var stopwatch = Stopwatch.StartNew();

            return(Task.FromResult <IEndThings>(new Disposable(middleWareType, key, stopwatch, environment, requestId)));
        }
Exemple #3
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            if (environment.GetRouteInformation().RoutedTo != null)
            {
                await _next(environment).ConfigureAwait(false);

                return;
            }

            var fileSystem = environment.Resolve <IFileSystem>();

            var fileReaders = (_options.GetFileReaders ?? (x => new List <IReadFiles> {
                new ReadFilesFromFileSystem(fileSystem, x, _options.DefaultFiles)
            }))(environment).ToList();

            if (!fileReaders.Any())
            {
                fileReaders.Add(new ReadFilesFromFileSystem(fileSystem, environment, _options.DefaultFiles));
            }

            var matchingReader = fileReaders.Select(x => x.TryRead(environment.GetRequest().Path)).FirstOrDefault(x => x.Exists);

            if (matchingReader != null)
            {
                await environment.PushDiagnosticsData(DiagnosticsCategories.RequestsFor(environment), DiagnosticsTypes.RequestExecution, environment.GetCurrentChain().RequestId,
                                                      new Tuple <string, IDictionary <string, object> >("RequestRouted", new Dictionary <string, object>
                {
                    { "RoutedTo", matchingReader.Name ?? "" },
                    { "Url", environment.GetRequest().Uri },
                    { "Found", true }
                })).ConfigureAwait(false);

                var output = new StaticFileOutput(matchingReader.Read, _options.GetCacheControl(matchingReader.Name));

                environment.SetRouteDestination(output, new List <Type>(), new Dictionary <string, object>());
                environment.SetOutput(output);
            }

            await _next(environment).ConfigureAwait(false);
        }
Exemple #4
0
 /// <summary>
 /// Uses default Area, EventId
 /// </summary>
 /// <param name="message"></param>
 /// <param name="category"></param>
 public void Debug(string message, DiagnosticsCategories category)
 {
     SPLogger.TraceToDeveloper(message, _eventId, TraceSeverity.None, AreaCategory(category));
 }
Exemple #5
0
 public string AreaCategory(string area, DiagnosticsCategories category)
 {
     return(string.Format("{0}/{1}", area, Enum.GetName(typeof(DiagnosticsCategories), category)));
 }
Exemple #6
0
 /// <summary>
 /// Uses default Area, EventId
 /// </summary>
 /// <param name="message"></param>
 /// <param name="exception"></param>
 /// <param name="category"></param>
 public void Error(string message, Exception exception, DiagnosticsCategories category)
 {
     SPLogger.TraceToDeveloper(exception, message, _eventId, TraceSeverity.Unexpected, AreaCategory(category));
 }
Exemple #7
0
 /// <summary>
 /// Uses default Area, EventId
 /// </summary>
 /// <param name="message"></param>
 /// <param name="exception"></param>
 /// <param name="category"></param>
 public void Warning(string message, Exception exception, DiagnosticsCategories category)
 {
     SPLogger.TraceToDeveloper(exception, message, _eventId, TraceSeverity.Monitorable, AreaCategory(category));
 }
Exemple #8
0
 /// <summary>
 /// Uses default Area, EventId
 /// </summary>
 /// <param name="message"></param>
 /// <param name="exception"></param>
 /// <param name="category"></param>
 public void Info(string message, Exception exception, DiagnosticsCategories category)
 {
     SPLogger.TraceToDeveloper(exception, message, _eventId, TraceSeverity.Verbose, AreaCategory(category));
 }