コード例 #1
0
        public void LoadConfigFile(string configFileName)
        {
            WebServerConfig config       = new WebServerConfig();
            string          appDirectory = ConfigurationManager.AppSettings.Get("AppDirectory");

            if (appDirectory == null)
            {
                appDirectory = Environment.CurrentDirectory;
            }
            else
            {
                appDirectory = appDirectory?.Replace("[ProgramDataDirectory]", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            }
            Directory.CreateDirectory(appDirectory);
            string configFilePath = Path.Combine(appDirectory, configFileName);

            if (File.Exists(configFilePath))
            {
                string configJSONStr = File.ReadAllText(configFilePath);
                config = JsonConvert.DeserializeObject <WebServerConfig>(configJSONStr, new JsonSerializerSettings()
                {
                    TypeNameHandling = TypeNameHandling.Auto
                });
            }
            else
            {
                string jsonString = JsonConvert.SerializeObject(config, Formatting.Indented);
                File.WriteAllText(configFilePath, jsonString);
            }
            //config.LogDirectory = config.LogDirectory.Replace("[ProgramDataDirectory]", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            //config.WWWDirectory = config.WWWDirectory.Replace("[ProgramDataDirectory]", Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData));
            this.EnableHTTP  = config.EnableHTTP;
            this.HTTPPort    = config.HTTPPort;
            this.EnableHTTPS = config.EnableHTTPS;
            this.HTTPSPort   = config.HTTPSPort;
            this.SSLCertificateSubjectName = config.SSLCertificateSubjectName;
            this.SSLCertificateStoreName   = config.SSLCertificateStoreName;
            this.LogDirectory                         = config.LogDirectory;
            this.MaximumCacheSizeInMB                 = config.MaximumCacheSizeInMB;
            this.OnlyCacheItemsLessThenMB             = config.OnlyCacheItemsLessThenMB;
            this.WWWDirectory                         = config.WWWDirectory;
            this.AllowLocalhostConnectionsOnlyForHttp = config.AllowLocalhostConnectionsOnlyForHttp;
            this.EnableCache = config.EnableCache;
            this.UtilityConfig.AllowLocalhostConnectionsOnlyForHttp = config.UtilityConfig.AllowLocalhostConnectionsOnlyForHttp;
            this.UtilityConfig.ConfigUsername            = config.UtilityConfig.ConfigUsername;
            this.UtilityConfig.ConfigPasswordHash        = config.UtilityConfig.ConfigPasswordHash;
            this.UtilityConfig.EnableHTTPS               = config.UtilityConfig.EnableHTTPS;
            this.UtilityConfig.HTTPPort                  = config.UtilityConfig.HTTPPort;
            this.UtilityConfig.HTTPSPort                 = config.UtilityConfig.HTTPSPort;
            this.UtilityConfig.SSLCertificateStoreName   = config.UtilityConfig.SSLCertificateStoreName;
            this.UtilityConfig.SSLCertificateSubjectName = config.UtilityConfig.SSLCertificateSubjectName;
            this.Rules.Clear();
            foreach (var r in config.Rules)
            {
                this.Rules.Add(r);
            }
        }
コード例 #2
0
 public void Update(WebServerConfig webServerConfig, ObservableCollection <string> sANs)
 {
     this.ConfigUsername                  = webServerConfig.UtilityConfig.ConfigUsername;
     this.ConfigPasswordHash              = webServerConfig.UtilityConfig.ConfigPasswordHash;
     this.ConfigHTTPPort                  = webServerConfig.UtilityConfig.HTTPPort;
     this.ConfigLocalhostOnly             = webServerConfig.UtilityConfig.AllowLocalhostConnectionsOnlyForHttp;
     this.ConfigEnableHTTPS               = webServerConfig.UtilityConfig.EnableHTTPS;
     this.ConfigHTTPSPort                 = webServerConfig.UtilityConfig.HTTPSPort;
     this.ConfigSSLCertificateSubjectName = webServerConfig.UtilityConfig.SSLCertificateSubjectName;
     this.ConfigSSLCertificateStoreName   = webServerConfig.UtilityConfig.SSLCertificateStoreName;
     this.ConfigSubjectAlternativeNames.Clear();
     foreach (var sAN in sANs)
     {
         this.ConfigSubjectAlternativeNames.Add(sAN);
     }
 }