-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGlobal.asax.cs
61 lines (57 loc) · 2.95 KB
/
Global.asax.cs
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
using System;
using System.Web.Hosting;
using System.Web.Mvc;
using System.Web.Routing;
using DevExpress.DashboardWeb;
using DevExpress.DataAccess.ConnectionParameters;
using DevExpress.Web;
using MvcDashboard_ServerSideApi.Controllers;
namespace MvcDashboard_ServerSideApi {
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start() {
DashboardConfig.RegisterService(RouteTable.Routes);
RouteConfig.RegisterRoutes(RouteTable.Routes);
ASPxWebControl.CallbackError += Application_Error;
ControllerBuilder.Current.SetControllerFactory(typeof(CustomControllerFactory));
}
protected void Application_Error(object sender, EventArgs e) {
Exception exception = System.Web.HttpContext.Current.Server.GetLastError();
}
}
public class CustomControllerFactory : DefaultControllerFactory {
public override IController CreateController(RequestContext requestContext, string controllerName) {
if (controllerName == "SalesDashboard") {
DashboardConfigurator salesConfigurator = new DashboardConfigurator();
salesConfigurator.SetDashboardStorage(new DashboardFileStorage(@"~/App_Data/Sales"));
salesConfigurator.ConfigureDataConnection += (s, e) => {
string databasePath = HostingEnvironment.MapPath("~/App_Data/nwind.mdb");
if (e.ConnectionName == "Northwind connection")
e.ConnectionParameters = new Access97ConnectionParameters(databasePath, "", "");
};
return new DefaultDashboardController(salesConfigurator);
}
else if (controllerName == "MarketingDashboard") {
DashboardConfigurator marketingConfigurator = new DashboardConfigurator();
marketingConfigurator.SetDashboardStorage(new DashboardFileStorage(@"~/App_Data/Marketing"));
marketingConfigurator.ConfigureDataConnection += (s, e) => {
string connectionString = @"provider=MSOLAP;
data source=http://demos.devexpress.com/Services/OLAP/msmdpump.dll;
initial catalog=Adventure Works DW Standard Edition;
cube name=Adventure Works;";
if (e.ConnectionName == "Adventure Works connection")
e.ConnectionParameters = new OlapConnectionParameters(connectionString);
};
return new DefaultDashboardController(marketingConfigurator);
}
else {
return base.CreateController(requestContext, controllerName);
}
}
public override void ReleaseController(IController controller) {
IDisposable dispose = controller as IDisposable;
if (dispose != null) {
dispose.Dispose();
}
}
}
}