static WebAppConfig() { string appClassName = ConfigurationManager.AppSettings["WebAppClassName"]; _version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); _templateCacheDuration = Convert.ToInt32(ConfigurationManager.AppSettings["TemplateCacheDuration"]); _templateFileEncoding = string.IsNullOrEmpty(ConfigurationManager.AppSettings["TemplateFileEncoding"]) ? Encoding.Default : Encoding.GetEncoding(ConfigurationManager.AppSettings["TemplateFileEncoding"]); bool.TryParse(ConfigurationManager.AppSettings["EnabledHttpCompress"], out _enabledHttpCompress); string enabledPermission = ConfigurationManager.AppSettings["EnabledPermission"]; string defaultLanguageCode = ConfigurationManager.AppSettings["DefaultLanguageCode"]; if (defaultLanguageCode != null && defaultLanguageCode.Length >= 2) { _defaultLanguageCode = defaultLanguageCode; } _extension = ConfigurationManager.AppSettings["Extension"] ?? string.Empty; _appKey = ConfigurationManager.AppSettings["AppKey"]; _appSecret = ConfigurationManager.AppSettings["AppSecret"]; _oAuthUri = ConfigurationManager.AppSettings["OAuthUri"]; //if (string.IsNullOrEmpty(_appKey)) // throw new CException("AppKey not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_appSecret)) // throw new CException("AppSecret not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_oAuthUri)) // throw new CException("OAuthUri not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_publicKey)) // throw new CException("PublicKey not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_privateKey)) // throw new CException("PrivateKey not found, please check the Web.config's configuration/appSettings."); if (!string.IsNullOrEmpty(enabledPermission)) { bool.TryParse(enabledPermission, out _enabledPermission); } if (string.IsNullOrEmpty(appClassName)) { throw new CException("WebAppClassName not found, please check the Web.config's configuration/appSettings."); } Type appType = Type.GetType(appClassName, false); if (appType == null) { throw new CException("Can not load the type of WebAppClassName '" + appClassName + "'"); } MethodInfo initMethod = appType.GetMethod("Init", new Type[0]); if (initMethod == null || !initMethod.IsStatic) { throw new CException("Can not found the static Init method of " + appType.FullName); } RegisterAssembly(appType.Assembly); initMethod.Invoke(null, null); if (_sessionType == null) { throw new CException("WebAppConfig.SessionType is null."); } if (_securityType == null) { throw new CException("WebAppConfig.SecurityType is null."); } LoadControllerClasses(); if (_timeProvider == null) { _timeProvider = new RealTimeProvider(); } if (_deserializeProvider == null) { _deserializeProvider = new JSONDeserializer(); } if (_serializeProvider == null) { _serializeProvider = new JSONSerializer(); } if (_securityProvider == null) { _securityProvider = MiniSecurity.CreateInstance(); } if (_stringFilterProvider == null) { _stringFilterProvider = new MFilter(); } }
static WebAppConfig() { string appClassName = ConfigurationManager.AppSettings["WebAppClassName"]; _version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); _templateCacheDuration = Convert.ToInt32(ConfigurationManager.AppSettings["TemplateCacheDuration"]); _templateFileEncoding = string.IsNullOrEmpty(ConfigurationManager.AppSettings["TemplateFileEncoding"]) ? Encoding.Default : Encoding.GetEncoding(ConfigurationManager.AppSettings["TemplateFileEncoding"]); bool.TryParse(ConfigurationManager.AppSettings["EnabledHttpCompress"], out _enabledHttpCompress); string enabledPermission = ConfigurationManager.AppSettings["EnabledPermission"]; string defaultLanguageCode = ConfigurationManager.AppSettings["DefaultLanguageCode"]; if (defaultLanguageCode != null && defaultLanguageCode.Length >= 2) { _defaultLanguageCode = defaultLanguageCode; } _extension = ConfigurationManager.AppSettings["Extension"] ?? string.Empty; _appKey = ConfigurationManager.AppSettings["AppKey"]; _appSecret = ConfigurationManager.AppSettings["AppSecret"]; _oAuthUri = ConfigurationManager.AppSettings["OAuthUri"]; //if (string.IsNullOrEmpty(_appKey)) // throw new CException("AppKey not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_appSecret)) // throw new CException("AppSecret not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_oAuthUri)) // throw new CException("OAuthUri not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_publicKey)) // throw new CException("PublicKey not found, please check the Web.config's configuration/appSettings."); //if (string.IsNullOrEmpty(_privateKey)) // throw new CException("PrivateKey not found, please check the Web.config's configuration/appSettings."); if (!string.IsNullOrEmpty(enabledPermission)) bool.TryParse(enabledPermission, out _enabledPermission); if (string.IsNullOrEmpty(appClassName)) throw new CException("WebAppClassName not found, please check the Web.config's configuration/appSettings."); Type appType = Type.GetType(appClassName, false); if (appType == null) throw new CException("Can not load the type of WebAppClassName '" + appClassName + "'"); MethodInfo initMethod = appType.GetMethod("Init", new Type[0]); if (initMethod == null || !initMethod.IsStatic) throw new CException("Can not found the static Init method of " + appType.FullName); RegisterAssembly(appType.Assembly); initMethod.Invoke(null, null); if (_sessionType == null) throw new CException("WebAppConfig.SessionType is null."); if (_securityType == null) throw new CException("WebAppConfig.SecurityType is null."); LoadControllerClasses(); if (_timeProvider == null) { _timeProvider = new RealTimeProvider(); } if (_deserializeProvider == null) { _deserializeProvider = new JSONDeserializer(); } if (_serializeProvider == null) { _serializeProvider = new JSONSerializer(); } if (_securityProvider == null) { _securityProvider = MiniSecurity.CreateInstance(); } if (_stringFilterProvider == null) { _stringFilterProvider = new MFilter(); } }