!29 增加功能:后台任务持久化

Merge pull request !29 from Argo/dev
This commit is contained in:
Argo 2019-09-06 01:58:33 +08:00 committed by Gitee
commit 568052193e
17 changed files with 91 additions and 81 deletions

View File

@ -10,9 +10,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.15-preview-1" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.16" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Tasks" Version="1.10.0-preview-3" />
<PackageReference Include="Longbow.Tasks" Version="1.10.0" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Versioning" Version="3.1.6" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.2.3" PrivateAssets="All" />

View File

@ -62,7 +62,7 @@ namespace Bootstrap.Admin
services.AddResponseCompression();
services.AddBootstrapAdminAuthentication();
services.AddSwagger();
services.AddButtonAuthorization(MenuHelper.RetrieveAllMenus);
services.AddButtonAuthorization(MenuHelper.AuthorizateButtons);
services.AddBootstrapAdminBackgroundTask();
services.AddHttpClient<GiteeHttpClient>();
services.AddAdminHealthChecks();

View File

@ -5,7 +5,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security" Version="1.7.0" />
<PackageReference Include="Bootstrap.Security" Version="1.8.0" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="MongoDB.Driver" Version="2.9.1" />
</ItemGroup>

View File

@ -5,9 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.12" />
<PackageReference Include="Longbow.Data" Version="2.3.6" />
<PackageReference Include="Longbow.Logging" Version="2.2.12" />
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.13" />
<PackageReference Include="Longbow.Data" Version="2.3.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.13" />
<PackageReference Include="Longbow.PetaPoco" Version="1.0.2" />
<PackageReference Include="Longbow.Security.Cryptography" Version="1.3.0" />
<PackageReference Include="Longbow.Web" Version="2.2.16" />

View File

@ -64,13 +64,13 @@ namespace Bootstrap.DataAccess
/// 获取系统网站标题
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
public virtual string RetrieveWebTitle() => DbHelper.RetrieveTitle();
/// <summary>
/// 获取系统网站页脚
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebFooter() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
public virtual string RetrieveWebFooter() => DbHelper.RetrieveFooter();
/// <summary>
/// 获得系统中配置的可以使用的网站样式

View File

@ -99,13 +99,13 @@ namespace Bootstrap.DataAccess
/// 获取站点 Title 配置信息
/// </summary>
/// <returns></returns>
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>()?.RetrieveWebTitle();
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <returns></returns>
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>()?.RetrieveWebFooter();
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
/// <summary>
/// 获得系统中配置的可以使用的网站样式
@ -117,7 +117,7 @@ namespace Bootstrap.DataAccess
/// 获得网站设置中的当前样式
/// </summary>
/// <returns></returns>
public static string RetrieveActiveTheme() => DbContextManager.Create<Dict>()?.RetrieveActiveTheme();
public static string RetrieveActiveTheme() => DbContextManager.Create<Dict>().RetrieveActiveTheme();
/// <summary>
/// 获取头像路径
@ -166,7 +166,7 @@ namespace Bootstrap.DataAccess
/// 获取 IP 地址位置查询服务名称
/// </summary>
/// <returns></returns>
public static string RetrieveLocaleIPSvr() => DbContextManager.Create<Dict>()?.RetrieveLocaleIPSvr();
public static string RetrieveLocaleIPSvr() => DbContextManager.Create<Dict>().RetrieveLocaleIPSvr();
/// <summary>
/// 通过 IP 地理位置查询服务名称获得请求地址方法

View File

@ -125,5 +125,14 @@ namespace Bootstrap.DataAccess
/// <param name="userName"></param>
/// <returns></returns>
public static IEnumerable<BootstrapMenu> RetrieveAllMenus(string userName) => CacheManager.GetOrAdd($"{RetrieveMenusAll}-{userName}", key => DbContextManager.Create<Menu>()?.RetrieveAllMenus(userName), RetrieveMenusAll);
/// <summary>
/// 通过当前用户名与指定菜单路径获取此菜单下所有授权按钮集合 (userName, url, auths) => bool
/// </summary>
/// <param name="userName">当前操作用户名</param>
/// <param name="url">资源按钮所属菜单</param>
/// <param name="auths">资源授权码</param>
/// <returns></returns>
public static bool AuthorizateButtons(string userName, string url, string auths) => DbHelper.AuthorizateButtons(userName, url, auths);
}
}

