Skip to content

Commit 2a48507

Browse files
committed
Routing: (perf) reduced and simplified mvc routes
1 parent bd587ac commit 2a48507

156 files changed

Lines changed: 2652 additions & 1866 deletions

File tree

Some content is hidden

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

src/Libraries/SmartStore.Core/Plugins/PluginFinder.cs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -82,14 +82,13 @@ public virtual IEnumerable<PluginDescriptor> GetPluginDescriptors<T>(bool instal
8282

8383
public virtual PluginDescriptor GetPluginDescriptorByAssembly(Assembly assembly, bool installedOnly = true)
8484
{
85-
Guard.ArgumentNotNull(() => assembly);
86-
8785
PluginDescriptor descriptor;
88-
if (_assemblyMap.TryGetValue(assembly, out descriptor))
86+
if (assembly != null && _assemblyMap.TryGetValue(assembly, out descriptor))
8987
{
9088
if (!installedOnly || descriptor.Installed)
9189
return descriptor;
9290
}
91+
9392
return null;
9493
}
9594

@@ -101,14 +100,13 @@ public virtual PluginDescriptor GetPluginDescriptorByAssembly(Assembly assembly,
101100
/// <returns>>Plugin descriptor</returns>
102101
public virtual PluginDescriptor GetPluginDescriptorBySystemName(string systemName, bool installedOnly = true)
103102
{
104-
Guard.ArgumentNotEmpty(() => systemName);
105-
106103
PluginDescriptor descriptor;
107-
if (_nameMap.TryGetValue(systemName, out descriptor))
104+
if (systemName.HasValue() && _nameMap.TryGetValue(systemName, out descriptor))
108105
{
109106
if (!installedOnly || descriptor.Installed)
110107
return descriptor;
111108
}
109+
112110
return null;
113111
}
114112

@@ -121,17 +119,16 @@ public virtual PluginDescriptor GetPluginDescriptorBySystemName(string systemNam
121119
/// <returns>>Plugin descriptor</returns>
122120
public virtual PluginDescriptor GetPluginDescriptorBySystemName<T>(string systemName, bool installedOnly = true) where T : class, IPlugin
123121
{
124-
Guard.ArgumentNotEmpty(() => systemName);
125-
126122
PluginDescriptor descriptor;
127-
if (_nameMap.TryGetValue(systemName, out descriptor))
123+
if (systemName.HasValue() && _nameMap.TryGetValue(systemName, out descriptor))
128124
{
129125
if (!installedOnly || descriptor.Installed)
130126
{
131127
if (typeof(T).IsAssignableFrom(descriptor.PluginType))
132128
return descriptor;
133129
}
134130
}
131+
135132
return null;
136133
}
137134

src/Libraries/SmartStore.Core/Themes/ThemeManifestMaterializer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public ThemeManifest Materialize()
3535
_manifest.ThemeTitle = root.GetAttribute("title") ?? _manifest.ThemeName;
3636
_manifest.SupportRtl = root.GetAttribute("supportRTL").ToBool();
3737
_manifest.MobileTheme = root.GetAttribute("mobileTheme").ToBool();
38-
_manifest.PreviewImageUrl = root.GetAttribute("previewImageUrl").NullEmpty() ?? "~/Themes/{0}/Content/preview.png".FormatCurrent(_manifest.ThemeName);
38+
_manifest.PreviewImageUrl = root.GetAttribute("previewImageUrl").NullEmpty() ?? "~/Themes/{0}/preview.png".FormatCurrent(_manifest.ThemeName);
3939
_manifest.PreviewText = root.GetAttribute("previewText").ToSafe();
4040
_manifest.Author = root.GetAttribute("author").ToSafe();
4141
_manifest.Version = root.GetAttribute("version").ToSafe().HasValue() ? root.GetAttribute("version") : "1.0";

src/Libraries/SmartStore.Services/Common/FulltextService.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,15 @@ public virtual bool IsFullTextSupported()
4747
if (_commonSettings.UseStoredProceduresIfSupported && _dataProvider.StoredProceduresSupported)
4848
{
4949
//stored procedures are enabled and supported by the database.
50-
var result = _dbContext.SqlQuery<int>("EXEC [FullText_IsSupported]");
51-
return result.FirstOrDefault() > 0;
50+
try
51+
{
52+
var result = _dbContext.SqlQuery<int>("EXEC [FullText_IsSupported]");
53+
return result.Any() && result.FirstOrDefault() > 0;
54+
}
55+
catch
56+
{
57+
return false;
58+
}
5259
}
5360
else
5461
{

src/Libraries/SmartStore.Services/Seo/UrlRecordService.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,7 @@ public partial class UrlRecordService : IUrlRecordService
2828

2929
#region Ctor
3030

31-
/// <summary>
32-
/// Ctor
33-
/// </summary>
34-
/// <param name="cacheManager">Cache manager</param>
35-
/// <param name="urlRecordRepository">URL record repository</param>
36-
public UrlRecordService(ICacheManager cacheManager,
37-
IRepository<UrlRecord> urlRecordRepository)
31+
public UrlRecordService(ICacheManager cacheManager, IRepository<UrlRecord> urlRecordRepository)
3832
{
3933
this._cacheManager = cacheManager;
4034
this._urlRecordRepository = urlRecordRepository;
@@ -158,10 +152,7 @@ public virtual string GetActiveSlug(int entityId, string entityName, int languag
158152
orderby ur.Id descending
159153
select ur.Slug;
160154
var slug = query.FirstOrDefault();
161-
//little hack here. nulls aren't cacheable so set it to ""
162-
if (slug == null)
163-
slug = "";
164-
return slug;
155+
return slug ?? "";
165156
});
166157
}
167158

src/Plugins/Developer.DevTools/Controllers/DevToolsController.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
namespace SmartStore.Plugin.Developer.DevTools.Controllers
1414
{
15-
public class DevToolsController : PluginControllerBase
15+
16+
public class DevToolsController : SmartController
1617
{
1718
private readonly IWorkContext _workContext;
1819
private readonly IStoreContext _storeContext;
@@ -31,6 +32,7 @@ public DevToolsController(
3132
_settingService = settingService;
3233
}
3334

35+
[AdminAuthorize]
3436
[ChildActionOnly]
3537
public ActionResult Configure()
3638
{
@@ -44,6 +46,7 @@ public ActionResult Configure()
4446
return View(settings);
4547
}
4648

49+
[AdminAuthorize]
4750
[HttpPost]
4851
[ChildActionOnly]
4952
public ActionResult Configure(ProfilerSettings model, FormCollection form)
@@ -61,7 +64,6 @@ public ActionResult Configure(ProfilerSettings model, FormCollection form)
6164
return Configure();
6265
}
6366

64-
[AllowAnonymous]
6567
public ActionResult MiniProfiler()
6668
{
6769
return View();

src/Plugins/Payments.PayPalStandard/Controllers/PaymentPayPalStandardController.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ public ActionResult PDTHandler(FormCollection form)
204204
}
205205
}
206206

207-
return RedirectToRoute("CheckoutCompleted");
207+
return RedirectToAction("Completed", "Checkout", new { area = "" });
208208
}
209209
else
210210
{
@@ -442,10 +442,10 @@ public ActionResult CancelOrder(FormCollection form)
442442

443443
if (order != null)
444444
{
445-
return RedirectToRoute("OrderDetails", new { orderId = order.Id });
445+
return RedirectToAction("Details", "Order", new { id = order.Id });
446446
}
447447

448-
return RedirectToAction("Index", "Home", new { area = "Payments.PayPalStandard" });
448+
return RedirectToAction("Index", "Home", new { area = "" });
449449
}
450450
}
451451
}

