This commit is contained in:
j4587698
2020-02-09 19:10:05 +08:00
commit 358617b0c3
414 changed files with 96012 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
using System;
using System.Linq;
using System.Reflection;
using System.Security.Claims;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace JXCMS.Core.Auth
{
public static class AuthExtension
{
public static IServiceCollection AddJXAuth(this IServiceCollection services)
{
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x =>
x.GetTypes().Where(y => y.BaseType == typeof(BaseAuthorizeAttribute)));
var builder = services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme);
foreach (var type in types)
{
builder.AddCookie(type.Name.Replace("AuthorizeAttribute", ""), o =>
{
o.LoginPath = type.GetField("LoginPath", BindingFlags.Static|BindingFlags.Public).GetValue(type) as string;
o.AccessDeniedPath =
type.GetField("AccessDeniedPath", BindingFlags.Static | BindingFlags.Public).GetValue(type) as string;
});
}
return services;
}
public static async Task LoginAsync(BaseAuthorizeAttribute authorize, HttpContext httpContext, ClaimsPrincipal claims)
{
await httpContext.SignInAsync(authorize.GetScheme(), claims);
}
}
}

View File

@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Authorization;
namespace JXCMS.Core.Auth
{
public abstract class BaseAuthorizeAttribute : AuthorizeAttribute
{
public static string LoginPath = "/Admin/Login";
public static string AccessDeniedPath = "/Error/Forbidden";
public BaseAuthorizeAttribute()
{
AuthenticationSchemes = GetScheme();
}
public string GetScheme()
{
return GetType().Name.Replace("AuthorizeAttribute", "");
}
}
}

43
Core/JXCMS.Core/Db/DbConfig.cs Executable file
View File

@@ -0,0 +1,43 @@
namespace JXCMS.Core.Db
{
/// <summary>
/// 数据库配置类
/// </summary>
public class DbConfig
{
/// <summary>
/// 数据库类型目前支持sqlite,mysql,sqlserver,oracle,postgresql
/// </summary>
public string DbType { get; set; }
/// <summary>
/// 数据库URL
/// </summary>
public string DbUrl { get; set; }
/// <summary>
/// 数据库端口号
/// </summary>
public string DbPort { get; set; }
/// <summary>
/// 数据库名
/// </summary>
public string DbName { get; set; }
/// <summary>
/// 数据库用户名
/// </summary>
public string Username { get; set; }
/// <summary>
/// 数据库密码
/// </summary>
public string Password { get; set; }
/// <summary>
/// 表前缀
/// </summary>
public string Prefix { get; set; }
}
}

121
Core/JXCMS.Core/Db/DbExtension.cs Executable file
View File

