public static void Configure(string connectionKey, string savedConnectionsKey)
        {
            ConnectionKey = connectionKey;

            SavedConnectionKey = savedConnectionsKey;
            CurrentConnection  = new ConnectionString();
            // Load from Registry if it exists
            try
            {
                CurrentConnection.LoadFromRegistry(connectionKey);
            }
            catch
            {
                RegistryHelper helper = new RegistryHelper();
                helper.Write(ConnectionKey, "ConnectionString", "");
            }
        }
        private static void CheckEncryption(RegistryHelper registryHelper)
        {
            var HistoricConnectionStrings = registryHelper.GetSubKeys(SavedConnectionKey);

            // Do the encrption if the strings were not encrypted already.

            foreach (var x in HistoricConnectionStrings)
            {
                if (x.Value.Contains("Data"))
                {
                    RegistryHelper helper = new RegistryHelper();
                    if (!string.IsNullOrEmpty(x.Key))
                    {
                        helper.Delete(ConnectionHelper.SavedConnectionKey, x.Key);
                    }
                    helper.Write(ConnectionHelper.SavedConnectionKey, x.Key,
                                 EncriptionHelper.EncryptString(x.Value, ConnectionHelper.Salt));
                }
            }
        }
        public void LoadFromRegistry(string key)
        {
            RegistryHelper registry= new RegistryHelper();
            _OrigionalString = registry.Read(key,"ConnectionString");

            // check if the read string was encrypted or not.
            // this is not a very reliable check as the database name could be different
            if(!_OrigionalString.Contains("Data"))
            {
                //
                _OrigionalString = EncriptionHelper.DecryptString(_OrigionalString, ConnectionHelper.Salt);
            }else
            {
                // write the ecrypted version instead of the version that is plain text.
                registry.Write(key, "ConnectionString",
                               EncriptionHelper.EncryptString(_OrigionalString, ConnectionHelper.Salt));
            }

            Parse(_OrigionalString);
            Name = registry.Read(key, "ConnectionName");
        }
        internal void SaveAsDefault()
        {
            RegistryHelper registry = new RegistryHelper();
            registry.Write(ConnectionHelper.ConnectionKey, "ConnectionName", Name);

            // encrypt and save the default connection string.
            registry.Write(ConnectionHelper.ConnectionKey, "ConnectionString", EncriptionHelper.EncryptString(ToString(), ConnectionHelper.Salt));
        }
        public static void Configure(string connectionKey, string savedConnectionsKey)
        {
            ConnectionKey = connectionKey;

            SavedConnectionKey = savedConnectionsKey;
            CurrentConnection = new ConnectionString();
            // Load from Registry if it exists
            try
            {
                CurrentConnection.LoadFromRegistry(connectionKey);
            }
            catch
            {
               RegistryHelper helper = new RegistryHelper();
               helper.Write(ConnectionKey, "ConnectionString", "");
            }
        }
        private static void CheckEncryption(RegistryHelper registryHelper)
        {
            var HistoricConnectionStrings = registryHelper.GetSubKeys(SavedConnectionKey);

            // Do the encrption if the strings were not encrypted already.

            foreach (var x in HistoricConnectionStrings)
            {
                if (x.Value.Contains("Data"))
                {
                    RegistryHelper helper = new RegistryHelper();
                    if (!string.IsNullOrEmpty(x.Key))
                    {
                        helper.Delete(ConnectionHelper.SavedConnectionKey, x.Key);
                    }
                    helper.Write(ConnectionHelper.SavedConnectionKey, x.Key,
                                 EncriptionHelper.EncryptString(x.Value, ConnectionHelper.Salt));
                }
            }
        }