Example #1
0
        public static IDictionary <string, ConnectionParams> EnumerateConnections()
        {
            ConnectionParamsCollection             _connParams;
            IDictionary <string, ConnectionParams> result = new Dictionary <string, ConnectionParams>();

            if (!File.Exists(_path))
            {
                return(result);
            }
            _connParams = ObjectXMLSerializer <ConnectionParamsCollection> .Load(_path);

            string normalServerName = String.Empty;

            foreach (ConnectionParams cp in _connParams)
            {
                if (cp.IsEncrypted)
                {
                    cp.Password = EncryiptionHelper.Decrypt(cp.Password);
                }

                normalServerName = cp.Server.Trim().ToLowerInvariant();
                if (!result.ContainsKey(normalServerName))
                {
                    result.Add(normalServerName, cp);
                }
            }

            return(result);;
        }
Example #2
0
        public static ConnectionParamsCollection GetConnections()
        {
            ConnectionParamsCollection _connParams;
            bool SaveEncrypted = false;

            if (!File.Exists(_path))
            {
                return(new ConnectionParamsCollection());
            }


            /*
             *
             * string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DBConnections.config");
             * if (!System.IO.File.Exists(filename))
             *      return (new ConnectionParamsCollection());
             *
             * XmlSerializer ser = new XmlSerializer(typeof(ConnectionParamsCollection));
             * TextReader reader = new StreamReader(filename);
             * _connParams = (ConnectionParamsCollection)ser.Deserialize(reader);
             * reader.Close();
             */

            _connParams = ObjectXMLSerializer <ConnectionParamsCollection> .Load(_path);

            foreach (ConnectionParams cp in _connParams)
            {
                if (!cp.IsEncrypted)
                {
                    SaveEncrypted = true;
                }
                else
                {
                    cp.Password = EncryiptionHelper.Decrypt(cp.Password);
                }
            }

            if (SaveEncrypted)
            {
                Save(_connParams);
            }


            return(_connParams);
        }
Example #3
0
        public static void Save(ConnectionParamsCollection connParams)
        {
            foreach (ConnectionParams cp in connParams)
            {
                cp.IsEncrypted = true;
                cp.Password    = EncryiptionHelper.Encrypt(cp.Password);
            }

            /*
             * string filename = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "DBConnections.config");
             * XmlSerializer ser = new XmlSerializer(typeof(ConnectionParamsCollection));
             * TextWriter writer = new StreamWriter(filename);
             * ser.Serialize(writer, connParams);
             * writer.Close();
             */

            ObjectXMLSerializer <ConnectionParamsCollection> .Save(connParams, _path);

            // Reset password
            foreach (ConnectionParams cp in connParams)
            {
                cp.Password = EncryiptionHelper.Decrypt(cp.Password);
            }
        }