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) 文件中創建的那個),可以點擊導入共享模型差異。
另外三個按鈕是:復制模型差異、 導出模型差異和重置模型差異 ,將應用于所選記錄。
在模型的差異列表視圖中,有一條共享模型差異的記錄。它不是指某個用戶的設置,而是指應用程序全局的設置。
文章列表