コード例 #1
0
        internal Client(object connectionString, object connectionOptions)
        {
            if (connectionString == null ||
                (connectionString is string &&
                 string.IsNullOrWhiteSpace(connectionString as string)))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            if (connectionOptions == null ||
                (connectionOptions is string &&
                 string.IsNullOrWhiteSpace(connectionOptions as string)))
            {
                throw new ArgumentNullException(nameof(connectionOptions));
            }

            bool isDefaultPort = true;

            if (connectionString is string)
            {
                isDefaultPort = !connectionString.ToString().Contains("port");
                //Validates the connection string or Uri string
                new MySqlXConnectionStringBuilder(new ClientSession().ParseConnectionData(connectionString as string), isDefaultPort);
                _connectionString = connectionString as string;
            }
            else
            {
                MySqlXConnectionStringBuilder settings = new MySqlXConnectionStringBuilder();
                foreach (var item in Tools.GetDictionaryFromAnonymous(connectionString))
                {
                    if (!settings.ContainsKey(item.Key))
                    {
                        throw new KeyNotFoundException(string.Format(ResourcesX.InvalidConnectionStringAttribute, item.Key));
                    }
                    settings.SetValue(item.Key, item.Value);
                    if (item.Key == "port")
                    {
                        isDefaultPort = false;
                    }
                }
                _connectionString = settings.ToString().Replace("\"", "");
                settings.AnalyzeConnectionString(_connectionString, true, isDefaultPort);
            }

            _connectionOptions = ParseConnectionOptions(connectionOptions);

            // Pooling setup
            _inUse          = new List <Session>(_connectionOptions.Pooling.MaxSize);
            _inIdle         = new ConcurrentQueue <Session>();
            _available      = _connectionOptions.Pooling.MaxSize;
            _autoResetEvent = new AutoResetEvent(false);
            _idleTimer      = new Timer(new TimerCallback(CleanIdleConnections),
                                        null,
                                        _connectionOptions.Pooling.MaxIdleTime,
                                        _connectionOptions.Pooling.MaxIdleTime == 0 ? Timeout.Infinite : _connectionOptions.Pooling.MaxIdleTime);
        }
コード例 #2
0
ファイル: BaseSession.cs プロジェクト: zhouweiaccp/MySQL.Data
 // Constructor used exclusively to parse connection string or connection data
 internal BaseSession()
 {
     Settings = new MySqlXConnectionStringBuilder();
 }