/// <summary>
        /// 创建数据库连接。
        /// </summary>
        /// <param name="connectionOptions">连接参数。</param>
        /// <returns>返回数据库连接。</returns>
        public override IConnection CreateConnection(object connectionOptions)
        {
            {
                if (connectionOptions is string connectionString)
                {
                    connectionString = connectionString.Trim();
                    if (connectionString.StartsWith("{"))
                    {
                        connectionOptions = JSON.Parse(connectionString);
                        goto lb_Object;
                    }
                    return(CreateConnection(connectionString));
                }
                if (connectionOptions is ConnectionOptions connectionOptions2)
                {
                    connectionOptions = connectionOptions2.ToObject();
                    goto lb_Object;
                }
            }
lb_Object:
            System.Data.SqlClient.SqlConnectionStringBuilder builder = new System.Data.SqlClient.SqlConnectionStringBuilder();
            Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>(connectionOptions);
            builder.MaxPoolSize = 1024;
            SetBuilderValue(builder, values, "host", "Data Source", p => {
                string p10 = p as string;
                if (string.IsNullOrEmpty(p10))
                {
                    return(p);
                }
                if (p10.IndexOf(':') > -1)
                {
                    return(p10.Replace(':', ','));
                }
                return(p);
            });
            SetBuilderValue(builder, values, "port", "Data Source", p => {
                string p10 = TypeExtensions.Convert <string>(p);
                if (string.IsNullOrEmpty(p10))
                {
                    return(null);
                }
                builder.DataSource += "," + p10;
                return(null);
            });

            SetBuilderValue(builder, values, "name", "Initial Catalog");
            SetBuilderValue(builder, values, "account", "User ID");
            SetBuilderValue(builder, values, "password", "Password");
            foreach (System.Collections.Generic.KeyValuePair <string, object> item in values)
            {
                //builder[item.Key] = item.Value;
                SetBuilderValue(builder, item.Key, item.Value);
            }
            if (!builder.PersistSecurityInfo && !builder.IntegratedSecurity)
            {
                builder.PersistSecurityInfo = true;
            }
            builder.MultipleActiveResultSets = true;
            return(CreateConnection(builder.ConnectionString));
        }
Example #2
0
        /// <summary>
        /// 创建数据库连接。
        /// </summary>
        /// <param name="connectionOptions">连接参数。</param>
        /// <returns>返回数据库连接。</returns>
        public override IConnection CreateConnection(object connectionOptions)
        {
            {
                if (connectionOptions is string connectionString)
                {
                    connectionString = connectionString.Trim();
                    if (connectionString.StartsWith("{"))
                    {
                        connectionOptions = JSON.Parse(connectionString);
                        goto lb_Object;
                    }
                    return(CreateConnection(connectionString));
                }
                if (connectionOptions is ConnectionOptions connectionOptions2)
                {
                    connectionOptions = connectionOptions2.ToObject();
                    goto lb_Object;
                }
            }
lb_Object:
            System.Data.Common.DbConnectionStringBuilder builder = FastWrapper.CreateInstance <System.Data.Common.DbConnectionStringBuilder>(GetType("MySql.Data.MySqlClient.MySqlConnectionStringBuilder", true));
            builder["pooling"] = true;
            //builder["MaxPoolSize"] = 1024;
            //builder["Port"] = 5432;
            builder["Charset"] = "utf8";
            Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>(connectionOptions);
            SetBuilderValue(builder, "SslMode", "None");
            SetBuilderValue(builder, values, "port", "Port");
            SetBuilderValue(builder, values, "host", "Data Source", p => {
                string p10 = p as string;
                if (string.IsNullOrEmpty(p10))
                {
                    return(p);
                }
                if (p10.IndexOf(':') > -1)
                {
                    string[] pair = p10.Split(':');
                    SetBuilderValue(builder, "Port", pair[1]);
                    return(pair[0]);
                }
                return(p);
            });
            SetBuilderValue(builder, values, "name", "Database");
            SetBuilderValue(builder, values, "account", "User ID");
            SetBuilderValue(builder, values, "password", "Password");
            foreach (System.Collections.Generic.KeyValuePair <string, object> item in values)
            {
                //builder[item.Key] = item.Value;
                SetBuilderValue(builder, item.Key, item.Value);
            }
            return(CreateConnection(builder.ConnectionString));
        }
        /// <summary>
        /// 创建数据库连接。
        /// </summary>
        /// <param name="connectionOptions">连接参数。</param>
        /// <returns>返回数据库连接。</returns>
        public override IConnection CreateConnection(object connectionOptions)
        {
            {
                if (connectionOptions is string connectionString)
                {
                    connectionString = connectionString.Trim();
                    if (connectionString.StartsWith("{"))
                    {
                        connectionOptions = JSON.Parse(connectionString);
                        goto lb_Object;
                    }
                    return(CreateConnection(connectionString));
                }
                if (connectionOptions is ConnectionOptions connectionOptions2)
                {
                    connectionOptions = connectionOptions2.ToObject();
                    goto lb_Object;
                }
            }
lb_Object:
            System.Data.Common.DbConnectionStringBuilder builder = SQLite.SQLiteHelper.CreateConnectionStringBuilder();
            Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>(connectionOptions);
            SetBuilderValue(builder, values, "host", "Data Source");
            SetBuilderValue(builder, values, "file", "Data Source");
            SetBuilderValue(builder, values, "name", "Data Source");
            SetBuilderValue(builder, values, "memory", "Data Source", p => {
                if (TypeExtensions.Convert(p, false))
                {
                    return(":memory:");
                }
                return(p);
            });
            foreach (System.Collections.Generic.KeyValuePair <string, object> item in values)
            {
                //builder[item.Key] = item.Value;
                SetBuilderValue(builder, item.Key, item.Value);
            }
            return(CreateConnection(builder.ConnectionString));
        }
