Skip to content

Commit

Permalink
增加Theme相关模块(未完成)
Browse files Browse the repository at this point in the history
  • Loading branch information
china-live committed Jan 9, 2018
1 parent 570c566 commit 98c3870
Show file tree
Hide file tree
Showing 27 changed files with 367 additions and 46 deletions.
28 changes: 0 additions & 28 deletions .vscode/launch.json

This file was deleted.

15 changes: 0 additions & 15 deletions .vscode/tasks.json

This file was deleted.

33 changes: 32 additions & 1 deletion XCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,17 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XCore.Migrator", "src\Dome.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XCore.Metronic", "src\XCore.Modules\XCore.Metronic\XCore.Metronic.csproj", "{8CE8CEF6-7ECF-4E40-9CCE-23B577B2C447}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XCore.DisplayManagement", "src\XCore\XCore.DisplayManagement\XCore.DisplayManagement.csproj", "{F302CD43-E3DB-4A66-8989-9A8BF8541F82}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XCore.DisplayManagement", "src\XCore\XCore.DisplayManagement\XCore.DisplayManagement.csproj", "{F302CD43-E3DB-4A66-8989-9A8BF8541F82}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XCore.Theme.Targets", "src\XCore\XCore.Theme.Targets\XCore.Theme.Targets.csproj", "{1A1D9EE2-6F22-457E-BA1C-7638B5927032}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "XCore.Themes", "XCore.Themes", "{7D799595-B8DD-4266-A6D3-677E2A3A2605}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TheAdmin", "src\XCore.Themes\TheAdmin\TheAdmin.csproj", "{D170BD67-0939-4C3D-B8A8-881A2C98E1B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XCore.Admin.Abstractions", "src\XCore\XCore.Admin.Abstractions\XCore.Admin.Abstractions.csproj", "{E4CB598A-CB02-4FCB-957A-D9F8CF702036}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XCore.Admin", "src\XCore.Modules\XCore.Admin\XCore.Admin.csproj", "{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down Expand Up @@ -311,6 +321,22 @@ Global
{F302CD43-E3DB-4A66-8989-9A8BF8541F82}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F302CD43-E3DB-4A66-8989-9A8BF8541F82}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F302CD43-E3DB-4A66-8989-9A8BF8541F82}.Release|Any CPU.Build.0 = Release|Any CPU
{1A1D9EE2-6F22-457E-BA1C-7638B5927032}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1A1D9EE2-6F22-457E-BA1C-7638B5927032}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1A1D9EE2-6F22-457E-BA1C-7638B5927032}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1A1D9EE2-6F22-457E-BA1C-7638B5927032}.Release|Any CPU.Build.0 = Release|Any CPU
{D170BD67-0939-4C3D-B8A8-881A2C98E1B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D170BD67-0939-4C3D-B8A8-881A2C98E1B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D170BD67-0939-4C3D-B8A8-881A2C98E1B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D170BD67-0939-4C3D-B8A8-881A2C98E1B8}.Release|Any CPU.Build.0 = Release|Any CPU
{E4CB598A-CB02-4FCB-957A-D9F8CF702036}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E4CB598A-CB02-4FCB-957A-D9F8CF702036}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E4CB598A-CB02-4FCB-957A-D9F8CF702036}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E4CB598A-CB02-4FCB-957A-D9F8CF702036}.Release|Any CPU.Build.0 = Release|Any CPU
{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -371,6 +397,11 @@ Global
{C6C108B9-8493-4BA0-B420-4ED180EB149D} = {0A9C407F-0BEF-4177-BFBE-C2B9CB3DC8FF}
{8CE8CEF6-7ECF-4E40-9CCE-23B577B2C447} = {CA55674E-52DD-472C-B8AD-2611D2EC47AC}
{F302CD43-E3DB-4A66-8989-9A8BF8541F82} = {4C6A1CEE-EE77-44EB-B374-43D6D27BF6A4}
{1A1D9EE2-6F22-457E-BA1C-7638B5927032} = {55076957-E554-4451-9DA9-34766675EE8C}
{7D799595-B8DD-4266-A6D3-677E2A3A2605} = {A22A02E7-92B0-4C0A-8576-2B4A2F064952}
{D170BD67-0939-4C3D-B8A8-881A2C98E1B8} = {7D799595-B8DD-4266-A6D3-677E2A3A2605}
{E4CB598A-CB02-4FCB-957A-D9F8CF702036} = {4C6A1CEE-EE77-44EB-B374-43D6D27BF6A4}
{6EDA26CE-F5CC-4D10-9605-2FBD7BD22CC5} = {CA55674E-52DD-472C-B8AD-2611D2EC47AC}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {898A87EC-3DDA-4ED8-92A9-C78FE4A09796}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

namespace XCore.Mvc.Admin.Controllers
{

public class HomeController : Controller
{
private readonly UserManager<User> userManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
using System;
using System.Collections.Generic;
using System.Text;
using XCore.Admin;

namespace XCore.Mvc.HelloWorld.Controllers
{
[Admin]
public class HomeController : Controller
{
public IActionResult Index()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@

<ItemGroup>
<ProjectReference Include="..\..\..\src\XCore\XCore.Module.Targets\XCore.Module.Targets.csproj" />
<ProjectReference Include="..\..\XCore.Modules\XCore.Admin\XCore.Admin.csproj" />
<ProjectReference Include="..\..\XCore.Modules\XCore.Mvc\XCore.Mvc.csproj" />
<ProjectReference Include="..\..\XCore.Themes\TheAdmin\TheAdmin.csproj" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/Dome/XCore.Mvc.Web/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Text.Encodings.Web;
using XCore.Logging;
using XCore.Modules.Extensions;
using XCore.Environment.Extensions.Manifests;
using XCore.Environment.Extensions;

namespace XCore.Mvc.Web
{
Expand Down Expand Up @@ -34,6 +36,10 @@ public void ConfigureServices(IServiceCollection services)
services.AddDistributedMemoryCache();
services.AddSession();

//services.AddThemingHost();
services.AddManifestDefinition("Theme.txt", "theme");
services.AddExtensionLocation("Themes");

services.AddModules(configure =>
{
configure.WithConfiguration(Configuration);
Expand Down
1 change: 1 addition & 0 deletions src/Dome/XCore.Mvc.Web/XCore.Mvc.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<ProjectReference Include="..\..\Dome.Modules\XCore.Mvc.HelloWorld\XCore.Mvc.HelloWorld.csproj" />
<ProjectReference Include="..\..\Dome.Modules\XCore.Mvc.Test\XCore.Mvc.Test.csproj" />
<ProjectReference Include="..\..\XCore.Modules\XCore.Metronic\XCore.Metronic.csproj" />
<ProjectReference Include="..\..\XCore.Themes\TheAdmin\TheAdmin.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Application.Mvc.Targets\XCore.Application.Mvc.Targets.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Logging.NLog\XCore.Logging.NLog.csproj" />
</ItemGroup>
Expand Down
48 changes: 48 additions & 0 deletions src/XCore.Modules/XCore.Admin/AdminThemeSelector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using Microsoft.AspNetCore.Http;
using XCore.DisplayManagement.Theming;
using System;
using System.Threading.Tasks;

namespace XCore.Admin
{
/// <summary>
/// Provides the theme defined in the site configuration for the current scope (request).
/// The same <see cref="ThemeSelectorResult"/> is returned if called multiple times
/// during the same scope.
/// </summary>
public class AdminThemeSelector : IThemeSelector
{
private readonly IAdminThemeService _adminThemeService;
private readonly IHttpContextAccessor _httpContextAccessor;

public AdminThemeSelector(
IAdminThemeService adminThemeService,
IHttpContextAccessor httpContextAccessor
)
{
_adminThemeService = adminThemeService;
_httpContextAccessor = httpContextAccessor;
}

public async Task<ThemeSelectorResult> GetThemeAsync()
{
if (AdminAttribute.IsApplied(_httpContextAccessor.HttpContext))
{
string adminThemeName = "TheAdmin";//await _adminThemeService.GetAdminThemeNameAsync();
if (String.IsNullOrEmpty(adminThemeName))
{
return null;
}

return new ThemeSelectorResult
{
Priority = 100,
ThemeName = adminThemeName
};
}
await Task.Run(()=> { });

return null;
}
}
}
62 changes: 62 additions & 0 deletions src/XCore.Modules/XCore.Admin/AdminThemeService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using Microsoft.Extensions.Caching.Memory;
using XCore.Settings;
using XCore.Environment.Extensions;
using System;
using System.Threading.Tasks;

namespace XCore.Admin
{
public class AdminThemeService : IAdminThemeService
{
private const string CacheKey = "AdminThemeName";

private readonly IExtensionManager _extensionManager;
private readonly ISiteService _siteService;
private readonly IMemoryCache _memoryCache;

public AdminThemeService(
ISiteService siteService,
IExtensionManager extensionManager,
IMemoryCache memoryCache
)
{
_siteService = siteService;
_extensionManager = extensionManager;
_memoryCache = memoryCache;
}

public async Task<IExtensionInfo> GetAdminThemeAsync()
{
string currentThemeName = await GetAdminThemeNameAsync();
if (String.IsNullOrEmpty(currentThemeName))
{
return null;
}

return _extensionManager.GetExtension(currentThemeName);
}

public async Task SetAdminThemeAsync(string themeName)
{
var site = await _siteService.GetSiteSettingsAsync();
site.Properties["CurrentAdminThemeName"] = themeName;
//(site as IContent).ContentItem.Content.CurrentAdminThemeName = themeName;
_memoryCache.Set(CacheKey, themeName);
await _siteService.UpdateSiteSettingsAsync(site);
}

public async Task<string> GetAdminThemeNameAsync()
{
string themeName;
if (!_memoryCache.TryGetValue(CacheKey, out themeName))
{
var site = await _siteService.GetSiteSettingsAsync();
themeName = (string)site.Properties["CurrentAdminThemeName"];
// themeName = (string)(site as IContent).ContentItem.Content.CurrentAdminThemeName;
_memoryCache.Set(CacheKey, themeName);
}

return themeName;
}
}
}
9 changes: 9 additions & 0 deletions src/XCore.Modules/XCore.Admin/Module.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Name: Admin
AntiForgery: enabled
Author: The Orchard Team
Website: http://orchardproject.net
Version: 2.0.x
OrchardVersion: 2.0.x
Description: Creates an admin section for the site.
Dependencies: XCore.Settings
Category: Infrastructure
38 changes: 38 additions & 0 deletions src/XCore.Modules/XCore.Admin/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;
using Microsoft.Extensions.DependencyInjection;
using System;
using XCore.DisplayManagement.Theming;
using XCore.Modules;

namespace XCore.Admin
{
public class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
//services.AddNavigation();

//services.Configure<MvcOptions>((options) =>
//{
// options.Filters.Add(typeof(AdminZoneFilter));
// options.Filters.Add(typeof(AdminFilter));
// options.Filters.Add(typeof(AdminMenuFilter));
//});

//services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IThemeSelector, AdminThemeSelector>();
//services.AddScoped<IAdminThemeService, AdminThemeService>();
}

public override void Configure(IApplicationBuilder builder, IRouteBuilder routes, IServiceProvider serviceProvider)
{
routes.MapAreaRoute(
name: "Adming",
areaName: "XCore.Admin",
template: "adming",
defaults: new { controller = "Admin", action = "Index" }
);
}
}
}
20 changes: 20 additions & 0 deletions src/XCore.Modules/XCore.Admin/XCore.Admin.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Compile Remove="AdminThemeService.cs" />
</ItemGroup>


<ItemGroup>
<ProjectReference Include="..\..\XCore\XCore.Admin.Abstractions\XCore.Admin.Abstractions.csproj" />
<ProjectReference Include="..\..\XCore\XCore.DisplayManagement\XCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Module.Targets\XCore.Module.Targets.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
</ItemGroup>
</Project>
3 changes: 2 additions & 1 deletion src/XCore.Modules/XCore.Commons/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Reflection;
using XCore.BackgroundTasks;
using XCore.DeferredTasks;
using XCore.DisplayManagement;
using XCore.EntityFrameworkCore;
using XCore.Modules;
using XCore.Mvc.Core;
Expand Down Expand Up @@ -36,7 +37,7 @@ public override void ConfigureServices(IServiceCollection services)
//services.AddCaching();
//services.AddShellDescriptorStorage();
//services.AddExtensionManager();
//services.AddTheming();
services.AddTheming();
//services.AddLiquidViews();
}

Expand Down
1 change: 1 addition & 0 deletions src/XCore.Modules/XCore.Commons/XCore.Commons.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<ItemGroup>
<ProjectReference Include="..\..\XCore\XCore.BackgroundTasks\XCore.BackgroundTasks.csproj" />
<ProjectReference Include="..\..\XCore\XCore.DeferredTasks\XCore.DeferredTasks.csproj" />
<ProjectReference Include="..\..\XCore\XCore.DisplayManagement\XCore.DisplayManagement.csproj" />
<ProjectReference Include="..\..\XCore\XCore.EntityFrameworkCore\XCore.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Environment.Extensions\XCore.Environment.Extensions.csproj" />
<ProjectReference Include="..\..\XCore\XCore.Module.Targets\XCore.Module.Targets.csproj" />
Expand Down
5 changes: 5 additions & 0 deletions src/XCore.Themes/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\XCore.Build\XCore.Commons.props" />
<Import Project="..\XCore\XCore.Theme.Targets\XCore.Theme.Targets.props" />
<Import Project="..\XCore\XCore.Module.Targets\XCore.Module.Targets.props" />
</Project>
3 changes: 3 additions & 0 deletions src/XCore.Themes/TheAdmin/Assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[

]
7 changes: 7 additions & 0 deletions src/XCore.Themes/TheAdmin/PlaceHolder.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TheAdmin
{
// Just a class so that an assembly gets created
public class Placeholder
{
}
}
Loading

0 comments on commit 98c3870

Please sign in to comment.