コード例 #1
0
 public FakeDiagnostics(
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable <IResponseProcessor> responseProcessors,
     IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService,
     IRequestTraceFactory requestTraceFactory,
     IEnumerable <IRouteMetadataProvider> routeMetadataProviders,
     ITextResource textResource,
     INancyEnvironment environment,
     ITypeCatalog typeCatalog)
 {
     this.diagnosticProviders     = (new IDiagnosticsProvider[] { new FakeDiagnosticsProvider() }).ToArray();
     this.rootPathProvider        = rootPathProvider;
     this.requestTracing          = requestTracing;
     this.configuration           = configuration;
     this.modelBinderLocator      = modelBinderLocator;
     this.responseProcessors      = responseProcessors;
     this.routeSegmentConstraints = routeSegmentConstraints;
     this.cultureService          = cultureService;
     this.requestTraceFactory     = requestTraceFactory;
     this.routeMetadataProviders  = routeMetadataProviders;
     this.textResource            = textResource;
     this.environment             = environment;
     this.typeCatalog             = typeCatalog;
 }
コード例 #2
0
ファイル: InfoModel.cs プロジェクト: jchannon/Glimpse.Nancy
        public InfoModel(IRootPathProvider rootPathProvider, NancyInternalConfiguration configuration)
        {
            this.rootPathProvider = rootPathProvider;

            Configuration = new Dictionary <string, IEnumerable <string> >();
            foreach (var propertyInfo in configuration.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                var value = propertyInfo.GetValue(configuration, null);

                Configuration[propertyInfo.Name] = (!typeof(IEnumerable).IsAssignableFrom(value.GetType())) ?
                                                   new[] { value.ToString() } :
                ((IEnumerable <object>)value).Select(x => x.ToString());
            }

            var properties = SettingTypes
                             .SelectMany(t => t.GetProperties(BindingFlags.Static | BindingFlags.Public))
                             .Where(x => x.PropertyType == typeof(bool));

            Settings = from property in properties
                       orderby property.Name
                       let value = (bool)property.GetValue(null, null)
                                   select new SettingsModel
            {
                Name  = Regex.Replace(property.Name, "[A-Z]", " $0"),
                Value = value
            };
        }
コード例 #3
0
        public static NancyInternalConfiguration WithOpenApi(this NancyBootstrapperBase <TinyIoCContainer> bootstrapper, NancyConventions conventions, TinyIoCContainer container)
        {
            conventions.WithOpenApi();
            container.WithOpenApi();

            return(NancyInternalConfiguration.WithOverrides(nic => nic.ViewLocationProvider = typeof(ResourceViewLocationProvider)));
        }
コード例 #4
0
 /// <summary>
 /// Creates a new instance of the <see cref="DefaultDiagnostics"/> class.
 /// </summary>
 /// <param name="diagnosticProviders"></param>
 /// <param name="rootPathProvider"></param>
 /// <param name="requestTracing"></param>
 /// <param name="configuration"></param>
 /// <param name="modelBinderLocator"></param>
 /// <param name="responseProcessors"></param>
 /// <param name="routeSegmentConstraints"></param>
 /// <param name="cultureService"></param>
 /// <param name="requestTraceFactory"></param>
 /// <param name="routeMetadataProviders"></param>
 /// <param name="textResource"></param>
 public DefaultDiagnostics(
     IEnumerable <IDiagnosticsProvider> diagnosticProviders,
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable <IResponseProcessor> responseProcessors,
     IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService,
     IRequestTraceFactory requestTraceFactory,
     IEnumerable <IRouteMetadataProvider> routeMetadataProviders,
     ITextResource textResource,
     INancyEnvironment environment)
 {
     this.diagnosticProviders     = diagnosticProviders;
     this.rootPathProvider        = rootPathProvider;
     this.requestTracing          = requestTracing;
     this.configuration           = configuration;
     this.modelBinderLocator      = modelBinderLocator;
     this.responseProcessors      = responseProcessors;
     this.routeSegmentConstraints = routeSegmentConstraints;
     this.cultureService          = cultureService;
     this.requestTraceFactory     = requestTraceFactory;
     this.routeMetadataProviders  = routeMetadataProviders;
     this.textResource            = textResource;
     this.environment             = environment;
 }
