示例#1
0
        /// <summary>
        /// 系统消息发送器构建
        /// </summary>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sqlType">数据库类型</param>
        /// <param name="redisOptions">Redis缓存服务器信息</param>
        /// <param name="keepAlive">是否保持缓存服务器长连接</param>
        /// <param name="cacheItems">需要缓存的数据类型</param>
        /// <param name="level2CacheSeconds">二级缓存时间(单位:秒)</param>
        public static void Factory(string connectionString, SqlProviderType sqlType, string redisOptions, bool keepAlive = true, CacheItemType[] cacheItems = null, int level2CacheSeconds = 30)
        {
            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentNullException(nameof(connectionString));
            }

            Configs.SqlConnectionString = connectionString;

            Configs.SqlType = sqlType;

            if (CacheCollection.Count < 1)
            {
                if (cacheItems == null || cacheItems.Length < 1)
                {
                    cacheItems = new[]
                    {
                        CacheItemType.SystemGolbalConfig,
                        CacheItemType.AreaForum,
                        CacheItemType.UserLevelConfig
                    };
                }

                DataCacheExtensions.UseDataCache(redisOptions, keepAlive, cacheItems, level2CacheSeconds);
            }
        }
示例#2
0
        /// <summary>
        /// 更新数据库连接
        /// </summary>
        /// <param name="sqlType"></param>
        /// <param name="connectionString"></param>
        public static void UpdateSqlConnection(SqlProviderType sqlType, string connectionString)
        {
            KylinDBConnectionString = connectionString;

            SqlType = sqlType;

            InjectionDataCache(true);
        }
示例#3
0
        public Startup(IHostingEnvironment env)
        {
            Application.Start(new ApplicationContext(env));

            // Set up configuration sources.
            var builder = new ConfigurationBuilder()
                          .SetBasePath(env.ContentRootPath)
                          .AddJsonFile("appsettings.json")
                          .AddEnvironmentVariables();

            WebRootPath = env.WebRootPath;

            Configuration = builder.Build();

            _sqlType = new Func <SqlProviderType>(() =>
            {
                string sqltype = Configuration["Data:SqlType"] ?? string.Empty;

                switch (sqltype.ToLower())
                {
                case "npgsql":
                    return(SqlProviderType.NpgSQL);

                case "mssql":
                default:
                    return(SqlProviderType.SqlServer);
                }
            }).Invoke();

            _sqlConn = Configuration["Data:DefaultConnection:ConnectionString"];
            string redisConn = Configuration["Redis:ConnectString"];//Redis缓存服务器信息

            //使用缓存
            DataCacheExtensions.UseDataCache(new DataCacheServerOptions
            {
                KeepAlive             = true,
                CacheItems            = null,
                RedisConnectionString = redisConn,
                InitIfNull            = false,
                SqlType            = _sqlType,
                SqlConnection      = _sqlConn,
                Level2CacheSeconds = int.Parse(Configuration["Redis:Level2CacheSeconds"])
            });

            #region 开启线程 执行索引库写队列处理

            AreaIndexManager.Instance.StartNewThread();

            MallProductIndexManager.Instance.StartNewThread();

            MerchantProductIndexManager.Instance.StartNewThread();

            MerchantIndexManager.Instance.StartNewThread();

            JobIndexManager.Instance.StartNewThread();

            #endregion
        }
示例#4
0
 /// <summary>
 /// 实例化(非Web程序中使用)
 /// </summary>
 /// <param name="redisOptions"></param>
 /// <param name="sqlType">数据库类型</param>
 /// <param name="sqlConnection">数据库连接字符串</param>
 public IMDataMiddleware(SqlProviderType sqlType, string sqlConnection)
 {
     if (string.IsNullOrWhiteSpace(sqlConnection))
     {
         throw new ArgumentNullException(nameof(sqlConnection));
     }
     _sqlProviderType     = sqlType;
     _sqlconnectionString = sqlConnection;
 }
 public static ISqlProvider GetSqlProvider(SqlProviderType type)
 {
     switch (type)
     {
         case SqlProviderType.SqlServer:
             return new MsSqlProvider();
         //    break;
         case SqlProviderType.PostgreSql:
             return new PgSqlProvider();
         //    break;
         default:
             throw new ArgumentException("The selected sql provider type was not recognized.");
         //    break;
     }
 }
        /// <summary>
        /// 使用SMS Sender组件
        /// </summary>
        /// <param name="providerType"><seealso cref="SmsProviderType"/></param>
        /// <param name="smsConfig"><seealso cref="SmsConfig"/>配置信息,根据providerType参数值配置对应的信息</param>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sqlType">数据库类型</param>
        public static void Factory(SmsProviderType providerType, SmsConfig smsConfig, string connectionString, SqlProviderType sqlType)
        {
            var option = new MiddlewareOptions();

            switch (providerType)
            {
            case SmsProviderType.YunPian:
                option.SendProvider = new YunPianProvider(smsConfig as YuanPianConfig);
                break;
            }

            option.SqlConnectionString = connectionString;

            option.SqlType = sqlType;

            MiddlewareConfig.Options = option;
        }
        /// <summary>
        /// 使用SMS Sender组件
        /// </summary>
        /// <param name="providerType"><seealso cref="SmsProviderType"/></param>
        /// <param name="smsConfig"><seealso cref="SmsConfig"/>配置信息,根据providerType参数值配置对应的信息</param>
        /// <param name="connectionString">数据库连接字符串</param>
        /// <param name="sqlType">数据库类型</param>
        /// <returns></returns>
        public static IApplicationBuilder UseSMSSenderMiddleware(this IApplicationBuilder builder, SmsProviderType providerType, SmsConfig smsConfig, string connectionString, SqlProviderType sqlType)
        {
            var option = new MiddlewareOptions();

            switch (providerType)
            {
            case SmsProviderType.YunPian:
                option.SendProvider = new YunPianProvider(smsConfig as YuanPianConfig);
                break;
            }

            option.SqlConnectionString = connectionString;

            option.SqlType = sqlType;

            return(UseSMSSenderMiddleware(builder, option));
        }
示例#8
0
 /// <summary>
 /// 注入授权
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="serverID">当前接口服务ID</param>
 /// <param name="sqlConnection"></param>
 /// <param name="sqlType"></param>
 /// <param name="LogUrl">错误日志接口Url</param>
 /// <returns></returns>
 public static IApplicationBuilder UseKylinWebApi(this IApplicationBuilder builder, string serverID, string sqlConnection, SqlProviderType sqlType, LogOptions LogEntity)
 {
     return(UseKylinWebApi(builder, new KylinWebApiOptions
     {
         SqlConnectionString = sqlConnection,
         SqlType = sqlType,
         ServerID = serverID,
         Log = LogEntity
     }));
 }
示例#9
0
 /// <summary>
 /// 注入IM Data服务(非Web形式注入)
 /// </summary>
 /// <param name="builder"></param>
 /// <param name="sqlType">数据库类型</param>
 /// <param name="sqlConnection">数据库连接字符串</param>
 /// <returns></returns>
 public static void UseIMData(SqlProviderType sqlType, string sqlConnection)
 {
     new IMDataMiddleware(sqlType, sqlConnection).Invoke();
 }