Example #4
0
 /// <summary>
 /// 匹配
 /// </summary>
 /// <param name="url">需要匹配的url。</param>
 /// <returns>任何匹配不成功时都返回null。</returns>
 public Symbol.Collections.Generic.NameValueCollection <object> Match(string url)
 {
     if (string.IsNullOrEmpty(url))
     {
         return(null);
     }
     System.Text.RegularExpressions.Match match = _regex.Match(url);
     if (!match.Success)
     {
         return(null);
     }
     Symbol.Collections.Generic.NameValueCollection <object> values = new Collections.Generic.NameValueCollection <object>();
     foreach (var item in _list_type)
     {
         string value = match.Groups[item.Key]?.Value;
         if (string.IsNullOrEmpty(value))
         {
             return(null);
         }
         if (item.Value == "byte")
         {
             byte?v = TypeExtensions.Convert <byte?>(value);
             if (v == null)
             {
                 return(null);
             }
             values[item.Key] = v.Value;
             continue;
         }
         else if (item.Value == "date")
         {
             DateTime?v = TypeExtensions.Convert <DateTime?>(value);
             if (v == null || v.Value.Year < 1970)
             {
                 return(null);
             }
             values[item.Key] = v.Value;
             continue;
         }
         else if (item.Value == "datetime")
         {
             DateTime?v = TypeExtensions.Convert <DateTime?>(value);
             if (v == null || v.Value.Year < 1970)
             {
                 return(null);
             }
             values[item.Key] = v.Value;
             continue;
         }
         else if (item.Value == "time")
         {
             TimeSpan?v = TypeExtensions.Convert <TimeSpan?>(value);
             if (v == null || v.Value.TotalMilliseconds < 0)
             {
                 return(null);
             }
             values[item.Key] = v.Value;
             continue;
         }
         else if (item.Value == "guid")
         {
             Guid?v = TypeExtensions.Convert <Guid?>(value);
             if (v == null)
             {
                 return(null);
             }
             values[item.Key] = v.Value;
             continue;
         }
         values[item.Key] = value;
     }
     return(values);
 }
Example #5
0
 /// <summary>
 /// 设置构造器的参数。
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="values">参数列表。</param>
 /// <param name="name">标准命名。</param>
 /// <param name="aliasName">别名。</param>
 /// <param name="filter">过滤器。</param>
 protected void SetBuilderValue(System.Data.Common.DbConnectionStringBuilder builder, Collections.Generic.NameValueCollection <object> values, string name, string aliasName, ValueFilter filter = null)
 {
     if (SetBuilderValue(builder, aliasName, values[name], filter))
     {
         values.Remove(name);
     }
 }