private static string GenerateConnectionString(string edsSqlSchemaVersion, string connectionString)
        {
            string value = Guid.NewGuid().ToString();
            DbConnectionStringBuilder dbConnectionStringBuilder = new DbConnectionStringBuilder();

            dbConnectionStringBuilder.ConnectionString = connectionString;
            object obj;

            if (dbConnectionStringBuilder.TryGetValue("Site", out obj))
            {
                dbConnectionStringBuilder.Remove("Site");
            }
            SqlConnectionStringBuilder sqlConnectionStringBuilder = new SqlConnectionStringBuilder(dbConnectionStringBuilder.ConnectionString);
            object obj2;

            if (!sqlConnectionStringBuilder.TryGetValue("Password", out obj2))
            {
                throw new ArgumentException("The connection string must contain a password.");
            }
            string password;

            if (!ManageEdsConnectionStrings.DkmEncryptString(obj2.ToString(), out password))
            {
                throw new ApplicationException("Unable to encrypt password");
            }
            sqlConnectionStringBuilder.Password = password;
            object obj3;

            if (!sqlConnectionStringBuilder.TryGetValue("User ID", out obj3) || string.IsNullOrEmpty(obj3.ToString()))
            {
                throw new ArgumentException("The connection string must contains a User ID");
            }
            if (!sqlConnectionStringBuilder.TryGetValue("Initial Catalog", out obj3) || string.IsNullOrEmpty(obj3.ToString()))
            {
                throw new ArgumentException("The connection string must contains an Initial Catalog");
            }
            if (!sqlConnectionStringBuilder.TryGetValue("Data Source", out obj3) || string.IsNullOrEmpty(obj3.ToString()))
            {
                throw new ArgumentException("The connection string must contains a Data Source");
            }
            DbConnectionStringBuilder dbConnectionStringBuilder2 = new DbConnectionStringBuilder();

            dbConnectionStringBuilder2.ConnectionString = sqlConnectionStringBuilder.ConnectionString;
            if (!string.IsNullOrEmpty((string)obj))
            {
                dbConnectionStringBuilder2.Add("Site", obj);
            }
            dbConnectionStringBuilder2.Add("Guid", value);
            dbConnectionStringBuilder2.Add("EdsSqlSchemaVersion", edsSqlSchemaVersion);
            return(dbConnectionStringBuilder2.ToString());
        }
            public void Add(string edsSqlSchemaVersion, string connectionString)
            {
                List <string> edsEndpointObject = this.GetEdsEndpointObject();

                if (edsEndpointObject != null)
                {
                    List <string> list = new List <string>(edsEndpointObject);
                    string        item = ManageEdsConnectionStrings.GenerateConnectionString(edsSqlSchemaVersion, connectionString);
                    list.Add(item);
                    this.SetEdsEndpointObject(list);
                    return;
                }
                throw new ApplicationException("The EDS endpoint object does not exist.");
            }
            public void Add(string edsSqlSchemaVersion, string connectionString)
            {
                SearchResult edsEndpointObject = ManageEdsConnectionStrings.AdConnectionStrings.GetEdsEndpointObject();

                if (edsEndpointObject != null)
                {
                    string value = ManageEdsConnectionStrings.GenerateConnectionString(edsSqlSchemaVersion, connectionString);
                    using (DirectoryEntry directoryEntry = new DirectoryEntry(edsEndpointObject.Path))
                    {
                        directoryEntry.Properties["serviceBindingInformation"].Add(value);
                        directoryEntry.CommitChanges();
                        return;
                    }
                }
                throw new ApplicationException("The EDS endpoint object does not exist.");
            }
 static ManageEdsConnectionStrings()
 {
     ManageEdsConnectionStrings.Initialize();
 }