@@ -0,0 +1,121 @@
using System;
using System.IO;
using System.Linq;
using FreeSql;
using JXCMS.Core.Exception;
using JXCMS.Core.Extensions;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace JXCMS.Core.Db
{
public static class DbExtension
{
public static IHostBuilder ConfigFreeDb(this IHostBuilder builder)
{
builder.ConfigureServices((context, collection) =>
{
var dbSettings = context.Configuration.GetSection("Db").Get<DbConfig>();
SetDb(dbSettings, context.HostingEnvironment.IsDevelopment());
});
return builder;
}
public static IServiceCollection AddDb(this IServiceCollection service, IConfiguration configuration, bool isDevVersion)
{
var dbSettings = configuration.GetSection("Db").Get<DbConfig>();
if (dbSettings != null)
{
var ret = SetDb(dbSettings, isDevVersion);
if (!ret.isSuccess)
{
throw new CMSException(ret.msg);
}
}
else if (File.Exists("install.lock"))
{
throw new CMSException("数据库配置错误,无数据库配置信息!");
}
return service;
}
public static (bool isSuccess, string msg) SetDb(DbConfig dbConfig, bool isDevVersion)
{
if (!dbConfig.DbType.IsNullOrEmpty() && Enum.TryParse(dbConfig.DbType, true, out DataType dataType))
{
switch (dataType)
{
case DataType.MySql:
var connStr = $"data source={dbConfig.DbName};PORT={dbConfig.DbPort};database={dbConfig.DbName}; uid={dbConfig.Username};pwd={dbConfig.Password};";
BaseEntity.Initialization(new FreeSqlBuilder()
.UseAutoSyncStructure(isDevVersion)
.UseNoneCommandParameter(true)
.UseConnectionString(dataType, connStr)
.Build());
break;
case DataType.SqlServer:
break;
case DataType.PostgreSQL:
break;
case DataType.Oracle:
break;
case DataType.Sqlite:
BaseEntity.Initialization(new FreeSqlBuilder()
.UseAutoSyncStructure(isDevVersion)
.UseNoneCommandParameter(true)
.UseConnectionString(dataType, $"data source={dbConfig.DbName}")
.Build());
break;
default:
return (false, "数据库类型不在指定范围内");
}
if (!BaseEntity.Orm.Ado.MasterPool.IsAvailable)
{
BaseEntity.Orm.Dispose();
return (false, "数据库连接失败");
}
BaseEntity.Orm.Aop.ConfigEntity = (s, e) =>
{
e.ModifyResult.Name = dbConfig.Prefix + e.EntityType.Name.Replace("Entity", "");
};
return (true, "");
}
return (false, "数据库类型不在指定范围内");;
}
public static void InstallDb(DbConfig dbConfig, Action<bool, string> syncTable = null)
{
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x =>
x.GetTypes().Where(y => y.BaseType != null && y.BaseType.IsGenericType && y.BaseType.GetGenericTypeDefinition() == typeof(BaseEntity<,>)
&& y.FullName != null && !y.FullName.Contains("FreeSql")));
foreach (var type in types)
{
var isSuccess = BaseEntity.Orm.CodeFirst.SyncStructure(type);
syncTable?.Invoke(isSuccess, type.Name);
//Console.WriteLine(type.FullName);
}
string contentPath = AppContext.BaseDirectory + @"\"; ; //項目根目錄
var filePath = contentPath + "appsettings.json";
JObject jsonObject;
using (StreamReader file = new StreamReader(filePath))
using (JsonTextReader reader = new JsonTextReader(file))
{
jsonObject = (JObject)JToken.ReadFrom(reader);
jsonObject.Add("Db", JObject.FromObject(dbConfig));
}
using (var writer = new StreamWriter(filePath))
using (JsonTextWriter jsonwriter = new JsonTextWriter(writer))
{
jsonwriter.Formatting = Formatting.Indented;
jsonObject.WriteTo(jsonwriter);
}
}
}
}

217
Core/JXCMS.Core/Encrypt/SM3.cs Executable file
View File

