using FreeRedis; using FreeRedis.Internal; using FreeSql; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using Common; using System.Data; namespace djy.Service.DjyService { /// /// 数据库结构体 /// public static class DbList { /// ///独立的大简云publice库 /// public const string djydb = "djydb"; /// ///大简云平台老库 /// public const string djyolddb = "djydb"; /// /// AMS /// public const string AMSCenter = "AMS"; /// /// 日志库 /// public const string Logsdb = "logsdb"; /// /// Common库 /// public const string Common = "Common"; } /// /// 数据库操作类 /// public class DbContext { /// /// 数据库连接池 /// public static IdleBus DbBus=new IdleBus(TimeSpan.FromSeconds(20)); /// /// RedisDB /// public static RedisClient DbRedis = new RedisClient(string.Format("{0}", sysOptionConfig.Webconfig.Redis)); /// /// 数据库连接池初始化 /// /// public static bool DbBusInit() { foreach (var item in sysOptionConfig.Webconfig.DataConnList) { if (item.SysKey == DbList.Logsdb)//日志库允许自动更新表结构 { DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString) .UseAutoSyncStructure(true) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText); }) .Build()); } else { DbBus.Register(item.SysKey, () => new FreeSqlBuilder().UseConnectionString((DataType)item.DataType, item.ConnString) .UseAutoSyncStructure(false) .UseNoneCommandParameter(true) .UseMonitorCommand(cmd => { Trace.WriteLine("\r\n" + Thread.CurrentThread.ManagedThreadId + ":" + cmd.CommandText); }) .Build()); } } return true; } } }