コード例 #5
0
        public InfoModule(IRootPathProvider rootPathProvider, NancyInternalConfiguration configuration)
            : base("/info")
        {
            Get["/"] = _ => View["Info"];

            Get["/data"] = _ =>
            {
                dynamic data = new ExpandoObject();

                data.Nancy                       = new ExpandoObject();
                data.Nancy.Version               = string.Format("v{0}", this.GetType().Assembly.GetName().Version.ToString());
                data.Nancy.CachesDisabled        = StaticConfiguration.DisableCaches;
                data.Nancy.TracesDisabled        = StaticConfiguration.DisableErrorTraces;
                data.Nancy.CaseSensitivity       = StaticConfiguration.CaseSensitive ? "Sensitive" : "Insensitive";
                data.Nancy.RootPath              = rootPathProvider.GetRootPath();
                data.Nancy.Hosting               = this.GetHosting();
                data.Nancy.BootstrapperContainer = this.GetBootstrapperContainer();
                data.Nancy.LocatedBootstrapper   = NancyBootstrapperLocator.Bootstrapper.GetType().ToString();
                data.Nancy.LoadedViewEngines     = GetViewEngines();

                data.Configuration = new Dictionary <string, object>();
                foreach (var propertyInfo in configuration.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    var value =
                        propertyInfo.GetValue(configuration, null);

                    data.Configuration[propertyInfo.Name] = (!typeof(IEnumerable).IsAssignableFrom(value.GetType())) ?
                                                            new[] { value.ToString() } :
                    ((IEnumerable <object>)value).Select(x => x.ToString());
                }

                return(Response.AsJson((object)data));
            };
        }
コード例 #6
0
ファイル: DiagnosticsHook.cs プロジェクト: jvanzella/Nancy
        public static void Enable(DiagnosticsConfiguration diagnosticsConfiguration, IPipelines pipelines, IEnumerable<IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IEnumerable<ISerializer> serializers, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable<IResponseProcessor> responseProcessors, ICultureService cultureService)
        {
            var keyGenerator = new DefaultModuleKeyGenerator();
            var diagnosticsModuleCatalog = new DiagnosticsModuleCatalog(keyGenerator, providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration);

            var diagnosticsRouteCache = new RouteCache(diagnosticsModuleCatalog, keyGenerator, new DefaultNancyContextFactory(cultureService), new DefaultRouteSegmentExtractor(), new DefaultRouteDescriptionProvider(), cultureService);

            var diagnosticsRouteResolver = new DefaultRouteResolver(
                diagnosticsModuleCatalog,
                new DefaultRoutePatternMatcher(),
                new DiagnosticsModuleBuilder(rootPathProvider, serializers, modelBinderLocator),
                diagnosticsRouteCache,
                responseProcessors);

            var serializer = new DefaultObjectSerializer();

            pipelines.BeforeRequest.AddItemToStartOfPipeline(
                new PipelineItem<Func<NancyContext, Response>>(
                    PipelineKey,
                    ctx =>
                    {
                        if (!ctx.ControlPanelEnabled)
                        {
                            return null;
                        }

                        if (!ctx.Request.Path.StartsWith(diagnosticsConfiguration.Path, StringComparison.OrdinalIgnoreCase))
                        {
                            return null;
                        }

                        ctx.Items[ItemsKey] = true;

                        var resourcePrefix =
                            string.Concat(diagnosticsConfiguration.Path, "/Resources/");

                        if (ctx.Request.Path.StartsWith(resourcePrefix, StringComparison.OrdinalIgnoreCase))
                        {
                            var resourceNamespace = "Nancy.Diagnostics.Resources";

                            var path = Path.GetDirectoryName(ctx.Request.Url.Path.Replace(resourcePrefix, string.Empty)) ?? string.Empty;
                            if (!string.IsNullOrEmpty(path))
                            {
                                resourceNamespace += string.Format(".{0}", path.Replace('\\', '.'));
                            }

                            return new EmbeddedFileResponse(
                                typeof(DiagnosticsHook).Assembly,
                                resourceNamespace,
                                Path.GetFileName(ctx.Request.Url.Path));
                        }

                        RewriteDiagnosticsUrl(diagnosticsConfiguration, ctx);

                        return diagnosticsConfiguration.Valid
                                   ? ExecuteDiagnostics(ctx, diagnosticsRouteResolver, diagnosticsConfiguration, serializer)
                                   : GetDiagnosticsHelpView(ctx);
                    }));
        }
