Ejemplo n.º 1
0
        public virtual string ToDisplayString()
        {
            var sensitiveProperties = Properties.Values.Where(x => x.IsSensitive);

            var removedProperties = new List <Tuple <string, object> >();

            foreach (var sensitiveProperty in sensitiveProperties)
            {
                var propertyName = sensitiveProperty.Name;
                if (!_connectionStringBuilder.ShouldSerialize(propertyName))
                {
                    continue;
                }

                removedProperties.Add(new Tuple <string, object>(propertyName, _connectionStringBuilder[propertyName]));
                _connectionStringBuilder.Remove(propertyName);
            }
            var displayConnectionString = _connectionStringBuilder.ConnectionString;

            foreach (var prop in removedProperties.Where(prop => prop.Item2 != null))
            {
                _connectionStringBuilder[prop.Item1] = prop.Item2;
            }

            return(displayConnectionString);
        }
        public override object this[string propertyName]
        {
            get
            {
                if (propertyName == null)
                {
                    throw new ArgumentNullException("propertyName");
                }

                // Update the propertyName to a value which is retrievable using MySqlConnectionStringBuilder.TryGetValue method.
                switch (propertyName)
                {
                case "IntegratedSecurity":
                    propertyName = "Integrated Security";
                    break;

                case "MaximumPoolSize":
                    propertyName = "MaxPoolSize";
                    break;

                case "MinimumPoolSize":
                    propertyName = "MinPoolSize";
                    break;

                case "PipeName":
                    propertyName = "Pipe";
                    break;

                case "SslCertificationAuthorityFile":
                    propertyName = "sslca";
                    break;

                case "SslClientCertificateFile":
                    propertyName = "sslcert";
                    break;

                case "SslKeyFile":
                    propertyName = "sslkey";
                    break;

                case "UseCompression":
                    propertyName = "Compress";
                    break;

                case "UserID":
                    propertyName = "User Id";
                    break;

                default:
                    break;
                }

                object obj;
                if (!ConnectionStringBuilder.TryGetValue(propertyName, out obj))
                {
                    return(null);
                }

                if (ConnectionStringBuilder.ShouldSerialize(propertyName))
                {
                    // A special condition was added to workaround a bug identified in the MySqlConnectionStringBuilder
                    // class which raises a KeyNotFoundException whenever trying to recover the "Integrated Security" key.
                    return(propertyName == "Integrated Security" ? obj : ConnectionStringBuilder[propertyName]);
                }

                return(ConnectionStringBuilder[propertyName] ?? DBNull.Value);
            }

            set
            {
                if (propertyName == null)
                {
                    throw new ArgumentNullException("propertyName");
                }

                ConnectionStringBuilder.Remove(propertyName);
                if (value == DBNull.Value)
                {
                    OnPropertyChanged(new DataConnectionPropertyChangedEventArgs(propertyName));
                }
                else
                {
                    object objA;
                    ConnectionStringBuilder.TryGetValue(propertyName, out objA);
                    ConnectionStringBuilder[propertyName] = value;
                    if (Equals(objA, value))
                    {
                        ConnectionStringBuilder.Remove(propertyName);
                    }

                    OnPropertyChanged(new DataConnectionPropertyChangedEventArgs(propertyName));
                }
            }
        }