mirror of
http://git.coreshop.cn/jianweie/coreshoppro.git
synced 2025-12-06 18:43:26 +08:00
添加项目文件。
This commit is contained in:
56
CoreCms.Net.Core/Config/CorsSetup.cs
Normal file
56
CoreCms.Net.Core/Config/CorsSetup.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-03 22:49:41
|
||||
* NameSpace: CoreCms.Net.Framework
|
||||
* FileName: Cors
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 配置跨域(CORS)
|
||||
/// </summary>
|
||||
public static class CorsSetup
|
||||
{
|
||||
public static void AddCorsSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
services.AddCors(c =>
|
||||
{
|
||||
if (!AppSettingsConstVars.CorsEnableAllIPs)
|
||||
{
|
||||
c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy =>
|
||||
{
|
||||
policy.WithOrigins(AppSettingsConstVars.CorsIPs.Split(','));
|
||||
policy.AllowAnyHeader();//Ensures that the policy allows any header.
|
||||
policy.AllowAnyMethod();
|
||||
policy.AllowCredentials();
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
//允许任意跨域请求
|
||||
c.AddPolicy(AppSettingsConstVars.CorsPolicyName, policy =>
|
||||
{
|
||||
policy.SetIsOriginAllowed((host) => true)
|
||||
.AllowAnyMethod()
|
||||
.AllowAnyHeader()
|
||||
.AllowCredentials();
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
73
CoreCms.Net.Core/Config/HangFireSetup.cs
Normal file
73
CoreCms.Net.Core/Config/HangFireSetup.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-03 22:49:41
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Transactions;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using Hangfire;
|
||||
using Hangfire.MySql;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 增加HangFire到单独配置
|
||||
/// </summary>
|
||||
public static class HangFireSetup
|
||||
{
|
||||
public static void AddHangFireSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
//注册Hangfire定时任务
|
||||
var isEnabledRedis = AppSettingsConstVars.RedisUseTimedTask;
|
||||
if (isEnabledRedis)
|
||||
{
|
||||
services.AddHangfire(x => x.UseRedisStorage(AppSettingsConstVars.RedisConfigConnectionString));
|
||||
}
|
||||
else
|
||||
{
|
||||
string dbTypeString = AppSettingsConstVars.DbDbType;
|
||||
if (dbTypeString == DbType.MySql.ToString())
|
||||
{
|
||||
services.AddHangfire(x => x.UseStorage(new MySqlStorage(AppSettingsConstVars.DbSqlConnection, new MySqlStorageOptions
|
||||
{
|
||||
TransactionIsolationLevel = IsolationLevel.ReadCommitted, // 事务隔离级别。默认是读取已提交。
|
||||
QueuePollInterval = TimeSpan.FromSeconds(15), //- 作业队列轮询间隔。默认值为15秒。
|
||||
JobExpirationCheckInterval = TimeSpan.FromHours(1), //- 作业到期检查间隔(管理过期记录)。默认值为1小时。
|
||||
CountersAggregateInterval = TimeSpan.FromMinutes(5), //- 聚合计数器的间隔。默认为5分钟。
|
||||
PrepareSchemaIfNecessary = true, //- 如果设置为true,则创建数据库表。默认是true。
|
||||
DashboardJobListLimit = 50000, //- 仪表板作业列表限制。默认值为50000。
|
||||
TransactionTimeout = TimeSpan.FromMinutes(1), //- 交易超时。默认为1分钟。
|
||||
TablesPrefix = "Hangfire" //- 数据库中表的前缀。默认为none
|
||||
})));
|
||||
}
|
||||
else if (dbTypeString == DbType.SqlServer.ToString())
|
||||
{
|
||||
services.AddHangfire(x => x.UseSqlServerStorage(AppSettingsConstVars.DbSqlConnection));
|
||||
}
|
||||
}
|
||||
|
||||
services.AddHangfireServer(options =>
|
||||
{
|
||||
options.Queues = new[] { GlobalEnumVars.HangFireQueuesConfig.@default.ToString(), GlobalEnumVars.HangFireQueuesConfig.apis.ToString(), GlobalEnumVars.HangFireQueuesConfig.web.ToString(), GlobalEnumVars.HangFireQueuesConfig.recurring.ToString() };
|
||||
options.ServerTimeout = TimeSpan.FromMinutes(4);
|
||||
options.SchedulePollingInterval = TimeSpan.FromSeconds(15);//秒级任务需要配置短点,一般任务可以配置默认时间,默认15秒
|
||||
options.ShutdownTimeout = TimeSpan.FromMinutes(30); //超时时间
|
||||
options.WorkerCount = Math.Max(Environment.ProcessorCount, 20); //工作线程数,当前允许的最大线程,默认20
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
29
CoreCms.Net.Core/Config/MemoryCacheSetup.cs
Normal file
29
CoreCms.Net.Core/Config/MemoryCacheSetup.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AutoMate.MemoryCache;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// Memory缓存 启动服务
|
||||
/// </summary>
|
||||
public static class MemoryCacheSetup
|
||||
{
|
||||
public static void AddMemoryCacheSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
services.AddScoped<ICachingProvider, MemoryCaching>();
|
||||
services.AddSingleton<IMemoryCache>(factory =>
|
||||
{
|
||||
var cache = new MemoryCache(new MemoryCacheOptions());
|
||||
return cache;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
39
CoreCms.Net.Core/Config/RedisCacheSetup.cs
Normal file
39
CoreCms.Net.Core/Config/RedisCacheSetup.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Caching.AutoMate.RedisCache;
|
||||
using CoreCms.Net.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using StackExchange.Redis;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// Redis缓存 启动服务
|
||||
/// </summary>
|
||||
public static class RedisCacheSetup
|
||||
{
|
||||
public static void AddRedisCacheSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
services.AddTransient<IRedisOperationRepository, RedisOperationRepository>();
|
||||
|
||||
// 配置启动Redis服务,虽然可能影响项目启动速度,但是不能在运行的时候报错,所以是合理的
|
||||
services.AddSingleton<ConnectionMultiplexer>(sp =>
|
||||
{
|
||||
//获取连接字符串
|
||||
string redisConfiguration = AppSettingsConstVars.RedisConfigConnectionString;
|
||||
|
||||
var configuration = ConfigurationOptions.Parse(redisConfiguration, true);
|
||||
|
||||
configuration.ResolveDns = true;
|
||||
|
||||
return ConnectionMultiplexer.Connect(configuration);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
48
CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs
Normal file
48
CoreCms.Net.Core/Config/RedisMessageQueueSetup.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.RedisMQ.Subscribe;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using InitQ;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// Redis 消息队列 启动服务
|
||||
/// </summary>
|
||||
public static class RedisMessageQueueSetup
|
||||
{
|
||||
public static void AddRedisMessageQueueSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
services.AddInitQ(m =>
|
||||
{
|
||||
//时间间隔
|
||||
m.SuspendTime = 1000;
|
||||
//redis服务器地址
|
||||
m.ConnectionString = AppSettingsConstVars.RedisConfigConnectionString;
|
||||
//对应的订阅者类,需要new一个实例对象,当然你也可以传参,比如日志对象
|
||||
m.ListSubscribe = new List<Type>() {
|
||||
typeof(OrderAgentOrDistributionSubscribe),
|
||||
typeof(OrderAutomaticDeliverySubscribe),
|
||||
typeof(OrderFinishCommandSubscribe),
|
||||
typeof(OrderPrintSubscribe),
|
||||
|
||||
typeof(LogingSubscribe),
|
||||
|
||||
typeof(UserSubscribe),
|
||||
typeof(WeChatPayNoticeSubscribe),
|
||||
typeof(SendWxTemplateMessageSubscribe),
|
||||
typeof(AfterSalesReviewSubscribe),
|
||||
};
|
||||
//显示日志
|
||||
m.ShowLog = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
95
CoreCms.Net.Core/Config/SqlSugarSetup.cs
Normal file
95
CoreCms.Net.Core/Config/SqlSugarSetup.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-03 22:45:34
|
||||
* FileName: SqlSugarSetup
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using CoreCms.Net.Caching.SqlSugar;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.Loging;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using SqlSugar;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// SqlSugar 启动服务
|
||||
/// </summary>
|
||||
public static class SqlSugarSetup
|
||||
{
|
||||
public static void AddSqlSugarSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
string connectionString = AppSettingsConstVars.DbSqlConnection;
|
||||
string dbTypeString = AppSettingsConstVars.DbDbType;
|
||||
|
||||
//获取数据类型
|
||||
var dbType = dbTypeString == DbType.MySql.ToString() ? DbType.MySql : DbType.SqlServer;
|
||||
//判断是否开启redis设置二级缓存方式
|
||||
ICacheService myCache = AppSettingsConstVars.RedisUseCache
|
||||
? (ICacheService)new SqlSugarRedisCache()
|
||||
: new SqlSugarMemoryCache();
|
||||
|
||||
var connectionConfig = new ConnectionConfig()
|
||||
{
|
||||
ConnectionString = connectionString, //必填
|
||||
DbType = dbType, //必填
|
||||
IsAutoCloseConnection = false,
|
||||
InitKeyType = InitKeyType.Attribute,
|
||||
|
||||
ConfigureExternalServices = new ConfigureExternalServices()
|
||||
{
|
||||
DataInfoCacheService = myCache
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
services.AddScoped<ISqlSugarClient>(o =>
|
||||
{
|
||||
|
||||
var db = new SqlSugarClient(connectionConfig); //默认SystemTable
|
||||
|
||||
//日志处理
|
||||
////SQL执行前 可以修改SQL
|
||||
//db.Aop.OnLogExecuting = (sql, pars) =>
|
||||
//{
|
||||
// //获取sql
|
||||
// Console.WriteLine(sql + "\r\n" + db.Utilities.SerializeObject(pars.ToDictionary(it => it.ParameterName, it => it.Value)));
|
||||
// Console.WriteLine();
|
||||
|
||||
// //通过TempItems这个变量来算出这个SQL执行时间(1)
|
||||
// if (db.TempItems == null) db.TempItems = new Dictionary<string, object>();
|
||||
// db.TempItems.Add("logTime", DateTime.Now);
|
||||
// //通过TempItems这个变量来算出这个SQL执行时间(2)
|
||||
// var startingTime = db.TempItems["logTime"];
|
||||
// db.TempItems.Remove("time");
|
||||
// var completedTime = DateTime.Now;
|
||||
|
||||
|
||||
//};
|
||||
//db.Aop.OnLogExecuted = (sql, pars) => //SQL执行完事件
|
||||
//{
|
||||
|
||||
//};
|
||||
//db.Aop.OnLogExecuting = (sql, pars) => //SQL执行前事件
|
||||
//{
|
||||
|
||||
//};
|
||||
db.Aop.OnError = (exp) =>//执行SQL 错误事件
|
||||
{
|
||||
NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Other, "SqlSugar", "执行SQL错误事件", exp);
|
||||
};
|
||||
return db;
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
132
CoreCms.Net.Core/Config/SwaggerSetup.cs
Normal file
132
CoreCms.Net.Core/Config/SwaggerSetup.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
/***********************************************************************
|
||||
* Project: CoreCms.Net *
|
||||
* Web: https://CoreCms.Net *
|
||||
* ProjectName: 核心内容管理系统 *
|
||||
* Author: 大灰灰 *
|
||||
* Email: JianWeie@163.com *
|
||||
* Versions: 1.0 *
|
||||
* CreateTime: 2020-02-02 18:41:38
|
||||
* FileName: SwaggerSetup
|
||||
* ClassDescription:
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using CoreCms.Net.Loging;
|
||||
using CoreCms.Net.Swagger;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.Filters;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
public static class SwaggerSetup
|
||||
{
|
||||
|
||||
public static void AddAdminSwaggerSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
var apiName = "核心商城系统管理端";
|
||||
|
||||
services.AddSwaggerGen((s) =>
|
||||
{
|
||||
//遍历出全部的版本,做文档信息展示
|
||||
typeof(CustomApiVersion.ApiVersions).GetEnumNames().ToList().ForEach(version =>
|
||||
{
|
||||
s.SwaggerDoc(version, new OpenApiInfo
|
||||
{
|
||||
Version = version,
|
||||
Title = $"{apiName} 接口文档",
|
||||
Description = $"{apiName} HTTP API " + version,
|
||||
Contact = new OpenApiContact { Name = apiName, Email = "JianWeie@163.com", Url = new Uri("https://CoreCms.Net") },
|
||||
});
|
||||
s.OrderActionsBy(o => o.RelativePath);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
//生成API XML文档
|
||||
var basePath = AppContext.BaseDirectory;
|
||||
var xmlPath = Path.Combine(basePath, "doc.xml");
|
||||
s.IncludeXmlComments(xmlPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Swagger, "Swagger", "Swagger生成失败,Doc.xml丢失,请检查并拷贝。", ex);
|
||||
}
|
||||
|
||||
// 开启加权小锁
|
||||
s.OperationFilter<AddResponseHeadersFilter>();
|
||||
s.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
|
||||
|
||||
// 在header中添加token,传递到后台
|
||||
s.OperationFilter<SecurityRequirementsOperationFilter>();
|
||||
|
||||
// 必须是 oauth2
|
||||
s.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)\"",
|
||||
Name = "Authorization",//jwt默认的参数名称
|
||||
In = ParameterLocation.Header,//jwt默认存放Authorization信息的位置(请求头中)
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
public static void AddClientSwaggerSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
var apiName = "核心商城系统接口端";
|
||||
|
||||
services.AddSwaggerGen((s) =>
|
||||
{
|
||||
//遍历出全部的版本,做文档信息展示
|
||||
typeof(CustomApiVersion.ApiVersions).GetEnumNames().ToList().ForEach(version =>
|
||||
{
|
||||
s.SwaggerDoc(version, new OpenApiInfo
|
||||
{
|
||||
Version = version,
|
||||
Title = $"{apiName} 接口文档",
|
||||
Description = $"{apiName} HTTP API " + version,
|
||||
Contact = new OpenApiContact { Name = apiName, Email = "JianWeie@163.com", Url = new Uri("https://CoreCms.Net") },
|
||||
});
|
||||
s.OrderActionsBy(o => o.RelativePath);
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
//生成API XML文档
|
||||
var basePath = AppContext.BaseDirectory;
|
||||
var xmlPath = Path.Combine(basePath, "doc.xml");
|
||||
s.IncludeXmlComments(xmlPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
NLogUtil.WriteFileLog(NLog.LogLevel.Error, LogType.Swagger, "Swagger", "Swagger生成失败,Doc.xml丢失,请检查并拷贝。", ex);
|
||||
}
|
||||
|
||||
// 开启加权小锁
|
||||
s.OperationFilter<AddResponseHeadersFilter>();
|
||||
s.OperationFilter<AppendAuthorizeToSummaryOperationFilter>();
|
||||
|
||||
// 在header中添加token,传递到后台
|
||||
s.OperationFilter<SecurityRequirementsOperationFilter>();
|
||||
|
||||
// 必须是 oauth2
|
||||
s.AddSecurityDefinition("oauth2", new OpenApiSecurityScheme
|
||||
{
|
||||
Description = "JWT授权(数据将在请求头中进行传输) 直接在下框中输入Bearer {token}(注意两者之间是一个空格)\"",
|
||||
Name = "Authorization",//jwt默认的参数名称
|
||||
In = ParameterLocation.Header,//jwt默认存放Authorization信息的位置(请求头中)
|
||||
Type = SecuritySchemeType.ApiKey
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
34
CoreCms.Net.Core/Config/YiLianYunSetup.cs
Normal file
34
CoreCms.Net.Core/Config/YiLianYunSetup.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using CoreCms.Net.Configuration;
|
||||
using CoreCms.Net.RedisMQ.Subscribe;
|
||||
using CoreCms.Net.Utility.Extensions;
|
||||
using InitQ;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Qc.YilianyunSdk;
|
||||
|
||||
namespace CoreCms.Net.Core.Config
|
||||
{
|
||||
/// <summary>
|
||||
/// 易联云打印机 启动服务
|
||||
/// </summary>
|
||||
public static class YiLianYunSetup
|
||||
{
|
||||
public static void AddYiLianYunSetup(this IServiceCollection services)
|
||||
{
|
||||
if (services == null) throw new ArgumentNullException(nameof(services));
|
||||
|
||||
services.AddYilianyunSdk<DefaultYilianyunSdkHook>(opt =>
|
||||
{
|
||||
// 应用ID请自行前往 dev.10ss.net 获取
|
||||
opt.ClientId = AppSettingsConstVars.YiLianYunConfigClientId;
|
||||
opt.ClientSecret = AppSettingsConstVars.YiLianYunConfigClientSecret;
|
||||
opt.YilianyunClientType = YilianyunClientType.自有应用;
|
||||
opt.SaveTokenDirPath = "./App_Data/YiLianYunLogs";
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user