コード例 #7
0
        public void Should_not_be_valid_if_any_types_null()
        {
            var config = NancyInternalConfiguration.WithOverrides((c) => c.ModelBinderLocator = null);

            var result = config.IsValid;

            result.ShouldBeFalse();
        }
コード例 #8
0
 protected BootstrapperBaseFixtureBase()
 {
     this.configuration = NancyInternalConfiguration.WithOverrides(
         builder =>
     {
         builder.NancyEngine = typeof(FakeEngine);
     });
 }
コード例 #9
0
        public void Should_allow_overrides()
        {
            var fakeModelBinderLocator = A.Fake <IModelBinderLocator>();
            var config = NancyInternalConfiguration.WithOverrides((c) => c.ModelBinderLocator = fakeModelBinderLocator.GetType());

            var result = config.GetTypeRegistations();

            result.Where(tr => tr.ImplementationType == fakeModelBinderLocator.GetType()).Any()
            .ShouldBeTrue();
        }
コード例 #10
0
ファイル: DiagnosticsStartup.cs プロジェクト: skinny/Nancy
 public DiagnosticsStartup(DiagnosticsConfiguration diagnosticsConfiguration, IEnumerable <IDiagnosticsProvider> diagnosticProviders, IRootPathProvider rootPathProvider, IEnumerable <ISerializer> serializers, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator)
 {
     this.diagnosticsConfiguration = diagnosticsConfiguration;
     this.diagnosticProviders      = diagnosticProviders;
     this.rootPathProvider         = rootPathProvider;
     this.serializers        = serializers;
     this.requestTracing     = requestTracing;
     this.configuration      = configuration;
     this.modelBinderLocator = modelBinderLocator;
 }
コード例 #11
0
ファイル: DefaultDiagnostics.cs プロジェクト: williware/Nancy
 public DefaultDiagnostics(DiagnosticsConfiguration diagnosticsConfiguration, IEnumerable <IDiagnosticsProvider> diagnosticProviders, IRootPathProvider rootPathProvider, IEnumerable <ISerializer> serializers, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable <IResponseProcessor> responseProcessors)
 {
     this.diagnosticsConfiguration = diagnosticsConfiguration;
     this.diagnosticProviders      = diagnosticProviders;
     this.rootPathProvider         = rootPathProvider;
     this.serializers        = serializers;
     this.requestTracing     = requestTracing;
     this.configuration      = configuration;
     this.modelBinderLocator = modelBinderLocator;
     this.responseProcessors = responseProcessors;
 }
コード例 #12
0
        public void Should_not_be_valid_if_any_types_null()
        {
            // Given
            var config = NancyInternalConfiguration.WithOverrides((c) => c.ModelBinderLocator = null);

            // When
            var result = config.Invoke(this.typeCatalog).IsValid;

            // Then
            result.ShouldBeFalse();
        }
コード例 #13
0
 public FakeDiagnostics(DiagnosticsConfiguration diagnosticsConfiguration, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable <IResponseProcessor> responseProcessors, ICultureService cultureService)
 {
     this.diagnosticsConfiguration = diagnosticsConfiguration;
     this.diagnosticProviders      = (new IDiagnosticsProvider[] { new FakeDiagnosticsProvider() }).ToArray();
     this.rootPathProvider         = rootPathProvider;
     this.requestTracing           = requestTracing;
     this.configuration            = configuration;
     this.modelBinderLocator       = modelBinderLocator;
     this.responseProcessors       = responseProcessors;
     this.cultureService           = cultureService;
 }