@@ -0,0 +1,217 @@
using System;
using System.Text;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Utilities.Encoders;
namespace JXCMS.Core.Encrypt
{
public class SM3: SM3Digest
{
public override string AlgorithmName => "SM3";
public override int GetDigestSize()
{
return DIGEST_LENGTH;
}
private const int DIGEST_LENGTH = 32;
private static readonly int[] v0 = new int[]{0x7380166f, 0x4914b2b9, 0x172442d7, unchecked((int) 0xda8a0600), unchecked((int) 0xa96f30bc), 0x163138aa, unchecked((int) 0xe38dee4d), unchecked((int) 0xb0fb0e4e)};
private int[] v = new int[8];
private int[] v_ = new int[8];
private static readonly int[] X0 = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
private int[] X = new int[68];
private int xOff;
private int T_00_15 = 0x79cc4519;
private int T_16_63 = 0x7a879d8a;
public SM3()
{
Reset();
}
public SM3(SM3 t):base(t)
{
Array.Copy(t.X, 0, X, 0, t.X.Length);
xOff = t.xOff;
Array.Copy(t.v, 0, v, 0, t.v.Length);
}
public sealed override void Reset()
{
base.Reset();
Array.Copy(v0, 0, v, 0, v0.Length);
xOff = 0;
Array.Copy(X0, 0, X, 0, X0.Length);
}
internal override void ProcessBlock()
{
int i;
int[] ww = X;
int[] ww_ = new int[64];
for (i = 16; i < 68; i++)
{
ww[i] = P1(ww[i - 16] ^ ww[i - 9] ^ (ROTATE(ww[i - 3], 15))) ^ (ROTATE(ww[i - 13], 7)) ^ ww[i - 6];
}
for (i = 0; i < 64; i++)
{
ww_[i] = ww[i] ^ ww[i + 4];
}
int[] vv = v;
int[] vv_ = v_;
Array.Copy(vv, 0, vv_, 0, v0.Length);
int SS1, SS2, TT1, TT2, aaa;
for (i = 0; i < 16; i++)
{
aaa = ROTATE(vv_[0], 12);
SS1 = aaa + vv_[4] + ROTATE(T_00_15, i);
SS1 = ROTATE(SS1, 7);
SS2 = SS1 ^ aaa;
TT1 = FF_00_15(vv_[0], vv_[1], vv_[2]) + vv_[3] + SS2 + ww_[i];
TT2 = GG_00_15(vv_[4], vv_[5], vv_[6]) + vv_[7] + SS1 + ww[i];
vv_[3] = vv_[2];
vv_[2] = ROTATE(vv_[1], 9);
vv_[1] = vv_[0];
vv_[0] = TT1;
vv_[7] = vv_[6];
vv_[6] = ROTATE(vv_[5], 19);
vv_[5] = vv_[4];
vv_[4] = P0(TT2);
}
for (i = 16; i < 64; i++)
{
aaa = ROTATE(vv_[0], 12);
SS1 = aaa + vv_[4] + ROTATE(T_16_63, i);
SS1 = ROTATE(SS1, 7);
SS2 = SS1 ^ aaa;
TT1 = FF_16_63(vv_[0], vv_[1], vv_[2]) + vv_[3] + SS2 + ww_[i];
TT2 = GG_16_63(vv_[4], vv_[5], vv_[6]) + vv_[7] + SS1 + ww[i];
vv_[3] = vv_[2];
vv_[2] = ROTATE(vv_[1], 9);
vv_[1] = vv_[0];
vv_[0] = TT1;
vv_[7] = vv_[6];
vv_[6] = ROTATE(vv_[5], 19);
vv_[5] = vv_[4];
vv_[4] = P0(TT2);
}
for (i = 0; i < 8; i++)
{
vv[i] ^= vv_[i];
}
// Reset
xOff = 0;
Array.Copy(X0, 0, X, 0, X0.Length);
}
internal override void ProcessWord(byte[] in_Renamed, int inOff)
{
int n = in_Renamed[inOff] << 24;
n |= (in_Renamed[++inOff] & 0xff) << 16;
n |= (in_Renamed[++inOff] & 0xff) << 8;
n |= (in_Renamed[++inOff] & 0xff);
X[xOff] = n;
if (++xOff == 16)
{
ProcessBlock();
}
}
internal override void ProcessLength(long bitLength)
{
if (xOff > 14)
{
ProcessBlock();
}
X[14] = (int) (SupportClass.URShift(bitLength, 32));
X[15] = (int) (bitLength & unchecked((int) 0xffffffff));
}
public static void IntToBigEndian(int n, byte[] bs, int off)
{
bs[off] = (byte) (SupportClass.URShift(n, 24));
bs[++off] = (byte) (SupportClass.URShift(n, 16));
bs[++off] = (byte) (SupportClass.URShift(n, 8));
bs[++off] = (byte) (n);
}
public override int DoFinal(byte[] out_Renamed, int outOff)
{
Finish();
for (int i = 0; i < 8; i++)
{
IntToBigEndian(v[i], out_Renamed, outOff + i * 4);
}
Reset();
return DIGEST_LENGTH;
}
private int ROTATE(int x, int n)
{
return (x << n) | (SupportClass.URShift(x, (32 - n)));
}
private int P0(int X)
{
return ((X) ^ ROTATE((X), 9) ^ ROTATE((X), 17));
}
private int P1(int X)
{
return ((X) ^ ROTATE((X), 15) ^ ROTATE((X), 23));
}
private int FF_00_15(int X, int Y, int Z)
{
return (X ^ Y ^ Z);
}
private int FF_16_63(int X, int Y, int Z)
{
return ((X & Y) | (X & Z) | (Y & Z));
}
private int GG_00_15(int X, int Y, int Z)
{
return (X ^ Y ^ Z);
}
private int GG_16_63(int X, int Y, int Z)
{
return ((X & Y) | (~ X & Z));
}
public static string GetSM3(string value)
{
byte[] md = new byte[32];
byte[] msg1 = Encoding.Default.GetBytes(value);
SM3 sm3 = new SM3();
sm3.BlockUpdate(msg1, 0, msg1.Length);
sm3.DoFinal(md, 0);
return new UTF8Encoding().GetString(Hex.Encode(md));
}
}
}

