internal ConnectionManager(string connectionString_Write, string[] connectionStrings_Read)
        {
            this.ConnectionString_Write = connectionString_Write;
            this.ConnectionStrings_Read = connectionStrings_Read?.Distinct()?.ToArray();
            //默认当前连接字符串是写
            this.CurrentConnectionString = connectionString_Write;

            //初始化
            //如果写字符串不需要负载策略,则直接返回
            if (ConnectionStrings_Read == null || !ConnectionStrings_Read.Any() || ConnectionStrings_Read.Length == 1)
                return;

            connectionStatuses = new List<ConnectionStatus>();

            //初始化连接使用情况集合
            ConnectionStrings_Read.Distinct().ToArray().Foreach(item => connectionStatuses.Add(new ConnectionStatus { HashKey = item.GetHashCode(), ConnectionString = item, Count = 0 }));

        }
Beispiel #2
0
        /// <summary>
        /// constructed function
        /// </summary>
        /// <param name="connectionString_Write">the master Database ConnectionString (Only one)</param>
        /// <param name="connectionStrings_Read">the slave Database ConnectionStrings</param>
        internal ConnectionManager(string connectionString_Write, string[] connectionStrings_Read)
        {
            this.ConnectionString_Write = connectionString_Write.ToFormativeConnectionString();
            this.ConnectionStrings_Read = connectionStrings_Read?.Select(c => c.ToFormativeConnectionString()).Distinct()?.ToArray();

            this.CurrentConnectionString = this.ConnectionString_Write;

            //don't need Load Balance Strategy
            if (ConnectionStrings_Read == null || !ConnectionStrings_Read.Any() || ConnectionStrings_Read.Length == 1)
            {
                return;
            }

            this.connectionStatuses = new List <ConnectionStatus>();

            //Initialize connection usage collection
            ConnectionStrings_Read.Distinct().ToArray().Foreach(item => connectionStatuses.Add(new ConnectionStatus {
                HashKey = item.GetHashCode(), ConnectionString = item, Count = 0
            }));
        }