/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="configurationSection">The section.</param> protected override void MemberwiseInitialize(ConfSection configurationSection) { sectionName = GetSettingsValue(SectionNameAttributeName); if (string.IsNullOrEmpty(this.sectionName)) { throw new InvalidOperationException("Missing parameter \"" + SectionNameAttributeName + "\"."); } var values = ConfigurationManager.GetSection(this.sectionName) as NameValueCollection; if (values == null) { throw new SectionNotFoundException("Section \"" + this.sectionName + "\" is not found."); } SettingsCollection v = new SettingsCollection(); foreach (string key in values.AllKeys) { v.Add(key, values.Get(key)); } Values = v; }
/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="configurationSection">The configuration section.</param> protected override void MemberwiseInitialize(ConfSection configurationSection) { var registryProvider = new RegistrySettingsProvider(); registryProvider.Initialize(configurationSection); var url = registryProvider.Values[UrlAttributeName]; var user = registryProvider.Values[UserAttributeName]; var password = registryProvider.Values[PasswordAttributeName]; var section = new ConfSection { Values = new NameValueCollection() }; section.Values.Add(UrlAttributeName, url); section.Values.Add(UserAttributeName, user); section.Values.Add(PasswordAttributeName, password); var providerWebService = new WebServiceProvider(); providerWebService.Initialize(section); // Get settings Values = providerWebService.Values; }
/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="configurationSection">The section.</param> protected override void MemberwiseInitialize(ConfSection configurationSection) { if (string.IsNullOrEmpty(this.ConfigRootNode)) { this.ConfigRootNode = GetSettingsValue(PathAttributeName); } Values = this.LoadSettings(); }
/// <summary> /// Method is design to perform any startup initialization tasks. /// </summary> /// <param name="configurationSection">The configuration section.</param> protected override void MemberwiseInitialize(ConfSection configurationSection) { this.filePath = GetSettingsValue(FilePathAttributeName); if (!File.Exists(this.filePath)) { throw new InvalidOperationException("File \"" + this.filePath + "\" does not exist."); } XmlDocument configDoc = new XmlDocument(); configDoc.Load(this.filePath); // TODO: validate against XSD schema Values = this.ReadSettings(configDoc.SelectSingleNode("/configuration")); }
/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="configurationSection">The configuration section.</param> protected override void MemberwiseInitialize(ConfSection configurationSection) { var url = GetSettingsValue(UrlAttributeName); var user = GetSettingsValue(UserAttributeName); var password = GetSettingsValue(PasswordAttributeName); var providerWebService = new Provider(); var cred = new NetworkCredential(user, password); providerWebService.PreAuthenticate = true; providerWebService.Credentials = cred; providerWebService.Url = url; // Try to get settings. PingConfigWebServices(providerWebService); // Get settings Values = GetSettings(providerWebService); }
/// <summary> /// Creates a configuration section handler. /// </summary> /// <param name="parent">Parent object.</param> /// <param name="configContext">Configuration context object.</param> /// <param name="section">Configuration section.</param> /// <returns> /// The created <see cref="ConfigurationSection"/> object. /// </returns> public object Create(object parent, object configContext, XmlNode section) { if (section == null) { throw new ArgumentNullException("section"); } var configuration = new ConfSection(); var reader = new XmlConfigProvider(); NameValueCollection settings = reader.ReadSettings(section); configuration.Values = settings; XmlNode initAttribute = section.Attributes.GetNamedItem("init"); configuration.ShouldReadOnStartup = true; if (initAttribute != null) { string initMode = initAttribute.InnerText; switch (initMode) { case "auto": configuration.ShouldReadOnStartup = true; break; case "ondemand": configuration.ShouldReadOnStartup = false; break; default: throw new InvalidOperationException("Unknown initialization mode \"" + initMode + "\""); } } return(configuration); }
/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="section">The section.</param> protected override void MemberwiseInitialize(ConfSection section) { this.server = GetSettingsValue(ServerAttributeName); this.database = GetSettingsValue(DatabaseAttributeName); this.user = GetSettingsValue(UserAttrbiuteName); this.password = GetSettingsValue(PasswordAttributeName); if (ContainsSettingsValue(SpAttrbiuteName)) { this.procedureName = GetSettingsValue(SpAttrbiuteName); } if (ContainsSettingsValue(PasswordSecurityKeyAttributeName)) { // Decrypt password string encryptKey = GetSettingsValue(PasswordSecurityKeyAttributeName); this.password = CryptoUtils.Encrypt(this.password, encryptKey); } ////TODO: rewrite this to use standart Sql connection construction mechnaism found in DBConnectionManager string sqlConnectionString = String.Format( CultureInfo.InvariantCulture, "Data Source=\"{0}\";Initial Catalog=\"{3}\";User Id=\"{1}\";Password=\"{2}\";", this.server, this.user, this.password, this.database); // Add connection string to settings collection. // Now there are no need to specify sql connection properties // in data base. Just read this this key from settings. Values.Add("SqlConnectionString", sqlConnectionString); using (SqlConnection connection = new SqlConnection(sqlConnectionString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = this.procedureName; cmd.Connection = connection; connection.Open(); using (SqlDataReader reader = cmd.ExecuteReader()) { if (reader == null) { throw new InvalidOperationException("Error while reading settings data. SqlReader is null."); } while (reader.Read()) { Values.Add( reader.GetString(reader.GetOrdinal("key")), reader.GetString(reader.GetOrdinal("value"))); } } } } }
/// <summary> /// Method is design to perform any startup initialization tasks. /// </summary> /// <param name="configurationSection">The configuration section.</param> public void Initialize(ConfSection configurationSection) { this.section = configurationSection; this.MemberwiseInitialize(this.section); }
/// <summary> /// Override this in child class to implement custom initialization. /// </summary> /// <param name="configurationSection">The section.</param> protected virtual void MemberwiseInitialize(ConfSection configurationSection) { }
/// <summary> /// Initializes the specified section. /// </summary> /// <param name="configurationSection">The section.</param> public void Initialize(ConfSection configurationSection) { this.values = new SettingsCollection(); }