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#

3 years ago
using FreeRedis;
3 years ago
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;
3 years ago
using System.Data;
3 years ago
2 years ago
namespace djy.Service.DjyService
3 years ago
{
/// <summary>
/// 数据库结构体
/// </summary>
public static class DbList
{
/// <summary>
///独立的大简云publice库
/// </summary>
3 years ago
public const string djydb = "djydb";
3 years ago
/// <summary>
///大简云平台老库
/// </summary>
2 years ago
public const string djyolddb = "djydb";
3 years ago
/// <summary>
3 years ago
/// AMS
3 years ago
/// </summary>
3 years ago
public const string AMSCenter = "AMS";
3 years ago
/// <summary>
/// 日志库
/// </summary>
public const string Logsdb = "logsdb";
3 years ago
/// <summary>
/// Common库
/// </summary>
public const string Common = "Common";
2 years ago
/// <summary>
/// 东胜库
/// </summary>
public const string DSDB = "DSDB";
3 years ago
}
/// <summary>
/// 数据库操作类
/// </summary>
public class DbContext
{
/// <summary>
/// 数据库连接池
/// </summary>
public static IdleBus<IFreeSql> DbBus=new IdleBus<IFreeSql>(TimeSpan.FromSeconds(20));
/// <summary>
/// RedisDB
/// </summary>
3 years ago
public static RedisClient DbRedis = new RedisClient(string.Format("{0}", sysOptionConfig.Webconfig.Redis));
3 years ago
/// <summary>
/// 数据库连接池初始化
/// </summary>
/// <returns></returns>
public static bool DbBusInit() {
3 years ago
foreach (var item in sysOptionConfig.Webconfig.DataConnList)
3 years ago
{
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;
}
3 years ago
3 years ago
}
}