|
15 | 15 | using Magicodes.Web.Interfaces; |
16 | 16 | using System.Web; |
17 | 17 | using System.Text.RegularExpressions; |
| 18 | +using Magicodes.Web.Interfaces.Plus.Info; |
| 19 | +using Magicodes.Core.Web.Route; |
18 | 20 |
|
19 | 21 | //====================================================================== |
20 | 22 | // |
@@ -115,45 +117,32 @@ public static void InitializeWebAPI() |
115 | 117 | } |
116 | 118 | static void GlobalConfigurationManager_OnConfiguration_Config_MVC(object sender, EventArgs e) |
117 | 119 | { |
118 | | - RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); |
119 | | - AreaRegistration.RegisterAllAreas(); |
120 | | - |
| 120 | + //检查MVC插件 |
| 121 | + CheckMvcPlus(); |
| 122 | + var documentsOpenProtocolManager = GlobalApplicationObject.Current.ApplicationContext.DocumentsOpenProtocolManager; |
| 123 | + //注册插件路由 |
121 | 124 | foreach (var mvcPlus in MvcConfigManager.MVCPlusList.OrderByDescending(p => p.MvcPlusType)) |
122 | 125 | { |
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); |
142 | 128 | } |
| 129 | + RouteTable.Routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); |
| 130 | + AreaRegistration.RegisterAllAreas(); |
| 131 | + #region 注册请求事件,处理插件资源加载问题 |
143 | 132 | //注册请求事件,处理插件资源加载问题 |
144 | | - GlobalApplicationObject.Current.EventsManager.BeginRequest += (requestSender,arg) => |
| 133 | + GlobalApplicationObject.Current.EventsManager.BeginRequest += (requestSender, arg) => |
145 | 134 | { |
146 | 135 | //应用程序对象 |
147 | 136 | var application = (HttpApplication)requestSender; |
148 | 137 | //HTTP上下文对象 |
149 | 138 | var context = application.Context; |
150 | 139 | #region 如果非站内请求,随它去吧 |
151 | 140 | if (!context.Request.IsLocal) |
152 | | - return; |
| 141 | + return; |
153 | 142 | #endregion |
154 | 143 | #region 如果非插件类请求,随它去吧 |
155 | 144 | if (!context.Request.Url.AbsolutePath.StartsWith("/Magicodes.", StringComparison.CurrentCultureIgnoreCase)) |
156 | | - return; |
| 145 | + return; |
157 | 146 | #endregion |
158 | 147 | foreach (var plusItem in MvcConfigManager.MVCPlusList) |
159 | 148 | { |
@@ -182,7 +171,26 @@ static void GlobalConfigurationManager_OnConfiguration_Config_MVC(object sender, |
182 | 171 | return; |
183 | 172 | } |
184 | 173 | } |
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 | + } |
186 | 194 | } |
187 | 195 | static void GlobalConfigurationManager_OnConfiguration_Config_WEBAPI(object sender, EventArgs e) |
188 | 196 | { |
|
0 commit comments