You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.0 KiB
C#
112 lines
3.0 KiB
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 数据库结构体
|
|
/// </summary>
|
|
public static class DbList
|
|
{
|
|
/// <summary>
|
|
///独立的大简云publice库
|
|
/// </summary>
|
|
public const string djydb = "djydb";
|
|
/// <summary>
|
|
///大简云平台老库
|
|
/// </summary>
|
|
public const string djyolddb = "djydb";
|
|
/// <summary>
|
|
/// AMS
|
|
/// </summary>
|
|
public const string AMSCenter = "AMS";
|
|
/// <summary>
|
|
/// 日志库
|
|
/// </summary>
|
|
public const string Logsdb = "logsdb";
|
|
|
|
/// <summary>
|
|
/// Common库
|
|
/// </summary>
|
|
public const string Common = "Common";
|
|
|
|
/// <summary>
|
|
/// 东胜库
|
|
/// </summary>
|
|
public const string DSDB = "DSDB";
|
|
}
|
|
|
|
/// <summary>
|
|
/// 数据库操作类
|
|
/// </summary>
|
|
public class DbContext
|
|
{
|
|
/// <summary>
|
|
/// 数据库连接池
|
|
/// </summary>
|
|
public static IdleBus<IFreeSql> DbBus=new IdleBus<IFreeSql>(TimeSpan.FromSeconds(20));
|
|
|
|
/// <summary>
|
|
/// RedisDB
|
|
/// </summary>
|
|
public static RedisClient DbRedis = new RedisClient(string.Format("{0}", sysOptionConfig.Webconfig.Redis));
|
|
|
|
/// <summary>
|
|
/// 数据库连接池初始化
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
}
|