public sealed partial class MySolutionWindowsFormsModule : ModuleBase { private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Win"); e.Handled = true; } private void Application_CreateCustomUserModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), false, "Win"); e.Handled = true; } //... public override void Setup(XafApplication application) { base.Setup(application); application.CreateCustomModelDifferenceStore += Application_CreateCustomModelDifferenceStore; application.CreateCustomUserModelDifferenceStore += Application_CreateCustomUserModelDifferenceStore; } }
注意红色的代码:
1.MySolutionWindowsFormsModule 是指 你的项目.Module.Win这个project.
2.在setup中的2行代码增加事件,CreateCustomModelDifferenceStore 是指全局的模型设置信息。
3.CreateCustomUserModelDifferenceStore ,是指当前用户的模型信息。
4.e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Win"); 其中,true代表是否为全局设置,“win"代表平台,当然在web中,需要写"web"。web项目是:你的项目.Module.Web
public sealed partial class MySolutionAspNetModule : ModuleBase { private void Application_CreateCustomModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), true, "Web"); e.Handled = true; } private void Application_CreateCustomUserModelDifferenceStore(Object sender, CreateCustomModelDifferenceStoreEventArgs e) { e.Store = new ModelDifferenceDbStore((XafApplication)sender, typeof(ModelDifference), false, "Web"); e.Handled = true; } // ... public override void Setup(XafApplication application) { base.Setup(application); application.CreateCustomModelDifferenceStore += Application_CreateCustomModelDifferenceStore; application.CreateCustomUserModelDifferenceStore += Application_CreateCustomUserModelDifferenceStore; } }
下面有介绍如何启用管理UI。
如果你使用Entity Framework, 需要在DbContext中做如下声明:
using DevExpress.Persistent.BaseImpl.EF; // ... public class MyDbContext : DbContext { // ... public DbSet<ModelDifference> ModelDifferences { get; set; } public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; } }
另外,一定要确保所有用户都具有读/写访问 ModelDifference 和 ModelDifferenceAspect 类型的权限,否则有的权限模块会阻止这个行为成功执行。
下面是在代码中给权限的代码:
C# public class Updater : ModuleUpdater { public override void UpdateDatabaseAfterUpdateSchema() { base.UpdateDatabaseAfterUpdateSchema(); SecuritySystemRole defaultRole = ObjectSpace.FindObject<SecuritySystemRole>( new BinaryOperator("Name", "Default")); if(defaultRole == null) { defaultRole = ObjectSpace.CreateObject<SecuritySystemRole>(); // ... defaultRole.SetTypePermissionsRecursively<ModelDifference>( SecurityOperations.ReadWriteAccess, SecuritySystemModifier.Allow); defaultRole.SetTypePermissionsRecursively<ModelDifferenceAspect>( SecurityOperations.ReadWriteAccess, SecuritySystemModifier.Allow); // The 'Create' permission is additionally required if you use the Middle Tier Application Server defaultRole.SetTypePermissionsRecursively<ModelDifference>( SecurityOperations.Create, SecuritySystemModifier.Allow); defaultRole.SetTypePermissionsRecursively<ModelDifferenceAspect>( SecurityOperations.Create, SecuritySystemModifier.Allow); } sampleUser.Roles.Add(defaultRole); // ... ObjectSpace.CommitChanges(); } // ... }
在运行时,通过菜单打开模型差异管理的列表,可以看到相关的按钮。
在这里,会列出存在的用户的模型差异(用户打开一次程序后,就会保存该用户的模型差异),如果想为没有使用过程序的用户创建模型差异,可以单击创建模型差异。
如果想要加载共享的模式差异(就是在 Visual Studio (Model.xafml) 文件中创建的那个),可以点击导入共享模型差异。
另外三个按钮是:复制模型差异、 导出模型差异和重置模型差异 ,将应用于所选记录。
在模型的差异列表视图中,有一条共享模型差异的记录。它不是指某个用户的设置,而是指应用程序全局的设置。