/
WebApplication.cs
85 lines (81 loc) · 4.58 KB
/
WebApplication.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
using System;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.Web;
using System.Collections.Generic;
using DevExpress.ExpressApp.Xpo;
namespace DxSample.Web {
// For more typical usage scenarios, be sure to check out https://documentation.devexpress.com/eXpressAppFramework/DevExpressExpressAppWebWebApplicationMembersTopicAll.aspx
public partial class DxSampleAspNetApplication : WebApplication {
private DevExpress.ExpressApp.SystemModule.SystemModule module1;
private DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule module2;
private DxSample.Module.DxSampleModule module3;
private DxSample.Module.Web.DxSampleAspNetModule module4;
public DxSampleAspNetApplication() {
InitializeComponent();
LinkNewObjectToParentImmediately = false;
DevExpress.ExpressApp.Web.Editors.ASPx.ASPxGridListEditor.AllowFilterControlHierarchy = true;
DevExpress.ExpressApp.Web.Editors.ASPx.ASPxGridListEditor.MaxFilterControlHierarchyDepth = 3;
DevExpress.ExpressApp.Web.Editors.ASPx.ASPxCriteriaPropertyEditor.AllowFilterControlHierarchyDefault = true;
DevExpress.ExpressApp.Web.Editors.ASPx.ASPxCriteriaPropertyEditor.MaxHierarchyDepthDefault = 3;
}
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
args.ObjectSpaceProvider = new XPObjectSpaceProvider(GetDataStoreProvider(args.ConnectionString, args.Connection), true);
args.ObjectSpaceProviders.Add(new NonPersistentObjectSpaceProvider(TypesInfo, null));
}
private IXpoDataStoreProvider GetDataStoreProvider(string connectionString, System.Data.IDbConnection connection) {
System.Web.HttpApplicationState application = (System.Web.HttpContext.Current != null) ? System.Web.HttpContext.Current.Application : null;
IXpoDataStoreProvider dataStoreProvider = null;
if(application != null && application["DataStoreProvider"] != null) {
dataStoreProvider = application["DataStoreProvider"] as IXpoDataStoreProvider;
}
else {
dataStoreProvider = XPObjectSpaceProvider.GetDataStoreProvider(connectionString, connection, true);
if(application != null) {
application["DataStoreProvider"] = dataStoreProvider;
}
}
return dataStoreProvider;
}
private void DxSampleAspNetApplication_DatabaseVersionMismatch(object sender, DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs e) {
#if EASYTEST
e.Updater.Update();
e.Handled = true;
#else
if(System.Diagnostics.Debugger.IsAttached) {
e.Updater.Update();
e.Handled = true;
}
else {
string message = "The application cannot connect to the specified database, " +
"because the database doesn't exist, its version is older " +
"than that of the application or its schema does not match " +
"the ORM data model structure. To avoid this error, use one " +
"of the solutions from the https://www.devexpress.com/kb=T367835 KB Article.";
if(e.CompatibilityError != null && e.CompatibilityError.Exception != null) {
message += "\r\n\r\nInner exception: " + e.CompatibilityError.Exception.Message;
}
throw new InvalidOperationException(message);
}
#endif
}
private void InitializeComponent() {
this.module1 = new DevExpress.ExpressApp.SystemModule.SystemModule();
this.module2 = new DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule();
this.module3 = new DxSample.Module.DxSampleModule();
this.module4 = new DxSample.Module.Web.DxSampleAspNetModule();
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
//
// DxSampleAspNetApplication
//
this.ApplicationName = "DxSample";
this.CheckCompatibilityType = DevExpress.ExpressApp.CheckCompatibilityType.DatabaseSchema;
this.Modules.Add(this.module1);
this.Modules.Add(this.module2);
this.Modules.Add(this.module3);
this.Modules.Add(this.module4);
this.DatabaseVersionMismatch += new System.EventHandler<DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs>(this.DxSampleAspNetApplication_DatabaseVersionMismatch);
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
}
}