Пример #1
0
        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
            };
        }
Пример #2
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));
            };
        }