-
Notifications
You must be signed in to change notification settings - Fork 11
/
WebApplication.cs
139 lines (135 loc) · 8.37 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
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
using System;
using DevExpress.ExpressApp;
using System.ComponentModel;
using DevExpress.ExpressApp.Web;
using System.Collections.Generic;
using DevExpress.ExpressApp.Xpo;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Security.ClientServer;
using MySolution.Module.Security;
using MySolution.Module.BusinessObjects;
using MySolution.Web.Security;
using MySolution.Module.Web.Security;
namespace MySolution.Web {
// For more typical usage scenarios, be sure to check out https://docs.devexpress.com/eXpressAppFramework/DevExpress.ExpressApp.Web.WebApplication
public partial class MySolutionAspNetApplication : WebApplication {
private DevExpress.ExpressApp.SystemModule.SystemModule module1;
private DevExpress.ExpressApp.Web.SystemModule.SystemAspNetModule module2;
private MySolution.Module.MySolutionModule module3;
private MySolution.Module.Web.MySolutionAspNetModule module4;
private DevExpress.ExpressApp.Security.SecurityModule securityModule1;
private DevExpress.ExpressApp.Security.SecurityStrategyComplex securityStrategyComplex1;
private DevExpress.ExpressApp.Security.AuthenticationStandard authenticationStandard1;
private DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule conditionalAppearanceModule;
private DevExpress.ExpressApp.Validation.ValidationModule validationModule;
private DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule validationAspNetModule;
public MySolutionAspNetApplication() {
InitializeComponent();
AuthenticationMixed authenticationMixed = new AuthenticationMixed();
authenticationMixed.IsSupportChangePassword = true;
authenticationMixed.LogonParametersType = typeof(AuthenticationStandardLogonParameters);
authenticationMixed.AuthenticationProviders.Add(typeof(CustomAuthenticationStandardProvider).Name, new CustomAuthenticationStandardProvider(typeof(ApplicationUser)));
OAuthProvider authProvider = new OAuthProvider(typeof(ApplicationUser), securityStrategyComplex1);
authProvider.CreateUserAutomatically = true;
authenticationMixed.AuthenticationProviders.Add(typeof(OAuthProvider).Name, authProvider);
securityStrategyComplex1.Authentication = authenticationMixed;
}
protected override IViewUrlManager CreateViewUrlManager() {
return new ViewUrlManager();
}
protected override void CreateDefaultObjectSpaceProvider(CreateCustomObjectSpaceProviderEventArgs args) {
args.ObjectSpaceProvider = new SecuredObjectSpaceProvider((SecurityStrategyComplex)Security, 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 MySolutionAspNetApplication_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 MySolution.Module.MySolutionModule();
this.module4 = new MySolution.Module.Web.MySolutionAspNetModule();
this.securityModule1 = new DevExpress.ExpressApp.Security.SecurityModule();
this.securityStrategyComplex1 = new CustomSecurityStrategyComplex();
this.securityStrategyComplex1.SupportNavigationPermissionsForTypes = false;
this.authenticationStandard1 = new DevExpress.ExpressApp.Security.AuthenticationStandard();
this.conditionalAppearanceModule = new DevExpress.ExpressApp.ConditionalAppearance.ConditionalAppearanceModule();
this.validationModule = new DevExpress.ExpressApp.Validation.ValidationModule();
this.validationAspNetModule = new DevExpress.ExpressApp.Validation.Web.ValidationAspNetModule();
((System.ComponentModel.ISupportInitialize)(this)).BeginInit();
//
// securityStrategyComplex1
//
//this.securityStrategyComplex1.Authentication = this.authenticationStandard1;
this.securityStrategyComplex1.RoleType = typeof(DevExpress.Persistent.BaseImpl.PermissionPolicy.PermissionPolicyRole);
this.securityStrategyComplex1.NewUserRoleName = "Default";
// ApplicationUser descends from PermissionPolicyUser and supports OAuth authentication. For more information, refer to the following help topic: https://docs.devexpress.com/eXpressAppFramework/402197
// If your application uses PermissionPolicyUser or a custom user type, set the UserType property as follows:
this.securityStrategyComplex1.UserType = typeof(MySolution.Module.BusinessObjects.ApplicationUser);
//
// securityModule1
//
this.securityModule1.UserType = typeof(MySolution.Module.BusinessObjects.ApplicationUser);
//
// authenticationStandard1
//
this.authenticationStandard1.LogonParametersType = typeof(DevExpress.ExpressApp.Security.AuthenticationStandardLogonParameters);
// ApplicationUserLoginInfo is only necessary for applications that use the ApplicationUser user type.
// Comment out the following line if using PermissionPolicyUser or a custom user type.
this.authenticationStandard1.UserLoginInfoType = typeof(MySolution.Module.BusinessObjects.ApplicationUserLoginInfo);
//
// validationModule
//
this.validationModule.AllowValidationDetailsAccess = false;
//
// MySolutionAspNetApplication
//
this.ApplicationName = "MySolution";
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.Modules.Add(this.securityModule1);
this.Security = this.securityStrategyComplex1;
this.Modules.Add(this.conditionalAppearanceModule);
this.Modules.Add(this.validationModule);
this.Modules.Add(this.validationAspNetModule);
this.DatabaseVersionMismatch += new System.EventHandler<DevExpress.ExpressApp.DatabaseVersionMismatchEventArgs>(this.MySolutionAspNetApplication_DatabaseVersionMismatch);
((System.ComponentModel.ISupportInitialize)(this)).EndInit();
}
}
}