View File

@ -1,5 +1,4 @@
using Bootstrap.Security;
using Longbow.Configuration;
using MongoDB.Driver;
using System.Collections.Generic;
using System.Linq;
@ -16,30 +15,5 @@ namespace Bootstrap.Client.DataAccess.MongoDB
/// </summary>
/// <returns></returns>
public override IEnumerable<BootstrapDict> RetrieveDicts() => DbManager.Dicts.Find(FilterDefinition<BootstrapDict>.Empty).ToList();
private static string RetrieveAppName(string name, string defaultValue = "未设置")
{
var dicts = DictHelper.RetrieveDicts();
var platName = dicts.FirstOrDefault(d => d.Category == "应用程序" && d.Code == ConfigurationManager.AppSettings["AppId"])?.Name;
return dicts.FirstOrDefault(d => d.Category == platName && d.Name == name)?.Code ?? $"{name}{defaultValue}";
}
/// <summary>
/// 获得系统设置地址
/// </summary>
/// <returns></returns>
public override string RetrieveSettingsUrl() => RetrieveAppName("系统设置地址");
/// <summary>
/// 获得系统个人中心地址
/// </summary>
/// <returns></returns>
public override string RetrieveProfilesUrl() => RetrieveAppName("个人中心地址");
/// <summary>
/// 获得系统通知地址地址
/// </summary>
/// <returns></returns>
public override string RetrieveNotisUrl() => RetrieveAppName("系统通知地址");
}
}

View File

@ -5,11 +5,12 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.13" />
<PackageReference Include="Longbow.Cache" Version="2.2.15" />
<PackageReference Include="Longbow.Data" Version="2.3.6" />
<PackageReference Include="Longbow.Logging" Version="2.2.12" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Data" Version="2.3.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.13" />
<PackageReference Include="Longbow.Web" Version="2.2.16" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.15-preview-1" />
</ItemGroup>
</Project>

View File

@ -16,13 +16,13 @@ namespace Bootstrap.Client.DataAccess
/// 获取系统网站标题
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebTitle() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站标题" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "后台管理系统" }).Code;
public virtual string RetrieveWebTitle(string appId) => DbHelper.RetrieveTitle(appId);
/// <summary>
/// 获取系统网站页脚
/// </summary>
/// <returns></returns>
public virtual string RetrieveWebFooter() => (DictHelper.RetrieveDicts().FirstOrDefault(d => d.Name == "网站页脚" && d.Category == "网站设置" && d.Define == 0) ?? new BootstrapDict() { Code = "2016 © 通用后台管理系统" }).Code;
public virtual string RetrieveWebFooter(string appId) => DbHelper.RetrieveFooter(appId);
/// <summary>
/// 获得网站设置中的当前样式
@ -93,18 +93,18 @@ namespace Bootstrap.Client.DataAccess
/// 获得系统设置地址
/// </summary>
/// <returns></returns>
public virtual string RetrieveSettingsUrl() => DbHelper.RetrieveSettingsUrl();
public virtual string RetrieveSettingsUrl(string appId) => DbHelper.RetrieveSettingsUrl(appId);
/// <summary>
/// 获得系统个人中心地址
/// </summary>
/// <returns></returns>
public virtual string RetrieveProfilesUrl() => DbHelper.RetrieveProfilesUrl();
public virtual string RetrieveProfilesUrl(string appId) => DbHelper.RetrieveProfilesUrl(appId);
/// <summary>
/// 获得系统通知地址地址
/// </summary>
/// <returns></returns>
public virtual string RetrieveNotisUrl() => DbHelper.RetrieveNotisUrl();
public virtual string RetrieveNotisUrl(string appId) => DbHelper.RetrieveNotisUrl(appId);
}
}