View File

@@ -0,0 +1,115 @@
using System;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Digests;
namespace JXCMS.Core.Encrypt
{
public abstract class SM3Digest: IDigest
{
private const int BYTE_LENGTH = 64;
private byte[] xBuf;
private int xBufOff;
private long byteCount;
internal SM3Digest()
{
xBuf = new byte[4];
}
internal SM3Digest(SM3Digest t)
{
xBuf = new byte[t.xBuf.Length];
Array.Copy(t.xBuf, 0, xBuf, 0, t.xBuf.Length);
xBufOff = t.xBufOff;
byteCount = t.byteCount;
}
public void Update(byte input)
{
xBuf[xBufOff++] = input;
if (xBufOff == xBuf.Length)
{
ProcessWord(xBuf, 0);
xBufOff = 0;
}
byteCount++;
}
public void BlockUpdate(
byte[] input,
int inOff,
int length)
{
//
// fill the current word
//
while ((xBufOff != 0) && (length > 0))
{
Update(input[inOff]);
inOff++;
length--;
}
//
// process whole words.
//
while (length > xBuf.Length)
{
ProcessWord(input, inOff);
inOff += xBuf.Length;
length -= xBuf.Length;
byteCount += xBuf.Length;
}
//
// load in the remainder.
//
while (length > 0)
{
Update(input[inOff]);
inOff++;
length--;
}
}
public void Finish()
{
long bitLength = (byteCount << 3);
//
// add the pad bytes.
//
Update((byte)128);
while (xBufOff != 0) Update((byte)0);
ProcessLength(bitLength);
ProcessBlock();
}
public virtual void Reset()
{
byteCount = 0;
xBufOff = 0;
Array.Clear(xBuf, 0, xBuf.Length);
}
public int GetByteLength()
{
return BYTE_LENGTH;
}
internal abstract void ProcessWord(byte[] input, int inOff);
internal abstract void ProcessLength(long bitLength);
internal abstract void ProcessBlock();
public abstract string AlgorithmName { get; }
public abstract int GetDigestSize();
public abstract int DoFinal(byte[] output, int outOff);
}
}

View File

