コード例 #1
0
        public Startup(IHostingEnvironment env)
        {
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
                          .AddEnvironmentVariables();

            if (env.IsDevelopment())
            {
                // This will push telemetry data through Application Insights pipeline faster, allowing you to view results immediately.
                builder.AddApplicationInsightsSettings(developerMode: true);
            }
            Configuration = builder.Build();

            foreach (var c in Configuration.GetSection("ErrorPages").GetChildren())
            {
                var key = Convert.ToInt32(c.Key);
                if (!ErrorPages.Keys.Contains(key))
                {
                    ErrorPages.Add(key, c.Value);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Initiates the server configuration and applications configuration.
        /// </summary>
        private void Init()
        {
            Console.WriteLine("+-+-+ INITIATING CONFIGURATION MANAGER +-+-+");
            Console.WriteLine("-- Loading configuration from JSON configuration file...");
            // Getting general JSON string from file
            JObject configJson = JsonConvert.DeserializeObject(File.ReadAllText(_path)) as JObject;

            // Assigning port from JSON
            Port = int.Parse(configJson["port"].ToString());

            // Populating defaultDocument List
            foreach (var document in configJson["defaultDocument"] as JArray)
            {
                DefaultDocument.Add(document.ToString());
            }

            // Populating errorPages Dictionary
            JProperty property;

            foreach (var token in configJson["errorPages"] as JArray)
            {
                property = token.First.Value <JProperty>();
                ErrorPages.Add(int.Parse(property.Name), property.Value.ToString());
            }

            // Populatin sites Struct List
            Site site = new Site();

            foreach (var token in configJson["sites"] as JArray)
            {
                site.DefaultDocument   = new List <string>();
                site.ErrorPages        = new Dictionary <int, string>();
                site.Name              = token["name"].ToString();
                site.PhysicalPath      = token["physicalPath"].ToString();
                site.VirtualPath       = token["virtualPath"].ToString();
                site.DirectoryBrowsing = bool.Parse(token["directoryBrowsing"].ToString());

                foreach (var document in token["defaultDocument"] as JArray)
                {
                    site.DefaultDocument.Add(document.ToString());
                }

                foreach (var pages in token["errorPages"] as JArray)
                {
                    property = pages.First.Value <JProperty>();
                    site.ErrorPages.Add(int.Parse(property.Name), property.Value.ToString());
                }

                Sites.Add(site);
            }

            //Printing Config
            Console.WriteLine("  + Port: {0}", Port);
            foreach (var document in DefaultDocument)
            {
                Console.WriteLine("  + Default Document: {0}", document);
            }
            foreach (var page in ErrorPages)
            {
                Console.WriteLine("  + Error Page: {0}", page);
            }
            int i = 0;

            foreach (var s in Sites)
            {
                Console.WriteLine("  + Site [{0}] | Name: {1}", i, s.Name);
                Console.WriteLine("  + Site [{0}] | Physical Path: {1}", i, s.PhysicalPath);
                Console.WriteLine("  + Site [{0}] | Virtual Path: {1}", i, s.VirtualPath);
                Console.WriteLine("  + Site [{0}] | Directory Browsing: {1}", i, s.DirectoryBrowsing);
                foreach (var document in s.DefaultDocument)
                {
                    Console.WriteLine("  + SiteDocument: {0}", document);
                }
                foreach (var pages in s.ErrorPages)
                {
                    Console.WriteLine("  + SiteErrorPage: {0}", pages);
                }
                i++;
            }
            Console.WriteLine("-- Configuration Loading COMPLETE!");
            Console.WriteLine("-");
        }