View File

@ -27,14 +27,16 @@ namespace Bootstrap.Client.DataAccess
/// <summary>
/// 获取站点 Title 配置信息
/// </summary>
/// <param name="appId">App 应用ID 默认为 0 表示后台管理程序</param>
/// <returns></returns>
public static string RetrieveWebTitle() => DbContextManager.Create<Dict>().RetrieveWebTitle();
public static string RetrieveWebTitle(string appId) => DbContextManager.Create<Dict>().RetrieveWebTitle(appId);
/// <summary>
/// 获取站点 Footer 配置信息
/// </summary>
/// <param name="appId">App 应用ID 默认为 0 表示后台管理程序</param>
/// <returns></returns>
public static string RetrieveWebFooter() => DbContextManager.Create<Dict>().RetrieveWebFooter();
public static string RetrieveWebFooter(string appId) => DbContextManager.Create<Dict>().RetrieveWebFooter(appId);
/// <summary>
/// 获得网站设置中的当前样式
@ -94,20 +96,23 @@ namespace Bootstrap.Client.DataAccess
/// <summary>
/// 获得系统设置地址
/// </summary>
/// <param name="appId">App 应用ID 默认为 0 表示后台管理程序</param>
/// <returns></returns>
public static string RetrieveSettingsUrl() => DbContextManager.Create<Dict>().RetrieveSettingsUrl();
public static string RetrieveSettingsUrl(string appId) => DbContextManager.Create<Dict>().RetrieveSettingsUrl(appId);
/// <summary>
/// 获得系统个人中心地址
/// </summary>
/// <param name="appId">App 应用ID 默认为 0 表示后台管理程序</param>
/// <returns></returns>
public static string RetrieveProfilesUrl() => DbContextManager.Create<Dict>().RetrieveProfilesUrl();
public static string RetrieveProfilesUrl(string appId) => DbContextManager.Create<Dict>().RetrieveProfilesUrl(appId);
/// <summary>
/// 获得系统通知地址地址
/// </summary>
/// <param name="appId">App 应用ID 默认为 0 表示后台管理程序</param>
/// <returns></returns>
public static string RetrieveNotisUrl() => DbContextManager.Create<Dict>().RetrieveNotisUrl();
public static string RetrieveNotisUrl(string appId) => DbContextManager.Create<Dict>().RetrieveNotisUrl(appId);
/// <summary>
/// 配置 IP 地理位置查询配置项 注入方法调用此方法

View File

@ -1,10 +1,7 @@
using Longbow.Configuration;
using Longbow.Web;
using Microsoft.AspNetCore;
using Longbow.Web;
using Microsoft.AspNetCore.Http;
using System;
using System.Collections.Specialized;
using System.Linq;
using System.Net.Http;
namespace Bootstrap.Client.DataAccess
@ -21,21 +18,7 @@ namespace Bootstrap.Client.DataAccess
/// </summary>
/// <param name="client"></param>
/// <param name="httpContextAccessor"></param>
public TraceHttpClient(HttpClient client, IHttpContextAccessor httpContextAccessor)
{
client.Timeout = TimeSpan.FromSeconds(10);
client.DefaultRequestHeaders.Connection.Add("keep-alive");
// set auth
var cookieValues = httpContextAccessor.HttpContext.Request.Cookies.Select(cookie => $"{cookie.Key}={cookie.Value}");
client.DefaultRequestHeaders.Add("Cookie", cookieValues);
var authHost = ConfigurationManager.Get<BootstrapAdminAuthenticationOptions>().AuthHost.TrimEnd(new char[] { '/' });
var url = $"{authHost}/api/Traces";
client.BaseAddress = new Uri(url);
_client = client;
}
public TraceHttpClient(HttpClient client) => _client = client;
/// <summary>
/// 提交数据到后台访问网页接口

View File

