public OdpSdeStDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) : base(config.GetParameter(component, "Server", null), config.GetParameter(component, "User", null), GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate), config.GetParameterAsInt(component, "Connect_Timeout", null)) { }
/// <summary> /// This constructor reads all the appropriate values from our standard config file /// in the normal format. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public PostgreSqlDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) { _server = config.GetParameter(component, "Server"); _port = config.GetParameter(component, "Port", _port); _databaseName = config.GetParameter(component, "Database"); _user = config.GetParameter(component, "User", null); _password = GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate); _encoding = config.GetParameter(component, "Encoding", _encoding); _connectionStr = MakeConnectionString(_server, _port, _databaseName, _user, _password, _encoding); _cleanConnStr = MakeConnectionString(_server, _port, _databaseName, _user, null, _encoding); }
/// <summary> /// This method is provided for convenience. If decryptionDelegate is not null, /// will use it to decrypt whatever value is in the config parameter. /// </summary> /// <param name="config">Config file to get the parameter from.</param> /// <param name="component">Section within the config file.</param> /// <param name="paramName">Name of the paraneter within the section.</param> /// <param name="decryptionDelegate">Method to call to decrypt the parameter. May be null if using plain text.</param> /// <returns></returns> protected static string GetDecryptedConfigParameter(Config config, string component, string paramName, ConnectionInfoDecryptionDelegate decryptionDelegate) { string retVal = config.GetParameter(component, paramName, null); if ((decryptionDelegate != null) && (!String.IsNullOrEmpty(retVal))) { retVal = decryptionDelegate.Invoke(retVal); } return retVal; }
/// <summary> /// This is a factory method, that will load the appropriate type of connection /// descriptor using the given config. /// /// It first searches for config item(s) called "ConnectionConfigSection" and/or /// "ConnectionConfig". (ConnectionConfig should be an "app name" for a config, not a file name). /// If present, it will use those to load from another section in this or another /// config file. This allows more dynamic install-time configuration of DB connections. /// You may daisy-chain the configuration if you wish. /// /// Once in the connection configuration section, it will first search for the "DescriptorClass" /// config item, and use that class if specified. If not, defaults to an OleDbDescriptor /// (which means it should be backwards compatible for all our existing config files). /// </summary> /// <param name="cfg">Config to load the descriptor info from.</param> /// <param name="section">What section of that config has the DB connection info in it.</param> /// <param name="decryptionDelegate">Method to call to decrypt information, if the actual /// connection descriptor type supports decryption. May be null.</param> /// <returns>A fully populated ConnectionDescriptor.</returns> public static IConnectionDescriptor LoadFromConfig(Config cfg, string section, ConnectionInfoDecryptionDelegate decryptionDelegate) { if (!cfg.ComponentExists(section)) { throw new BadDaoConfigurationException("Config section " + section + " does not exist in " + cfg.Application); } IConnectionDescriptor retVal; // First see if we're redirected to another config and/or section. if (cfg.ParameterExists(section, "ConnectionConfig") || cfg.ParameterExists(section, "ConnectionConfigSection")) { string otherName = cfg.GetParameter(section, "ConnectionConfig", cfg.Application); string otherSection = cfg.GetParameter(section, "ConnectionConfigSection", section); if (_log.IsDebugEnabled) { _log.Debug("Loading " + section + " connection info from " + otherName + "[" + otherSection + "]"); } // Recurse with different config values. retVal = LoadFromConfig(Config.GetConfig(otherName), otherSection, decryptionDelegate); } else { // Not overridden, read from this config section. // For backwards compatibility, default to using an OleDb descriptor. string typeName = cfg.GetParameter(section, "DescriptorClass", "Azavea.Open.DAO.OleDb.OleDbDescriptor,Azavea.Open.DAO.OleDb"); Type[] paramTypes = new Type[] {typeof (Config), typeof (string), typeof(ConnectionInfoDecryptionDelegate)}; Type descType = Type.GetType(typeName); if (descType == null) { throw new BadDaoConfigurationException("DescriptorClass '" + typeName + "' was specified, but we were unable to get type info. Are you missing a DLL?"); } ConstructorInfo constr = descType.GetConstructor(paramTypes); if (constr == null) { throw new BadDaoConfigurationException("DescriptorClass '" + typeName + "' was specified, but we were unable to get constructor info."); } retVal = (IConnectionDescriptor)constr.Invoke(new object[] { cfg, section, decryptionDelegate }); } return retVal; }
/// <summary> /// Populates the descriptor's values from a config file. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public CsvDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) : this(CsvConnectionType.Unknown, config.GetParameterWithSubstitution(component, "Path", true), null, null, config.ParameterExists(component, "OutputQuoteLevel") ? (CsvQuoteLevel) Enum.Parse(typeof (CsvQuoteLevel),config.GetParameter(component, "OutputQuoteLevel")) : CsvQuoteLevel.QuoteStrings) { }
/// <summary> /// This constructor reads all the appropriate values from our standard config file /// in the normal format. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public FirebirdDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) { FbConnectionStringBuilder builder = new FbConnectionStringBuilder(); Server = config.GetParameter(component, "Server", null); if (StringHelper.IsNonBlank(Server)) { builder.DataSource = Server; } else { builder.ServerType = FbServerType.Embedded; // For the embedded server, we want to disable pooling so we don't wind up locking // the file indefinitely. builder.Pooling = false; _usePooling = false; } builder.Database = Database = config.GetParameterWithSubstitution(component, "Database", true); builder.UserID = User = config.GetParameter(component, "User", null); // First make it without a password. _cleanConnStr = builder.ToString(); // Now with the password for the real one. Password = GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate); builder.Password = Password; _connectionStr = builder.ToString(); }
/// <summary> /// This constructor reads all the appropriate values from our standard config file /// in the normal format. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public SQLiteDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) { SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder(); builder.Pooling = false; _usePooling = false; builder.DataSource = _databasePath = config.GetParameterWithSubstitution(component, "Database", true); // We don't currently support passwords, so the clean conn str is the same // as the real one. _cleanConnStr = builder.ToString(); _connectionStr = builder.ToString(); }
/// <summary> /// This constructor reads all the appropriate values from a config file. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public OleDbDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) : this(GetTypeFromConfig(config, component), config.GetParameter(component, "Provider", null), config.GetParameter(component, "Server", null), config.GetParameterWithSubstitution(component, "Database", true, null), config.GetParameter(component, "User", null), GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate), config.GetParameterAsInt(component, "Connect_Timeout", null)) { }
/// <summary> /// This constructor reads all the appropriate values from a config file. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public SQLServerDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) : this(config.GetParameter(component, "Server", null), config.GetParameter(component, "Database", null), config.GetParameter(component, "User", null), GetDecryptedConfigParameter(config, component, "Password", decryptionDelegate)) { }
/// <summary> /// Populates the descriptor's values from a config file. /// </summary> /// <param name="config">Config to get params from.</param> /// <param name="component">Section of the config XML to look in for db params.</param> /// <param name="decryptionDelegate">Delegate to call to decrypt password fields. /// May be null if passwords are in plain text.</param> public MemoryDescriptor(Config config, string component, ConnectionInfoDecryptionDelegate decryptionDelegate) : this(config.GetParameter(component, "UID")) { }