コード例 #14
0
        public void Should_allow_overrides()
        {
            // Given
            var fakeModelBinderLocator = A.Fake <IModelBinderLocator>();
            var config = NancyInternalConfiguration.WithOverrides((c) => c.ModelBinderLocator = fakeModelBinderLocator.GetType());

            // When
            var result = config.Invoke(this.typeCatalog).GetTypeRegistrations();

            // Then
            result.Where(tr => tr.ImplementationType == fakeModelBinderLocator.GetType()).Any().ShouldBeTrue();
        }
コード例 #15
0
        protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
        {
            base.ApplicationStartup(container, pipelines);

            pipelines.EnableBasicAuthentication(new BasicAuthenticationConfiguration(
                                                    container.Resolve <IUserValidator>(),
                                                    "Couchbase XDCR"));

            StaticConfiguration.EnableRequestTracing = true;

            NancyInternalConfiguration.WithOverrides(c =>
            {
                c.StatusCodeHandlers.Clear();
                c.StatusCodeHandlers.Add(typeof(StatusCodeHandler));
            }
                                                     );

            container.Register <IReplicationHandler>(new XmlReplicator());
        }
コード例 #16
0
ファイル: DefaultDiagnostics.cs プロジェクト: zippy1981/Nancy
 public DefaultDiagnostics(
     DiagnosticsConfiguration diagnosticsConfiguration,
     IEnumerable <IDiagnosticsProvider> diagnosticProviders,
     IRootPathProvider rootPathProvider,
     IRequestTracing requestTracing,
     NancyInternalConfiguration configuration,
     IModelBinderLocator modelBinderLocator,
     IEnumerable <IResponseProcessor> responseProcessors,
     IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
     ICultureService cultureService)
 {
     this.diagnosticsConfiguration = diagnosticsConfiguration;
     this.diagnosticProviders      = diagnosticProviders;
     this.rootPathProvider         = rootPathProvider;
     this.requestTracing           = requestTracing;
     this.configuration            = configuration;
     this.modelBinderLocator       = modelBinderLocator;
     this.responseProcessors       = responseProcessors;
     this.routeSegmentConstraints  = routeSegmentConstraints;
     this.cultureService           = cultureService;
 }
コード例 #17
0
        public void GetEngine_Defaults_Registered_In_Container()
        {
            // Given
            this.bootstrapper.GetEngine();
            var defaults = NancyInternalConfiguration.WithOverrides(x =>
            {
                x.ModuleKeyGenerator = typeof(WindsorModuleKeyGenerator);
            });

            // When
            foreach (var registration in defaults.GetTypeRegistations().Where(x => x.RegistrationType != typeof(INancyEngine)))
            {
                this.bootstrapper.Container.Resolve(registration.RegistrationType)
                .ShouldBeOfType(registration.ImplementationType);
            }
            // NancyEngine is being proxied by Castle to intercept the HandleRequest call

            // Then
            this.bootstrapper.Container.Resolve <INancyEngine>()
            .GetType().Name.ShouldEqual("INancyEngineProxy");
        }