@@ -0,0 +1,55 @@
namespace JXCMS.Core.Encrypt
{
public class SupportClass
{
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
///<param name="number">Number to operate on
///<param name="bits">Ammount of bits to shift
/// <returns>The resulting number from the shift operation</returns>
public static int URShift(int number, int bits)
{
if (number >= 0)
return number >> bits;
else
return (number >> bits) + (2 << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
///<param name="number">Number to operate on
///<param name="bits">Ammount of bits to shift
/// <returns>The resulting number from the shift operation</returns>
public static int URShift(int number, long bits)
{
return URShift(number, (int)bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
///<param name="number">Number to operate on
///<param name="bits">Ammount of bits to shift
/// <returns>The resulting number from the shift operation</returns>
public static long URShift(long number, int bits)
{
if (number >= 0)
return number >> bits;
else
return (number >> bits) + (2L << ~bits);
}
/// <summary>
/// Performs an unsigned bitwise right shift with the specified number
/// </summary>
///<param name="number">Number to operate on
///<param name="bits">Ammount of bits to shift
/// <returns>The resulting number from the shift operation</returns>
public static long URShift(long number, long bits)
{
return URShift(number, (int)bits);
}
}
}

View File

@@ -0,0 +1,11 @@
using System;
namespace JXCMS.Core.Exception
{
public class CMSException : System.Exception
{
public CMSException() : base() { }
public CMSException(string message) : base(message) { }
}
}

View File

@@ -0,0 +1,10 @@
namespace JXCMS.Core.Extensions
{
public static class StringExtension
{
public static bool IsNullOrEmpty(this string str)
{
return string.IsNullOrEmpty(str);
}
}
}

View File

@@ -0,0 +1,10 @@
namespace Microsoft.AspNetCore.Mvc
{
public static class UrlExtensions
{
public static string ContentAdmin(this IUrlHelper url, string path)
{
return url.Content("~/Admin/Content/" + path);
}
}
}

View File

@@ -0,0 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<ApplicationIcon />
<OutputType>Library</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BouncyCastle" Version="1.8.5" />
<PackageReference Include="DeviceDetector.NET" Version="4.1.0" />
<PackageReference Include="DotnetSpider" Version="4.0.7" />
<PackageReference Include="FreeSql.Extensions.BaseEntity" Version="0.11.20" />
<PackageReference Include="FreeSql.Provider.MySql" Version="0.11.20" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="0.11.20" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="0.11.20" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="0.11.20" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="0.11.20" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="0.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Serilog.AspNetCore" Version="3.2.0" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.2-dev-00824" />
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
<PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.1-dev-00771" />
</ItemGroup>
<ItemGroup>
<Folder Include="Log\" />
</ItemGroup>
<ItemGroup>
</ItemGroup>
</Project>

View File

@@ -0,0 +1,28 @@
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
namespace JXCMS.Core
{
public class JXCMSMiddleware
{
private readonly RequestDelegate _next;
private readonly string _installPath;
public JXCMSMiddleware(RequestDelegate next, string installPath)
{
_next = next;
_installPath = installPath;
}
public Task Invoke(HttpContext context)
{
if (!File.Exists("install.lock") && !context.Request.Path.Value.Contains(_installPath))
{
context.Response.Redirect(
$"{context.Request.Scheme}://{context.Request.Host}{_installPath}");
}
return _next(context);
}
}
}

View File

@@ -0,0 +1,18 @@
using Microsoft.AspNetCore.Builder;
namespace JXCMS.Core
{
public static class JXCMSMiddlewareExtensions
{
/// <summary>
/// 使用JXCMS中间件的扩展方法初始化数据库提供安装等
/// </summary>
/// <param name="builder"></param>
/// <param name="installPath">安装路径(第一次打开时使用)</param>
/// <returns></returns>
public static IApplicationBuilder UseJXCMS(this IApplicationBuilder builder, string installPath)
{
return builder.UseMiddleware<JXCMSMiddleware>(installPath);
}
}
}

View File

@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.IO;
using McMaster.NETCore.Plugins;
namespace JXCMS.Core.Plugin
{
public class Plugin
{
private static readonly Dictionary<string, PluginLoader> Loaders = new Dictionary<string, PluginLoader>();
public static PluginLoader GetOrLoadPlugin(string path, params Type[] types)
{
if (Loaders.ContainsKey(path))
{
return Loaders[path];
}
if (File.Exists(path) && Path.GetExtension(path).ToLower() == ".dll")
{
var loader = PluginLoader.CreateFromAssemblyFile(path, true, types);
Loaders.Add(path, loader);
return loader;
}
return null;
}
}
}

View File

@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:51237/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"JXCMS.Core": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:51239/"
}
}
}

View File

@@ -0,0 +1,10 @@
namespace JXCMS.Core.Spider
{
public class SpiderMain
{
public static void StartSpider()
{
}
}
}

View File

@@ -0,0 +1,77 @@
using System.Collections.Generic;
using System.Linq;
using DeviceDetectorNET.Parser.Device;
using JXCMS.Core.Extensions;
using Microsoft.AspNetCore.Mvc.Razor;
namespace JXCMS.Core.Themes
{
public class TemplateViewLocationExpander : IViewLocationExpander
{
/// <summary>
/// PC主题不切换主题与自适应主题同样使用此主题
/// </summary>
public static string PcThemeName = "Default";
/// <summary>
/// 手机版主题
/// </summary>
public static string MobileThemeName = "Mobile";
/// <summary>
/// 主题切换方式,默认为不切换
/// </summary>
public static ThemeChangeMode Mode { get; set; } = ThemeChangeMode.None;
/// <summary>
/// 手机版域名
/// </summary>
public static string MobileDomain;
public IEnumerable<string> ExpandViewLocations(ViewLocationExpanderContext context, IEnumerable<string> viewLocations)
{
if (!context.AreaName.IsNullOrEmpty())
{
return viewLocations;
}
var themeName = context.Values["template"] ?? PcThemeName;
string[] locations = { "/Views/" + themeName + "/{1}/{0}.cshtml", "/Views/" + themeName + "/{0}.cshtml", "/Views/" + themeName + "/Shared/{0}.cshtml", "/Views/Shared/{0}.cshtml" };
return locations.Union(viewLocations.Where(x => !x.StartsWith("/Views/")));
}
public void PopulateValues(ViewLocationExpanderContext context)
{
switch (Mode)
{
case ThemeChangeMode.None:
case ThemeChangeMode.Adaptive:
context.Values["template"] = PcThemeName;
break;
case ThemeChangeMode.Auto:
MobileParser mobileParser = new MobileParser();
mobileParser.SetUserAgent(context.ActionContext.HttpContext.Request.Headers["User-Agent"]);
var result = mobileParser.Parse();
if ( result.Success)
{
context.Values["template"] = MobileThemeName;
}
else
{
context.Values["template"] = PcThemeName;
}
break;
case ThemeChangeMode.Domain:
if (context.ActionContext.HttpContext.Request.Host.Host == MobileDomain)
{
context.Values["template"] = MobileThemeName;
}
else
{
context.Values["template"] = PcThemeName;
}
break;
}
}
}
}

View File

@@ -0,0 +1,25 @@
namespace JXCMS.Core.Themes
{
/// <summary>
/// 切换主题方式
/// </summary>
public enum ThemeChangeMode
{
/// <summary>
/// 不切换
/// </summary>
None,
/// <summary>
/// 自适应
/// </summary>
Adaptive,
/// <summary>
/// 自动切换主题
/// </summary>
Auto,
/// <summary>
/// 根据域名切换主题
/// </summary>
Domain
}
}

View File

@@ -0,0 +1,15 @@
namespace JXCMS.Core.Themes
{
public class ThemeConfig
{
public string ThemeName { get; set; }
public string FolderName { get; set; }
public string ScreenShot { get; set; }
public int ThemeType { get; set; }
public bool IsUsing { get; set; }
}
}

View File

@@ -0,0 +1,70 @@
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace JXCMS.Core.Themes
{
public static class ThemeUtil
{
/// <summary>
/// PC主题
/// </summary>
public const int PcTheme = 1;
/// <summary>
/// 手机主题
/// </summary>
public const int MobileTheme = 2;
/// <summary>
/// 自适应主题
/// </summary>
public const int AdaptiveTheme = 3;
/// <summary>
/// PC主题字段名称
/// </summary>
public const string PcThemeName = "PcTheme";
/// <summary>
/// 移动主题字段名称
/// </summary>
public const string MobileThemeName = "MobileTheme";
public static List<ThemeConfig> ListThemes(string basePath)
{
var themes = Directory.GetDirectories(basePath);
List<ThemeConfig> themeConfigs = new List<ThemeConfig>();
foreach (var theme in themes)
{
var configPath = Path.Combine(theme, "theme.json");
if (File.Exists(configPath))
{
var themeConfig = JsonConvert.DeserializeObject<ThemeConfig>(File.ReadAllText(configPath));
themeConfig.FolderName = Path.GetFileName(theme);
if (themeConfig.ThemeType == MobileTheme)
{
if (TemplateViewLocationExpander.Mode == ThemeChangeMode.Domain || TemplateViewLocationExpander.Mode == ThemeChangeMode.Auto)
{
themeConfigs.Add(themeConfig);
}
}
else
{
themeConfigs.Add(themeConfig);
}
if (themeConfig.FolderName == TemplateViewLocationExpander.PcThemeName)
{
themeConfig.IsUsing = true;
}
else if (themeConfig.FolderName == TemplateViewLocationExpander.MobileThemeName)
{
themeConfig.IsUsing = true;
}
}
}
return themeConfigs;
}
}
}

View File

@@ -0,0 +1,15 @@
namespace JXCMSFramework
{
public interface IPluginInfo
{
string PluginName { get; set; }
string Author { get; set; }
string Version { get; set; }
int BuilderNumber { get; set; }
string Description { get; set; }
}
}

View File

@@ -0,0 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
</PropertyGroup>
</Project>