private PostgreSqlConnectionStringBuilder PreparePostgreSqlConnectionStringBuilder(out Dictionary<string, string> referenceValues) { referenceValues = new Dictionary<string, string>(); referenceValues.Add("Name", "Test ConnectionString"); referenceValues.Add("Database", "db"); referenceValues.Add("Server", "server"); referenceValues.Add("Port", "1234"); referenceValues.Add("SSL", false.ToString()); referenceValues.Add("UserId", "username"); referenceValues.Add("Password", "password"); PostgreSqlConnectionStringBuilder csb = new PostgreSqlConnectionStringBuilder(); csb.Name = referenceValues["Name"]; csb.Database = referenceValues["Database"]; csb.Server = referenceValues["Server"]; csb.Port = int.Parse(referenceValues["Port"]); csb.SSL = bool.Parse(referenceValues["SSL"]); csb.UserId = referenceValues["UserId"]; csb.Password = referenceValues["Password"]; return csb; }
/// <summary> /// Creates a new PostgreSql connection. /// </summary> /// <param name="connection">The PostgreSql connection.</param> /// <param name="configPath">The config path.</param> /// <param name="configFile">The config file.</param> /// <remarks>Documented by Dev03, 2008-12-19</remarks> public static void CreatePostgreSqlConnection(PostgreSqlConnectionStringBuilder connection, string configPath, string configFile) { if (connection == null) throw new ArgumentNullException("connection can't be null"); if (configPath == null) throw new ArgumentNullException("configPath can't be null"); if (configFile == null) throw new ArgumentNullException("configFile can't be null"); if (configPath.Trim().Length == 0) throw new ArgumentException("configPath can't be null"); if (configFile.Trim().Length == 0) throw new ArgumentException("configFile can't be null"); XmlSerializer uncSerializer = new XmlSerializer(typeof(PostgreSqlConnectionStringBuilder)); Directory.CreateDirectory(configPath); using (Stream uncStream = File.Create(Path.Combine(configPath, configFile))) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; XmlWriter writer = XmlTextWriter.Create(uncStream, settings); writer.WriteStartElement("Configuration"); writer.WriteStartElement("Connections"); uncSerializer.Serialize(writer, connection); writer.WriteEndElement(); writer.WriteEndElement(); writer.Close(); uncStream.Close(); } }