src/Plugins/Tax.CountryStateZip/SmartStore.Plugin.Tax.CountryStateZip.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
<WebProjectProperties>
228228
<UseIIS>False</UseIIS>
229229
<AutoAssignPort>True</AutoAssignPort>
230-
<DevelopmentServerPort>0</DevelopmentServerPort>
230+
<DevelopmentServerPort>60948</DevelopmentServerPort>
231231
<DevelopmentServerVPath>/</DevelopmentServerVPath>
232232
<IISUrl>http://localhost:53074/</IISUrl>
233233
<NTLMAuthentication>False</NTLMAuthentication>
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
using System;
2+
using System.Linq;
3+
using System.Collections.Generic;
4+
using System.Net;
5+
using System.Web;
6+
using System.Web.Mvc;
7+
using System.Web.Routing;
8+
using SmartStore.Core;
9+
using SmartStore.Core.Data;
10+
using SmartStore.Core.Infrastructure;
11+
using SmartStore.Core.Logging;
12+
using SmartStore.Core.Localization;
13+
using System.Threading;
14+
using System.Security;
15+
using System.Runtime.InteropServices;
16+
17+
namespace SmartStore.Web.Framework.Controllers
18+
{
19+
20+
public class HandleExceptionFilter : IActionFilter
21+
{
22+
private readonly Lazy<ILogger> _logger;
23+
private readonly Lazy<IEnumerable<IExceptionFilter>> _exceptionFilters;
24+
private readonly INotifier _notifier;
25+
26+
public HandleExceptionFilter(
27+
Lazy<ILogger> logger,
28+
Lazy<IEnumerable<IExceptionFilter>> exceptionFilters,
29+
INotifier notifier)
30+
{
31+
this._logger = logger;
32+
this._exceptionFilters = exceptionFilters;
33+
this._notifier = notifier;
34+
}
35+
36+
public void OnActionExecuting(ActionExecutingContext filterContext)
37+
{
38+
}
39+
40+
public void OnActionExecuted(ActionExecutedContext filterContext)
41+
{
42+
var descriptor = filterContext.ActionDescriptor;
43+
44+
// handle server error
45+
// don't provide custom errors if the action has some custom code to handle exceptions
46+
if (!filterContext.ActionDescriptor.GetCustomAttributes(typeof(HandleErrorAttribute), false).Any())
47+
{
48+
if (!filterContext.ExceptionHandled && filterContext.Exception != null && filterContext.HttpContext.IsCustomErrorEnabled)
49+
{
50+
if (ShouldHandleException(filterContext.Exception))
51+
{
52+
_logger.Value.Error("An unexpected error occurred", filterContext.Exception);
53+
54+
// inform exception filters of the exception that was suppressed
55+
var exceptionContext = new ExceptionContext(filterContext.Controller.ControllerContext, filterContext.Exception);
56+
foreach (var exceptionFilter in _exceptionFilters.Value)
57+
{
58+
exceptionFilter.OnException(exceptionContext);
59+
}
60+
61+
if (exceptionContext.ExceptionHandled)
62+
{
63+
filterContext.ExceptionHandled = true;
64+
filterContext.Result = exceptionContext.Result;
65+
}
66+
else
67+
{
68+
if (!filterContext.IsChildAction)
69+
{
70+
var controllerName = descriptor.ControllerDescriptor.ControllerName;
71+
var actionName = descriptor.ActionName;
72+
73+
// if the request is AJAX return JSON data
74+
if (filterContext.HttpContext.Request.IsAjaxRequest())
75+
{
76+
filterContext.Result = new JsonResult
77+
{
78+
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
79+
Data = new
80+
{
81+
error = true,
82+
controller = controllerName,
83+
action = actionName,
84+
message = filterContext.Exception.Message
85+
}
86+
};
87+
}
88+
else
89+
{
90+
filterContext.Result = new ViewResult
91+
{
92+
ViewName = "Error",
93+
MasterName = (string)null,
94+
ViewData = new ViewDataDictionary<HandleErrorInfo>(new HandleErrorInfo(filterContext.Exception, controllerName, actionName)),
95+
TempData = filterContext.Controller.TempData
96+
};
97+
}
98+
99+
filterContext.ExceptionHandled = true;
100+
101+
filterContext.RequestContext.HttpContext.Response.Clear();
102+
filterContext.RequestContext.HttpContext.Response.StatusCode = 500;
103+
104+
// prevent IIS 7.0 classic mode from handling the 404/500 itself
105+
filterContext.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
106+
}
107+
}
108+
}
109+
}
110+
}
111+
112+
if (filterContext.Result is HttpNotFoundResult && !filterContext.IsChildAction)
113+
{
114+
// handle not found (404) from within the MVC pipleline (only called when HttpNotFoundResult is returned from actions)
115+
var requestContext = filterContext.RequestContext;
116+
var url = requestContext.HttpContext.Request.RawUrl;
117+
118+
filterContext.Result = new ViewResult
119+
{
120+
ViewName = "NotFound",
121+
MasterName = (string)null,
122+
ViewData = new ViewDataDictionary<HandleErrorInfo>(new HandleErrorInfo(new HttpException(404, "The resource does not exist."), descriptor.ActionName, descriptor.ControllerDescriptor.ControllerName)),
123+
TempData = filterContext.Controller.TempData
124+
};
125+
requestContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
126+
127+
// prevent IIS 7.0 classic mode from handling the 404/500 itself
128+
requestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
129+
}
130+
}
131+
132+
private bool ShouldHandleException(Exception exception)
133+
{
134+
return !(
135+
exception is StackOverflowException ||
136+
exception is OutOfMemoryException ||
137+
exception is AccessViolationException ||
138+
exception is AppDomainUnloadedException ||
139+
exception is ThreadAbortException ||
140+
exception is SecurityException ||
141+
exception is SEHException);
142+
}
143+
144+
}
145+
146+
}