コード例 #18
0
        private static TinyIoCContainer ConfigureContainer(IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration)
        {
            var diagContainer = new TinyIoCContainer();

            diagContainer.Register <IInteractiveDiagnostics, InteractiveDiagnostics>();
            diagContainer.Register <IRequestTracing>(requestTracing);
            diagContainer.Register <IRootPathProvider>(rootPathProvider);
            diagContainer.Register <NancyInternalConfiguration>(configuration);
            diagContainer.Register <IModelBinderLocator, DefaultModelBinderLocator>();
            diagContainer.Register <IBinder, DefaultBinder>();
            diagContainer.Register <IFieldNameConverter, DefaultFieldNameConverter>();
            diagContainer.Register <BindingDefaults, BindingDefaults>();
            diagContainer.Register <ISerializer>(new DefaultJsonSerializer {
                RetainCasing = false
            });

            foreach (var diagnosticsProvider in providers)
            {
                var key = string.Concat(
                    diagnosticsProvider.GetType().FullName,
                    "_",
                    diagnosticsProvider.DiagnosticObject.GetType().FullName);

                diagContainer.Register <IDiagnosticsProvider>(diagnosticsProvider, key);
            }

            foreach (var moduleType in AppDomainAssemblyTypeScanner.TypesOf <DiagnosticModule>().ToArray())
            {
                diagContainer.Register(typeof(INancyModule), moduleType, moduleType.FullName).AsMultiInstance();
            }

            return(diagContainer);
        }
コード例 #19
0
 public DiagnosticsModuleCatalog(IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, DiagnosticsConfiguration diagnosticsConfiguration)
 {
     this.container = ConfigureContainer(providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration);
 }
コード例 #20
0
 public static void OnConfigurationBuilder(NancyInternalConfiguration obj)
 {
     obj.ViewLocationProvider = typeof(ResourceViewLocationProvider);
 }
コード例 #21
0
 public FakeUnityNancyBootstrapper(NancyInternalConfiguration configuration)
     : this(configuration, null)
 {
 }
コード例 #22
0
 void OnConfigurationBuilder(NancyInternalConfiguration x)
 {
     x.ViewLocationProvider = typeof(ResourceViewLocationProvider);
 }
コード例 #23
0
 public FakeDefaultNancyBootstrapper()
     : this(NancyInternalConfiguration.WithOverrides(b => b.StatusCodeHandlers = new List <Type>(new[] { typeof(DefaultStatusCodeHandler) })))
 {
 }
 public FakeStructureMapNancyBootstrapper(NancyInternalConfiguration configuration)
 {
     this.configuration = configuration;
 }
コード例 #25
0
 static void OnConfigurationBuilder(NancyInternalConfiguration config)
 {
     config.ViewLocationProvider = typeof(ResourceViewLocationProvider);
 }
コード例 #26
0
 public FakeUnityNancyBootstrapper(NancyInternalConfiguration configuration, IUnityContainer container)
 {
     this.configuration = configuration;
     this.container = container;
 }
コード例 #27
0
 private void ConfigurationBuilder(NancyInternalConfiguration nancyInternalConfiguration)
 {
     nancyInternalConfiguration.ViewLocationProvider = typeof(ResourceViewLocationProvider);
 }
コード例 #28
0
 public FakeBootstrapper(NancyInternalConfiguration configuration)
 {
     this.configuration = configuration;
 }
コード例 #29
0
        public FakeDefaultNancyBootstrapper(NancyInternalConfiguration configuration)
        {
            this.configuration = configuration.WithIgnoredAssembly(asm => asm.FullName.StartsWith("TestAssembly"));

            this.RequestContainerInitialisations = new Dictionary <NancyContext, int>();
        }
