初步可用后台

This commit is contained in:
j4587698
2020-02-16 22:11:24 +08:00
parent 104cfb2463
commit c448afdd1d
37 changed files with 2278 additions and 310 deletions

View File

@@ -110,12 +110,9 @@ namespace JXCMS.Core.Db
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);
}
using var writer = new StreamWriter(filePath);
using JsonTextWriter jsonWriter = new JsonTextWriter(writer) {Formatting = Formatting.Indented};
jsonObject.WriteTo(jsonWriter);
}
}
}

View File

@@ -0,0 +1,99 @@
using Microsoft.AspNetCore.Html;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc.Infrastructure;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.IO;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Mvc.Rendering
{
public static class HtmlHelperViewExtensions
{
public static IHtmlContent Action(this IHtmlHelper helper, string action, object parameters = null)
{
var controller = (string)helper.ViewContext.RouteData.Values["controller"];
return Action(helper, action, controller, parameters);
}
public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, object parameters = null)
{
var area = (string)helper.ViewContext.RouteData.Values["area"];
return Action(helper, action, controller, area, parameters);
}
public static IHtmlContent Action(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
{
if (action == null)
throw new ArgumentNullException("action");
if (controller == null)
throw new ArgumentNullException("controller");
var task = RenderActionAsync(helper, action, controller, area, parameters);
return task.Result;
}
private static async Task<IHtmlContent> RenderActionAsync(this IHtmlHelper helper, string action, string controller, string area, object parameters = null)
{
// fetching required services for invocation
var serviceProvider = helper.ViewContext.HttpContext.RequestServices;
var actionContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IActionContextAccessor>();
var httpContextAccessor = helper.ViewContext.HttpContext.RequestServices.GetRequiredService<IHttpContextAccessor>();
var actionSelector = serviceProvider.GetRequiredService<IActionSelector>();
// creating new action invocation context
var routeData = new RouteData();
foreach (var router in helper.ViewContext.RouteData.Routers)
{
routeData.PushState(router, null, null);
}
routeData.PushState(null, new RouteValueDictionary(new { controller = controller, action = action, area = area }), null);
routeData.PushState(null, new RouteValueDictionary(parameters ?? new { }), null);
//get the actiondescriptor
RouteContext routeContext = new RouteContext(helper.ViewContext.HttpContext) { RouteData = routeData };
var candidates = actionSelector.SelectCandidates(routeContext);
var actionDescriptor = actionSelector.SelectBestCandidate(routeContext, candidates);
var originalActionContext = actionContextAccessor.ActionContext;
var originalhttpContext = httpContextAccessor.HttpContext;
try
{
var newHttpContext = serviceProvider.GetRequiredService<IHttpContextFactory>().Create(helper.ViewContext.HttpContext.Features);
if (newHttpContext.Items.ContainsKey(typeof(IUrlHelper)))
{
newHttpContext.Items.Remove(typeof(IUrlHelper));
}
newHttpContext.Response.Body = new MemoryStream();
var actionContext = new ActionContext(newHttpContext, routeData, actionDescriptor);
actionContextAccessor.ActionContext = actionContext;
var invoker = serviceProvider.GetRequiredService<IActionInvokerFactory>().CreateInvoker(actionContext);
await invoker.InvokeAsync();
newHttpContext.Response.Body.Position = 0;
using (var reader = new StreamReader(newHttpContext.Response.Body))
{
return new HtmlString(reader.ReadToEnd());
}
}
catch (Exception ex)
{
return new HtmlString(ex.Message);
}
finally
{
actionContextAccessor.ActionContext = originalActionContext;
httpContextAccessor.HttpContext = originalhttpContext;
if (helper.ViewContext.HttpContext.Items.ContainsKey(typeof(IUrlHelper)))
{
helper.ViewContext.HttpContext.Items.Remove(typeof(IUrlHelper));
}
}
}
}
}

View File

@@ -1,4 +1,6 @@
namespace JXCMS.Core.Extensions
using System.Text;
namespace JXCMS.Core.Extensions
{
public static class StringExtension
{
@@ -6,5 +8,18 @@
{
return string.IsNullOrEmpty(str);
}
public static string InsertMultipleString(this string str, string insertStr, int count)
{
StringBuilder returnValue = new StringBuilder();
for (int i = 0; i < count; i++)
{
returnValue.Append(insertStr);
}
returnValue.Append(str);
return returnValue.ToString();
}
}
}

View File

@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
@@ -11,12 +11,12 @@
<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="FreeSql.Extensions.BaseEntity" Version="1.2.0-preview1" />
<PackageReference Include="FreeSql.Provider.MySql" Version="1.2.0-preview1" />
<PackageReference Include="FreeSql.Provider.Oracle" Version="1.2.0-preview1" />
<PackageReference Include="FreeSql.Provider.PostgreSQL" Version="1.2.0-preview1" />
<PackageReference Include="FreeSql.Provider.Sqlite" Version="1.2.0-preview1" />
<PackageReference Include="FreeSql.Provider.SqlServer" Version="1.2.0-preview1" />
<PackageReference Include="McMaster.NETCore.Plugins" Version="0.3.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Quartz" Version="3.0.7" />

View File

@@ -52,6 +52,42 @@ namespace JXCMS.Core.TimingTask
{
return await _scheduler.DeleteJobs(jobKeys);
}
/// <summary>
/// Corn表达式的运行时间
/// </summary>
/// <param name="cron">表达式</param>
/// <param name="times">计算次数</param>
/// <param name="startTime">开始时间</param>
/// <returns></returns>
public static string GetCronSchedule(String cron, int times, DateTimeOffset startTime)
{
String timeSchedule = "";
if (!CronExpression.IsValidExpression(cron))
{
return "Cron表达式不合法!";
}
try
{
ITrigger trigger1 = TriggerBuilder.Create()
.WithCronSchedule(cron)
.StartNow()
.Build();
for (int i = 0; i < times; i++)
{
DateTimeOffset? s = trigger1.GetFireTimeAfter(startTime);
DateTime? time = s?.LocalDateTime;
timeSchedule = time?.ToString("F");
}
}
catch (System.Exception e)
{
timeSchedule = "未知时间";
}
return timeSchedule;
}
}
}

View File

@@ -0,0 +1,15 @@
using Microsoft.Extensions.Configuration;
namespace JXCMS.Core.Utils
{
public class ConfigHelper
{
public static IConfiguration Configs { get; set; }
public static string GetValue(string key)
{
var res = Configs.GetSection(key).Value;
return res;
}
}
}