src/Presentation/SmartStore.Web.Framework/Controllers/LanguageSeoCodeAttribute.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Net;
23
using System.Web;
34
using System.Web.Mvc;
45
using System.Web.Routing;
@@ -58,10 +59,21 @@ public override void OnActionExecuting(ActionExecutingContext filterContext)
5859
{
5960
if (!workContext.IsPublishedLanguage(seoCode))
6061
{
61-
// language is not defined in system or not assigned to store
62-
if (localizationSettings.InvalidLanguageRedirectBehaviour == InvalidLanguageRedirectBehaviour.ReturnHttp404)
62+
var descriptor = filterContext.ActionDescriptor;
63+
64+
// language is not defined in system or not assigned to store
65+
if (localizationSettings.InvalidLanguageRedirectBehaviour == InvalidLanguageRedirectBehaviour.ReturnHttp404)
6366
{
64-
filterContext.Result = new RedirectResult("~/404");
67+
filterContext.Result = new ViewResult
68+
{
69+
ViewName = "NotFound",
70+
MasterName = (string)null,
71+
ViewData = new ViewDataDictionary<HandleErrorInfo>(new HandleErrorInfo(new HttpException(404, "The resource does not exist."), descriptor.ActionName, descriptor.ControllerDescriptor.ControllerName)),
72+
TempData = filterContext.Controller.TempData
73+
};
74+
filterContext.RouteData.Values["StripInvalidSeoCode"] = true;
75+
filterContext.RequestContext.HttpContext.Response.StatusCode = (int)HttpStatusCode.NotFound;
76+
filterContext.RequestContext.HttpContext.Response.TrySkipIisCustomErrors = true;
6577
}
6678
else if (localizationSettings.InvalidLanguageRedirectBehaviour == InvalidLanguageRedirectBehaviour.FallbackToWorkingLanguage)
6779
{

0 commit comments

Comments
 (0)