forked from smartstore/SmartStoreNET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGlobal.asax.cs
More file actions
166 lines (134 loc) · 5.59 KB
/
Copy pathGlobal.asax.cs
File metadata and controls
166 lines (134 loc) · 5.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System.Linq;
using System.Web;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using System.Web.WebPages;
using FluentValidation.Mvc;
using SmartStore.Core;
using SmartStore.Core.Data;
using SmartStore.Core.Events;
using SmartStore.Core.Infrastructure;
using SmartStore.Services.Tasks;
using SmartStore.Web.Framework.Controllers;
using SmartStore.Web.Framework.Mvc;
using SmartStore.Web.Framework.Mvc.Bundles;
using SmartStore.Web.Framework.Mvc.Routes;
using SmartStore.Web.Framework.Plugins;
using SmartStore.Web.Framework.Themes;
using SmartStore.Web.Framework.Validators;
namespace SmartStore.Web
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
var eventPublisher = EngineContext.Current.Resolve<IEventPublisher>();
eventPublisher.Publish(new AppRegisterGlobalFiltersEvent {
Filters = filters
});
}
public static void RegisterRoutes(RouteCollection routes, bool databaseInstalled = true)
{
//routes.IgnoreRoute("favicon.ico");
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("{resource}.ashx/{*pathInfo}");
routes.IgnoreRoute(".db/{*virtualpath}");
// register routes (core, admin, plugins, etc)
var routePublisher = EngineContext.Current.Resolve<IRoutePublisher>();
routePublisher.RegisterRoutes(routes);
}
public static void RegisterBundles(BundleCollection bundles)
{
// register custom bundles
var bundlePublisher = EngineContext.Current.Resolve<IBundlePublisher>();
bundlePublisher.RegisterBundles(bundles);
}
protected void Application_Start()
{
// we use our own mobile devices support (".Mobile" is reserved). that's why we disable it.
var mobileDisplayMode = DisplayModeProvider.Instance.Modes.FirstOrDefault(x => x.DisplayModeId == DisplayModeProvider.MobileDisplayModeId);
if (mobileDisplayMode != null)
DisplayModeProvider.Instance.Modes.Remove(mobileDisplayMode);
bool installed = DataSettings.DatabaseIsInstalled();
if (installed)
{
// remove all view engines
ViewEngines.Engines.Clear();
}
// initialize engine context
EngineContext.Initialize(false);
// model binders
ModelBinders.Binders.DefaultBinder = new SmartModelBinder();
// Add some functionality on top of the default ModelMetadataProvider
ModelMetadataProviders.Current = new SmartMetadataProvider();
// Register MVC areas
AreaRegistration.RegisterAllAreas();
// fluent validation
DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new SmartValidatorFactory()));
// Routes
RegisterRoutes(RouteTable.Routes, installed);
// localize MVC resources
ClientDataTypeModelValidatorProvider.ResourceClassKey = "MvcLocalization";
DefaultModelBinder.ResourceClassKey = "MvcLocalization";
ErrorMessageProvider.SetResourceClassKey("MvcLocalization");
if (installed)
{
// register our themeable razor view engine we use
ViewEngines.Engines.Add(new ThemeableRazorViewEngine());
// Global filters
RegisterGlobalFilters(GlobalFilters.Filters);
// Bundles
RegisterBundles(BundleTable.Bundles);
// register virtual path provider for theming (file inheritance & variables handling)
HostingEnvironment.RegisterVirtualPathProvider(new ThemingVirtualPathProvider(HostingEnvironment.VirtualPathProvider));
BundleTable.VirtualPathProvider = HostingEnvironment.VirtualPathProvider;
// register plugin debug view virtual path provider
if (HttpContext.Current.IsDebuggingEnabled)
{
HostingEnvironment.RegisterVirtualPathProvider(new PluginDebugViewVirtualPathProvider());
}
// start scheduled tasks
TaskManager.Instance.Initialize();
TaskManager.Instance.Start();
}
else
{
// app not installed
// Install filter
GlobalFilters.Filters.Add(new HandleInstallFilter());
}
}
public override string GetVaryByCustomString(HttpContext context, string custom)
{
string result = string.Empty;
if (DataSettings.DatabaseIsInstalled())
{
custom = custom.ToLowerInvariant();
switch (custom)
{
case "theme":
result = EngineContext.Current.Resolve<IThemeContext>().CurrentTheme.ThemeName;
break;
case "store":
result = EngineContext.Current.Resolve<IStoreContext>().CurrentStore.Id.ToString();
break;
case "theme_store":
result = "{0}-{1}".FormatInvariant(
EngineContext.Current.Resolve<IThemeContext>().CurrentTheme.ThemeName,
EngineContext.Current.Resolve<IStoreContext>().CurrentStore.Id.ToString());
break;
}
}
if (result.HasValue())
{
return result;
}
return base.GetVaryByCustomString(context, custom);
}
}
}