public virtual ILdapConnectionSettings Parse(string connectionString) { if (connectionString == null) { throw new ArgumentNullException("connectionString"); } var ldapConnectionSettings = new LdapConnectionSettings(); var dictionary = this.GetConnectionStringAsDictionary(connectionString); if (dictionary.Any()) { try { foreach (var keyValuePair in dictionary) { this.TrySetValue(ldapConnectionSettings, keyValuePair); } } catch (Exception exception) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "The connection-string \"{0}\" could not be parsed.", connectionString), exception); } } return(ldapConnectionSettings); }
protected internal virtual void TrySetValue(LdapConnectionSettings ldapConnectionSettings, KeyValuePair <string, string> keyValuePair) { if (ldapConnectionSettings == null) { throw new ArgumentNullException("ldapConnectionSettings"); } if (string.IsNullOrEmpty(keyValuePair.Key)) { throw new FormatException("A key can not be empty."); } switch (keyValuePair.Key.ToLowerInvariant()) { case "authenticationtype": { ldapConnectionSettings.AuthenticationType = (AuthType)Enum.Parse(typeof(AuthType), keyValuePair.Value); break; } case "distinguishedname": { ldapConnectionSettings.DistinguishedName = keyValuePair.Value; break; } case "host": { ldapConnectionSettings.Host = keyValuePair.Value; break; } case "password": { ldapConnectionSettings.Password = keyValuePair.Value; break; } case "port": { ldapConnectionSettings.Port = int.Parse(keyValuePair.Value, CultureInfo.InvariantCulture); break; } case "securesocketlayer": { ldapConnectionSettings.SecureSocketLayer = bool.Parse(keyValuePair.Value); break; } case "timeout": { ldapConnectionSettings.Timeout = TimeSpan.Parse(keyValuePair.Value); break; } case "username": { ldapConnectionSettings.UserName = keyValuePair.Value; break; } default: { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "The key \"{0}\" is not valid.", keyValuePair.Key)); } } }