Skip to content
This repository was archived by the owner on Feb 21, 2022. It is now read-only.

Commit 9a7bb0f

Browse files
author
magicodes
committed
1 parent 201db1d commit 9a7bb0f

File tree

68 files changed

+1854
-2247
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+1854
-2247
lines changed

Magicodes.Core.Web/GlobalConfigurationManager.cs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
using Magicodes.Web.Interfaces;
1616
using System.Web;
1717
using System.Text.RegularExpressions;
18+
using Magicodes.Web.Interfaces.Plus.Info;
19+
using Magicodes.Core.Web.Route;
1820

1921
//======================================================================
2022
//
@@ -115,45 +117,32 @@ public static void InitializeWebAPI()
115117
}
116118
static void GlobalConfigurationManager_OnConfiguration_Config_MVC(object sender, EventArgs e)
117119
{
118-
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
119-
AreaRegistration.RegisterAllAreas();
120-
120+
//检查MVC插件
121+
CheckMvcPlus();
122+
var documentsOpenProtocolManager = GlobalApplicationObject.Current.ApplicationContext.DocumentsOpenProtocolManager;
123+
//注册插件路由
121124
foreach (var mvcPlus in MvcConfigManager.MVCPlusList.OrderByDescending(p => p.MvcPlusType))
122125
{
123-
switch (mvcPlus.MvcPlusType)
124-
{
125-
case MvcPlusTypes.MVCHome:
126-
{
127-
RouteTable.Routes.MapRoute(
128-
name: "MCV_" + mvcPlus.PlusName,
129-
url: "{controller}/{action}/{id}",
130-
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, pluginName = mvcPlus.PlusName });
131-
}
132-
break;
133-
case MvcPlusTypes.MVC:
134-
{
135-
RouteTable.Routes.MapRoute(name: "MCV_" + mvcPlus.PlusName, url: "_{pluginName}/{controller}/{action}/{id}", defaults: new { action = "Index", id = UrlParameter.Optional, pluginName = mvcPlus.PlusName });
136-
}
137-
break;
138-
default:
139-
break;
140-
}
141-
126+
RouteHelper.MapRouteMVCPlus(mvcPlus);
127+
documentsOpenProtocolManager.RegisterDocumentsOpenProtocols(mvcPlus);
142128
}
129+
RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
130+
AreaRegistration.RegisterAllAreas();
131+
#region 注册请求事件,处理插件资源加载问题
143132
//注册请求事件,处理插件资源加载问题
144-
GlobalApplicationObject.Current.EventsManager.BeginRequest += (requestSender,arg) =>
133+
GlobalApplicationObject.Current.EventsManager.BeginRequest += (requestSender, arg) =>
145134
{
146135
//应用程序对象
147136
var application = (HttpApplication)requestSender;
148137
//HTTP上下文对象
149138
var context = application.Context;
150139
#region 如果非站内请求,随它去吧
151140
if (!context.Request.IsLocal)
152-
return;
141+
return;
153142
#endregion
154143
#region 如果非插件类请求,随它去吧
155144
if (!context.Request.Url.AbsolutePath.StartsWith("/Magicodes.", StringComparison.CurrentCultureIgnoreCase))
156-
return;
145+
return;
157146
#endregion
158147
foreach (var plusItem in MvcConfigManager.MVCPlusList)
159148
{
@@ -182,7 +171,26 @@ static void GlobalConfigurationManager_OnConfiguration_Config_MVC(object sender,
182171
return;
183172
}
184173
}
185-
};
174+
};
175+
#endregion
176+
}
177+
178+
179+
/// <summary>
180+
/// 检查MVC程序集的正确性
181+
/// </summary>
182+
private static void CheckMvcPlus()
183+
{
184+
var count = MvcConfigManager.MVCPlusList.Where(p => p.MvcPlusType == MvcPlusTypes.MVCAdmin).Count();
185+
if (count > 1 || count == 0)
186+
{
187+
throw new MagicodesException(count > 1 ? "后台程序集只允许存在一个" : "当前环境并不存在后台程序集,请下载");
188+
}
189+
count = MvcConfigManager.MVCPlusList.Where(p => p.MvcPlusType == MvcPlusTypes.MVCHome).Count();
190+
if (count > 1 || count == 0)
191+
{
192+
throw new MagicodesException(count > 1 ? "首页程序集只允许存在一个" : "当前环境并不存在首页程序集,请下载");
193+
}
186194
}
187195
static void GlobalConfigurationManager_OnConfiguration_Config_WEBAPI(object sender, EventArgs e)
188196
{

Magicodes.Core.Web/Magicodes.Core.Web.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
</Reference>
146146
</ItemGroup>
147147
<ItemGroup>
148+
<Compile Include="Controllers\EditorControllerBase.cs" />
148149
<Compile Include="Editor\EditorController.cs" />
149150
<Compile Include="Controllers\JSONActionResult.cs" />
150151
<Compile Include="Controllers\AdminControllerBase.cs" />
@@ -167,6 +168,7 @@
167168
<Compile Include="Mvc\PluginRazorViewEngine.cs" />
168169
<Compile Include="OData\ODataAdminControllerbase.cs" />
169170
<Compile Include="Properties\AssemblyInfo.cs" />
171+
<Compile Include="Route\RouteHelper.cs" />
170172
<Compile Include="Security\AntiXssAttribute.cs" />
171173
<Compile Include="Security\AuthHelper.cs" />
172174
<Compile Include="Security\EncoderHelper.cs" />

Magicodes.Core.Web/Mvc/MvcConfigManager.cs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using Magicodes.Web.Interfaces.Plus.Info;
2+
using Magicodes.Web.Interfaces.Plus.Mvc;
23
using System;
34
using System.Collections.Generic;
45
using System.Linq;
@@ -23,40 +24,35 @@
2324
//======================================================================
2425
namespace Magicodes.Core.Web.Mvc
2526
{
26-
/// <summary>
27-
/// MVC插件类型
28-
/// </summary>
29-
public enum MvcPlusTypes
30-
{
31-
MVCHome = 1,
32-
MVC = 2
33-
}
34-
public class MVCPlusInfo
27+
public class MVCPlusInfo : IMVCPlusInfo
3528
{
3629
public string PlusName { get; set; }
30+
public string PlusFullName { get; set; }
3731
public MvcPlusTypes MvcPlusType { get; set; }
32+
public PlusConfigInfo PlusConfigInfo { get; set; }
3833
}
3934
public class MvcConfigManager
4035
{
4136
static MvcConfigManager()
4237
{
43-
MVCPlusList = new List<MVCPlusInfo>();
4438
}
4539
/// <summary>
4640
/// Mvc插件列表
4741
/// </summary>
48-
public static List<MVCPlusInfo> MVCPlusList { get; set; }
42+
public static List<MVCPlusInfo> MVCPlusList = new List<MVCPlusInfo>();
4943
/// <summary>
5044
/// 配置MVC插件程序集路由
5145
/// </summary>
5246
/// <param name="mvcPlus"></param>
53-
public static void Config(Assembly mvcPlus, AssemblyTypes assType)
47+
public static void Config(Assembly mvcPlus, PlusConfigInfo plusInfo)
5448
{
5549
MVCPlusList.Add(
5650
new MVCPlusInfo()
5751
{
5852
PlusName = mvcPlus.GetName().Name,
59-
MvcPlusType = assType == AssemblyTypes.MVCHome ? MvcPlusTypes.MVCHome : MvcPlusTypes.MVC
53+
PlusFullName = mvcPlus.FullName,
54+
PlusConfigInfo = plusInfo,
55+
MvcPlusType = plusInfo.MvcPlusType == null ? MvcPlusTypes.MVC : plusInfo.MvcPlusType
6056
});
6157
}
6258

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
using Magicodes.Core.Web.Mvc;
2+
using Magicodes.Web.Interfaces.Plus.Info;
3+
using Magicodes.Web.Interfaces.Plus.Mvc;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
using System.Web.Mvc;
10+
using System.Web.Routing;
11+
12+
//======================================================================
13+
//
14+
// Copyright (C) 2014-2016 Magicodes团队
15+
// All rights reserved
16+
//
17+
// filename :RouteHelper
18+
// description :
19+
//
20+
// created by 雪雁 at 2015/2/9 17:12:01
21+
// http://www.magicodes.net
22+
//
23+
//======================================================================
24+
namespace Magicodes.Core.Web.Route
25+
{
26+
public class RouteHelper
27+
{
28+
public static void MapRouteMVCPlus(IMVCPlusInfo mvcPlus)
29+
{
30+
switch (mvcPlus.MvcPlusType)
31+
{
32+
//此类型插件只支持一个
33+
case MvcPlusTypes.MVCHome:
34+
{
35+
RouteTable.Routes.MapRoute(
36+
name: "MCV_" + mvcPlus.PlusName,
37+
url: "{controller}/{action}/{id}",
38+
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional, pluginName = mvcPlus.PlusName });
39+
}
40+
break;
41+
case MvcPlusTypes.MVC:
42+
{
43+
RouteTable.Routes.MapRoute(
44+
name: "MCV_" + mvcPlus.PlusName,
45+
url: "_{pluginName}/{controller}/{action}/{id}",
46+
defaults: new { action = "Index", id = UrlParameter.Optional, pluginName = mvcPlus.PlusName });
47+
}
48+
break;
49+
//此类型插件只支持一个
50+
case MvcPlusTypes.MVCAdmin:
51+
{
52+
RouteTable.Routes.MapRoute(
53+
name: "MCV_" + mvcPlus.PlusName,
54+
url: "admin/{controller}/{action}/{id}",
55+
defaults: new { action = "Index", controller = "Admin", id = UrlParameter.Optional, pluginName = mvcPlus.PlusName });
56+
}
57+
break;
58+
default:
59+
break;
60+
}
61+
}
62+
}
63+
}

Magicodes.Core/ApplicationContext.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
using Magicodes.Core.Web;
3030
using Magicodes.Web.Interfaces.Data.API.SiteNavs;
3131
using Magicodes.Web.Interfaces.Data.API;
32+
using Magicodes.Core.DocumentProtocols;
3233

3334
namespace Magicodes.Core
3435
{
@@ -260,6 +261,8 @@ public override void PreApplicationStartInitialize()
260261
PlusManager.LoadPlusStrategys(this.GetType().Assembly);
261262
//初始化嵌入资源管理器
262263
ManifestResourceManager = new ManifestResourceManager();
264+
//初始化文档协议管理器
265+
DocumentsOpenProtocolManager = new DocumentsOpenProtocolManager();
263266
//初始化配置管理器
264267
ConfigManager = new ConfigManager();
265268
//加载程序集

Magicodes.Web.Interfaces/DocumentProtocols/DocumentOpenProtocol.cs renamed to Magicodes.Core/DocumentProtocols/DocumentOpenProtocol.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System;
1+
using Magicodes.Web.Interfaces.DocumentProtocols;
2+
using System;
23
using System.Collections.Generic;
34
using System.Linq;
45
using System.Text;
@@ -16,12 +17,12 @@
1617
// http://www.magicodes.net
1718
//
1819
//======================================================================
19-
namespace Magicodes.Web.Interfaces.DocumentProtocols
20+
namespace Magicodes.Core.DocumentProtocols
2021
{
2122
/// <summary>
2223
/// 文档打开协议
2324
/// </summary>
24-
public class DocumentOpenProtocol
25+
public class DocumentOpenProtocol : IDocumentOpenProtocol
2526
{
2627
/// <summary>
2728
/// contentType:内容类型(MIME 类型)。

Magicodes.Core/Magicodes.Core.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@
112112
<Compile Include="Data\DataRepositoryBase.cs" />
113113
<Compile Include="Data\UnitOfWorkBase.cs" />
114114
<Compile Include="Data\DbSessionBase.cs" />
115+
<Compile Include="DocumentProtocols\DocumentOpenProtocol.cs" />
116+
<Compile Include="DocumentProtocols\DocumentsOpenProtocolManager.cs" />
115117
<Compile Include="Performance\Watch\CodeWatch.cs" />
116118
<Compile Include="Plus\AssemblyManager.cs" />
117119
<Compile Include="Plus\PlusAssemblys.cs" />

Magicodes.Core/Plus/PlusManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,10 @@ public override Assembly Deploy(FileInfo dllFile)
134134
case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.Models:
135135
break;
136136
case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.MVC:
137-
case Magicodes.Web.Interfaces.Plus.Info.AssemblyTypes.MVCHome:
138137
{
139138
//配置插件路由
140-
MvcConfigManager.Config(assembly, plusInfo.PlusConfigInfo.AssemblyType);
139+
MvcConfigManager.Config(assembly, plusInfo.PlusConfigInfo);
140+
break;
141141
}
142142
break;
143143
default:

Magicodes.Web.Interfaces/ApplicationContextBase.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ public abstract class ApplicationContextBase
2929
/// </summary>
3030
readonly Lazy<SitePaths> sitePaths = new Lazy<SitePaths>(() => new SitePaths());
3131

32-
/// <summary>
33-
/// 文档打开协议管理器
34-
/// </summary>
35-
readonly Lazy<DocumentsOpenProtocolManager> documentsOpenProtocolManager = new Lazy<DocumentsOpenProtocolManager>(() => new DocumentsOpenProtocolManager());
36-
3732
#region 属性
3833
/// <summary>
3934
/// 网站路径
@@ -42,7 +37,7 @@ public abstract class ApplicationContextBase
4237
/// <summary>
4338
/// 文档打开协议管理器
4439
/// </summary>
45-
public DocumentsOpenProtocolManager DocumentsOpenProtocolManager { get { return documentsOpenProtocolManager.Value; } }
40+
public IDocumentsOpenProtocolManager DocumentsOpenProtocolManager { get;set; }
4641
/// <summary>
4742
/// 应用程序日志对象
4843
/// </summary>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
//======================================================================
8+
//
9+
// Copyright (C) 2014-2016 Magicodes团队
10+
// All rights reserved
11+
//
12+
// filename :IDocumentOpenProtocol
13+
// description :文档打开协议信息
14+
//
15+
// created by 雪雁 at 2014/12/18 14:56:48
16+
// http://www.magicodes.net
17+
//
18+
//======================================================================
19+
namespace Magicodes.Web.Interfaces.DocumentProtocols
20+
{
21+
/// <summary>
22+
/// 文档打开协议
23+
/// </summary>
24+
public class IDocumentOpenProtocol
25+
{
26+
/// <summary>
27+
/// contentType:内容类型(MIME 类型)。
28+
/// </summary>
29+
public string ContentType { get; set; }
30+
/// <summary>
31+
/// 查看器路径
32+
/// </summary>
33+
public string ViewerUrl { get; set; }
34+
}
35+
}

0 commit comments

Comments
 (0)