コード例 #30
0
        public static void Enable(
            DiagnosticsConfiguration diagnosticsConfiguration,
            IPipelines pipelines,
            IEnumerable <IDiagnosticsProvider> providers,
            IRootPathProvider rootPathProvider,
            IRequestTracing requestTracing,
            NancyInternalConfiguration configuration,
            IModelBinderLocator modelBinderLocator,
            IEnumerable <IResponseProcessor> responseProcessors,
            IEnumerable <IRouteSegmentConstraint> routeSegmentConstraints,
            ICultureService cultureService,
            IRequestTraceFactory requestTraceFactory,
            IEnumerable <IRouteMetadataProvider> routeMetadataProviders,
            ITextResource textResource)
        {
            var diagnosticsModuleCatalog = new DiagnosticsModuleCatalog(providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration);

            var diagnosticsRouteCache = new RouteCache(
                diagnosticsModuleCatalog,
                new DefaultNancyContextFactory(cultureService, requestTraceFactory, textResource),
                new DefaultRouteSegmentExtractor(),
                new DefaultRouteDescriptionProvider(),
                cultureService,
                routeMetadataProviders);

            var diagnosticsRouteResolver = new DefaultRouteResolver(
                diagnosticsModuleCatalog,
                new DiagnosticsModuleBuilder(rootPathProvider, modelBinderLocator),
                diagnosticsRouteCache,
                new RouteResolverTrie(new TrieNodeFactory(routeSegmentConstraints)));

            var serializer = new DefaultObjectSerializer();

            pipelines.BeforeRequest.AddItemToStartOfPipeline(
                new PipelineItem <Func <NancyContext, Response> >(
                    PipelineKey,
                    ctx =>
            {
                if (!ctx.ControlPanelEnabled)
                {
                    return(null);
                }

                if (!ctx.Request.Path.StartsWith(diagnosticsConfiguration.Path, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                ctx.Items[ItemsKey] = true;

                var resourcePrefix =
                    string.Concat(diagnosticsConfiguration.Path, "/Resources/");

                if (ctx.Request.Path.StartsWith(resourcePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    var resourceNamespace = "Nancy.Diagnostics.Resources";

                    var path = Path.GetDirectoryName(ctx.Request.Url.Path.Replace(resourcePrefix, string.Empty)) ?? string.Empty;
                    if (!string.IsNullOrEmpty(path))
                    {
                        resourceNamespace += string.Format(".{0}", path.Replace(Path.DirectorySeparatorChar, '.'));
                    }

                    return(new EmbeddedFileResponse(
                               typeof(DiagnosticsHook).Assembly,
                               resourceNamespace,
                               Path.GetFileName(ctx.Request.Url.Path)));
                }

                RewriteDiagnosticsUrl(diagnosticsConfiguration, ctx);

                return(diagnosticsConfiguration.Valid
                                   ? ExecuteDiagnostics(ctx, diagnosticsRouteResolver, diagnosticsConfiguration, serializer)
                                   : GetDiagnosticsHelpView(ctx));
            }));
        }
コード例 #31
0
        public FakeDefaultNancyBootstrapper(NancyInternalConfiguration configuration)
        {
            this.configuration = configuration.WithIgnoredAssembly(asm => asm.FullName.StartsWith("TestAssembly"));

            this.RequestContainerInitialisations = new Dictionary<NancyContext, int>();
        }
コード例 #32
0
 public FakeDefaultNancyBootstrapper(NancyInternalConfiguration configuration)
 {
     this.configuration = configuration;
     this.RequestContainerInitialisations = new Dictionary <NancyContext, int>();
 }
コード例 #33
0
        public FakeDefaultNancyBootstrapper(NancyInternalConfiguration configuration)
        {
            this.configuration = configuration;

            this.RequestContainerInitialisations = new Dictionary<NancyContext, int>();
        }
 public FakeWindsorNancyBootstrapper(NancyInternalConfiguration configuration)
 {
     this.configuration = configuration;
 }
コード例 #35
0
 public DiagnosticsModuleCatalog(IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, INancyEnvironment diagnosticsEnvironment, ITypeCatalog typeCatalog)
 {
     this.container = ConfigureContainer(providers, rootPathProvider, requestTracing, configuration, diagnosticsEnvironment, typeCatalog);
 }
コード例 #36
0
ファイル: DiagnosticsHook.cs プロジェクト: qdkll/Nancy
        public static void Enable(DiagnosticsConfiguration diagnosticsConfiguration, IPipelines pipelines, IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IEnumerable <ISerializer> serializers, IRequestTracing requestTracing, NancyInternalConfiguration configuration, IModelBinderLocator modelBinderLocator, IEnumerable <IResponseProcessor> responseProcessors)
        {
            var keyGenerator             = new DefaultModuleKeyGenerator();
            var diagnosticsModuleCatalog = new DiagnosticsModuleCatalog(keyGenerator, providers, rootPathProvider, requestTracing, configuration, diagnosticsConfiguration);

            var diagnosticsRouteCache = new RouteCache(diagnosticsModuleCatalog, keyGenerator, new DefaultNancyContextFactory(), new DefaultRouteSegmentExtractor());

            var diagnosticsRouteResolver = new DefaultRouteResolver(
                diagnosticsModuleCatalog,
                new DefaultRoutePatternMatcher(),
                new DiagnosticsModuleBuilder(rootPathProvider, serializers, modelBinderLocator),
                diagnosticsRouteCache,
                responseProcessors);

            var serializer = new DefaultObjectSerializer();

            pipelines.BeforeRequest.AddItemToStartOfPipeline(
                new PipelineItem <Func <NancyContext, Response> >(
                    PipelineKey,
                    ctx =>
            {
                if (!ctx.ControlPanelEnabled)
                {
                    return(null);
                }

                if (!ctx.Request.Path.StartsWith(ControlPanelPrefix, StringComparison.OrdinalIgnoreCase))
                {
                    return(null);
                }

                if (ctx.Request.Path.StartsWith(ResourcePrefix, StringComparison.OrdinalIgnoreCase))
                {
                    var resourceNamespace = "Nancy.Diagnostics.Resources";

                    var path = Path.GetDirectoryName(ctx.Request.Url.Path.Replace(ResourcePrefix, string.Empty)) ?? string.Empty;
                    if (!string.IsNullOrEmpty(path))
                    {
                        resourceNamespace += string.Format(".{0}", path.Replace('\\', '.'));
                    }

                    return(new EmbeddedFileResponse(
                               typeof(DiagnosticsHook).Assembly,
                               resourceNamespace,
                               Path.GetFileName(ctx.Request.Url.Path)));
                }

                return(diagnosticsConfiguration.Valid
                                   ? ExecuteDiagnostics(ctx, diagnosticsRouteResolver, diagnosticsConfiguration, serializer)
                                   : GetDiagnosticsHelpView(ctx));
            }));
        }
コード例 #37
0
        private static TinyIoCContainer ConfigureContainer(IEnumerable <IDiagnosticsProvider> providers, IRootPathProvider rootPathProvider, IRequestTracing requestTracing, NancyInternalConfiguration configuration, INancyEnvironment diagnosticsEnvironment, ITypeCatalog typeCatalog)
        {
            var diagContainer = new TinyIoCContainer();

            diagContainer.Register <IInteractiveDiagnostics, InteractiveDiagnostics>();
            diagContainer.Register <IRequestTracing>(requestTracing);
            diagContainer.Register <IRootPathProvider>(rootPathProvider);
            diagContainer.Register <NancyInternalConfiguration>(configuration);
            diagContainer.Register <IModelBinderLocator, DefaultModelBinderLocator>();
            diagContainer.Register <IBinder, DefaultBinder>();
            diagContainer.Register <IFieldNameConverter, DefaultFieldNameConverter>();
            diagContainer.Register <BindingDefaults, BindingDefaults>();
            diagContainer.Register <INancyEnvironment>(diagnosticsEnvironment);
            diagContainer.Register <ISerializer>(new DefaultJsonSerializer(diagnosticsEnvironment));
            diagContainer.Register <ITypeCatalog>(typeCatalog);

            foreach (var diagnosticsProvider in providers)
            {
                var key = string.Concat(
                    diagnosticsProvider.GetType().FullName,
                    "_",
                    diagnosticsProvider.DiagnosticObject.GetType().FullName);

                diagContainer.Register <IDiagnosticsProvider>(diagnosticsProvider, key);
            }

            foreach (var moduleType in typeCatalog.GetTypesAssignableTo <DiagnosticModule>())
            {
                diagContainer.Register(typeof(INancyModule), moduleType, moduleType.FullName).AsMultiInstance();
            }

            return(diagContainer);
        }