@ -5,10 +5,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Bootstrap.Security.DataAccess" Version="2.2.12" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.15-preview-1" />
<PackageReference Include="Bootstrap.Security.Mvc" Version="2.2.16" />
<PackageReference Include="Longbow.Configuration" Version="2.2.7" />
<PackageReference Include="Longbow.Logging" Version="2.2.12" />
<PackageReference Include="Longbow.Logging" Version="2.2.13" />
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="2.2.6" />
</ItemGroup>

View File

@ -0,0 +1,32 @@
using Bootstrap.Client.DataAccess;
using Longbow.Configuration;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Linq;
namespace Microsoft.AspNetCore.Builder
{
internal static class HttpClientExtensions
{
public static IServiceCollection AddBootstrapHttpClient(this IServiceCollection services)
{
services.AddHttpClient("BootstrapAdmin", client => client.DefaultRequestHeaders.Connection.Add("keep-alive"));
services.AddHttpClient<TraceHttpClient>((provider, client) =>
{
client.Timeout = TimeSpan.FromSeconds(10);
client.DefaultRequestHeaders.Connection.Add("keep-alive");
// set auth
var context = provider.GetRequiredService<IHttpContextAccessor>();
var cookieValues = context.HttpContext.Request.Cookies.Select(cookie => $"{cookie.Key}={cookie.Value}");
client.DefaultRequestHeaders.Add("Cookie", cookieValues);
var authHost = ConfigurationManager.Get<BootstrapAdminAuthenticationOptions>().AuthHost.TrimEnd(new char[] { '/' });
var url = $"{authHost}/api/Traces";
client.BaseAddress = new Uri(url);
});
return services;
}
}
}

View File

@ -21,9 +21,9 @@ namespace Bootstrap.Client.Models
var user = UserHelper.RetrieveUserByUserName(identity.Name);
DisplayName = user.DisplayName;
UserName = user.UserName;
SettingsUrl = DictHelper.RetrieveSettingsUrl();
ProfilesUrl = DictHelper.RetrieveProfilesUrl();
NotisUrl = DictHelper.RetrieveNotisUrl();
SettingsUrl = DictHelper.RetrieveSettingsUrl(AppId);
ProfilesUrl = DictHelper.RetrieveProfilesUrl(AppId);
NotisUrl = DictHelper.RetrieveNotisUrl(AppId);
// set LogoutUrl
var authHost = ConfigurationManager.Get<BootstrapAdminAuthenticationOptions>().AuthHost;

View File

@ -1,4 +1,5 @@
using Bootstrap.Client.DataAccess;
using Longbow.Configuration;
namespace Bootstrap.Client.Models
{
@ -12,11 +13,14 @@ namespace Bootstrap.Client.Models
/// </summary>
public ModelBase()
{
Title = DictHelper.RetrieveWebTitle();
Footer = DictHelper.RetrieveWebFooter();
AppId = ConfigurationManager.GetValue("AppId", "2");
Title = DictHelper.RetrieveWebTitle(AppId);
Footer = DictHelper.RetrieveWebFooter(AppId);
Theme = DictHelper.RetrieveActiveTheme();
}
public string AppId { get; private set; }
/// <summary>
/// 获取 网站标题
/// </summary>

View File

@ -1,6 +1,8 @@
using Bootstrap.Client.DataAccess;
using Longbow.Configuration;
using Longbow.Web;
using Longbow.Web.SignalR;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
@ -11,6 +13,7 @@ using Microsoft.Extensions.DependencyInjection;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using System;
using System.Linq;
namespace Bootstrap.Client
{
@ -51,10 +54,9 @@ namespace Bootstrap.Client
services.AddConfigurationManager();
services.AddCacheManager();
services.AddDbAdapter();
services.AddHttpClient("BootstrapAdmin", client => client.DefaultRequestHeaders.Connection.Add("keep-alive"));
services.AddBootstrapHttpClient();
services.AddIPLocator(DictHelper.ConfigIPLocator);
services.AddOnlineUsers();
services.AddHttpClient<TraceHttpClient>();
services.AddSignalR().AddJsonProtocalDefault();
services.AddResponseCompression();
services.AddBootstrapAdminAuthentication();