添加项目文件。
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using JNPF;
|
||||
using JNPF.Common.Options;
|
||||
using OnceMi.AspNetCore.OSS;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// OSS服务配置拓展.
|
||||
/// </summary>
|
||||
public static class OSSServiceConfigureExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// OSS服务配置.
|
||||
/// </summary>
|
||||
/// <param name="services"></param>
|
||||
/// <returns></returns>
|
||||
public static IServiceCollection OSSServiceConfigure(this IServiceCollection services)
|
||||
{
|
||||
// 获取选项
|
||||
OssOptions oss = App.GetConfig<OssOptions>("OSS", true);
|
||||
|
||||
string fileStoreType = oss.Provider.ToString();
|
||||
OSSProvider provider = (OSSProvider)oss.Provider;
|
||||
string endpoint = oss.Endpoint;
|
||||
string accessKey = oss.AccessKey;
|
||||
string secretKey = oss.SecretKey;
|
||||
string region = oss.Region;
|
||||
bool isEnableHttps = oss.IsEnableHttps;
|
||||
bool isEnableCache = oss.IsEnableCache;
|
||||
|
||||
services.AddOSSService(fileStoreType, option =>
|
||||
{
|
||||
option.Provider = provider; // 服务器
|
||||
option.Endpoint = endpoint; // 地址
|
||||
option.AccessKey = accessKey; // 服务访问玥
|
||||
option.SecretKey = secretKey; // 服务密钥
|
||||
option.Region = region;
|
||||
option.IsEnableHttps = isEnableHttps; // 是否启用https
|
||||
option.IsEnableCache = isEnableCache; // 是否启用缓存
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Reflection;
|
||||
using JNPF;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// SqlSugar配置拓展.
|
||||
/// </summary>
|
||||
public static class SqlSugarConfigureExtensions
|
||||
{
|
||||
public static IServiceCollection SqlSugarConfigure(this IServiceCollection services)
|
||||
{
|
||||
// 获取选项
|
||||
ConnectionStringsOptions connectionStrings = App.GetConfig<ConnectionStringsOptions>("ConnectionStrings", true);
|
||||
|
||||
List<ConnectionConfig> connectConfigList = new List<ConnectionConfig>();
|
||||
|
||||
string? connectionStr = connectionStrings.DefaultConnection;
|
||||
var dataBase = connectionStrings.DBName;
|
||||
var DBType = (DbType)Enum.Parse(typeof(DbType), connectionStrings.DBType);
|
||||
var ConfigId = connectionStrings.ConfigId;
|
||||
var DBName = connectionStrings.DBName;
|
||||
|
||||
// 默认数据库
|
||||
connectConfigList.Add(new ConnectionConfig
|
||||
{
|
||||
ConnectionString = string.Format(connectionStr, DBName),
|
||||
DbType = DBType,
|
||||
IsAutoCloseConnection = true,
|
||||
ConfigId = ConfigId,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
MoreSettings = new ConnMoreSettings()
|
||||
{
|
||||
IsAutoRemoveDataCache = true // 自动清理缓存
|
||||
},
|
||||
});
|
||||
|
||||
services.AddSqlSugar(connectConfigList, client =>
|
||||
{
|
||||
//connectConfigList.ForEach(config =>
|
||||
//{
|
||||
// var db = ((SqlSugarScope)client).GetConnectionScope((string)config.ConfigId);
|
||||
|
||||
// // 设置超时时间
|
||||
// db.Ado.CommandTimeOut = 30;
|
||||
|
||||
// // 打印SQL语句
|
||||
// db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
// {
|
||||
// if (sql.StartsWith("SELECT", StringComparison.OrdinalIgnoreCase))
|
||||
// Console.ForegroundColor = ConsoleColor.Green;
|
||||
// if (sql.StartsWith("UPDATE", StringComparison.OrdinalIgnoreCase) || sql.StartsWith("INSERT", StringComparison.OrdinalIgnoreCase))
|
||||
// Console.ForegroundColor = ConsoleColor.White;
|
||||
// if (sql.StartsWith("DELETE", StringComparison.OrdinalIgnoreCase))
|
||||
// Console.ForegroundColor = ConsoleColor.Blue;
|
||||
// Console.WriteLine("【" + DateTime.Now + "——执行SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, sql, pars) + "\r\n");
|
||||
// App.PrintToMiniProfiler("SqlSugar", "Info", sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
// };
|
||||
// db.Aop.OnError = (ex) =>
|
||||
// {
|
||||
// Console.ForegroundColor = ConsoleColor.Red;
|
||||
// var pars = db.Utilities.SerializeObject(((SugarParameter[])ex.Parametres).ToDictionary(it => it.ParameterName, it => it.Value));
|
||||
// Console.WriteLine("【" + DateTime.Now + "——错误SQL】\r\n" + UtilMethods.GetSqlString(config.DbType, ex.Sql, (SugarParameter[])ex.Parametres) + "\r\n");
|
||||
// App.PrintToMiniProfiler("SqlSugar", "Error", $"{ex.Message}{Environment.NewLine}{ex.Sql}{pars}{Environment.NewLine}");
|
||||
// };
|
||||
//});
|
||||
});
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user