How to: Store the Application Model Differences in the Database How to: model differences stored in a database application

When you create a new application with the Security System enabled in the Solution Wizard, the end-user settings (model differences) are stored in the database using the ModelDifferenceDbStore storage, by default. This topic describes how to enable this feature in an existing application, along with how to store shared model differences (administrator's settings) in the database.

When you Solution Wizard to create a new application-enabled security system, end-user settings (model differences) default ModelDifferenceDbStore stored in a database. This topic describes how to enable this functionality in existing applications, as well as how to store shared model differences in the database (administrator settings).

Note Note
Mobile applications do not allow you to store model differences in a database, so the approach described in this topic is not supported by the Mobile platform.
Mobile application does not allow storage model differences in the database, so the mobile platform approach described in this topic is not supported.
The System.Security.Principal.WindowsIdentity.GetCurrent().Name value is used as a user identifier (passed to the IModelDifference.UserId property) when the Security System is disabled. So, you can enable ModelDifferenceDbStore for WinForms applications with the disabled Security System using the approach described here. However, it is not recommended that you enable ModelDifferenceDbStore for unsecured ASP.NET applications, because the UserID will be the same for all users in this instance. Shared model differences are supported for both WinForms and ASP.NET when the Security System is disabled.
System security. .Windows body identification .GetCurrent (). When the safety system is disabled, the user name value is used as an identifier (attributes passed to IModelDifference.UserId). Therefore, you can use the method described here, the use of the disabled security system to enable the model for the difference DbStore WinForms applications. However, it is not recommended to enable ModelDifferenceDbStore for ASP.NET applications secure because users of all users in this instance are the same UserID. When disabled the security system, WinForms and ASP.NET support shared model differences.

Edit the WinModule.cs (WinModule.vb) file located in the WinForms module project. In the overridden ModuleBase.Setup method, subscribe to the XafApplication.CreateCustomModelDifferenceStore and XafApplication.CreateCustomUserModelDifferenceStore events. In these event handlers, pass the ModelDifferenceDbStore instance to the e.Store parameter. Pass the ModelDifference type to the ModelDifferenceDbStore constructor. Here, the ModelDifference is a built-in persistent object from the DevExpress.Persistent.BaseImpl namespace (for XPO) or from the DevExpress.Persistent.BaseImpl.EF namespace (for Entity Framework) implementing the IModelDifference interface. Note the constructor's contextId last parameter (used to initialize the IModelDifference.ContextId property). In the WinForms module, set it to "Win" to distinguish model differences created for the same user in different platforms.

Edit the module WinForms project WinModule.cs (WinModule.vb) files. In rewriting ModuleBase. Setup method, subscribe Xaf application. Creating a custom model differences in storage and Xaf applications. Creating a custom user model difference store events. In the event handler, the ModelDifferenceDbStore instance to e.Store parameters. The transfer model to the model type differences difference DbStore constructor. Here, ModelDifference from DevExpress. .BaseImpl persistent name space (XPO) or from DevExpress. .Baseimpl.EF persistent name space (Entity Framework) IModelDifference implement persistent objects built interface. Note that the last parameter constructor Context Id (IModelDifference.ContextId properties used to initialize). In WinForms module, set it to "Win", to distinguish differences in the model created for the same users on different platforms.

 

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;
    }
}

 

Analogously, edit the WebModule.cs (WebModule.vb) file located in the ASP.NET module project, but set the contextId parameter to "Web" instead of "Win".

Similarly, editing ASP.NET module project located in WebModule.cs (WebModule.vb) file, but the context of the Id parameter is set to "Web" instead of "Win". .

 

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;
    }
}

 

Note Note
When the CreateCustomModelDifferenceStore event is handled, the shared model differences (administrator settings) are stored in the database. Changes with the Model.xafml file located in the application project are ignored if the database record already exists for the shared model differences. To reload settings from Model.xafml, enable the administrative UI and use the Import Shared Model Difference Action (or delete the "Shared Model Difference" record and restart). If this behavior is inappropriate, do not handle this event. Handle it in the RELEASE project configuration only.
When the process "to create a custom model differences in storage" event, sharing model differences (administrator settings) will be stored in the database. If the shared model differences database record already exists, it ignores changes to the application project Model.xafml file. From Model.xafml reload settings, enable management UI and use the Import-sharing model difference operation (or delete records "shared model differences" and restart). If this behavior is not appropriate, do not handle this event. RELEASE only deal with it in the project configuration.

 

If you use the Entity Framework, register the ModelDifference and ModelDifferenceAspect entity types within your DbConext.

If you use Entity Framework, please register model differences and differences in model entity type in DbConext in.

 

using DevExpress.Persistent.BaseImpl.EF;
// ...
public class MyDbContext : DbContext {
    // ...
    public DbSet<ModelDifference> ModelDifferences { get; set; }
    public DbSet<ModelDifferenceAspect> ModelDifferenceAspects { get; set; }
}

 

I you use XPO, run the Module Designer and add the ModelDifference and ModelDifferenceAspect persistent types to the Exported Types section.

XPO use, operation of the module designer, and the difference between the model and the model of persistent differences in type to the "Export Type" section.

 

Ensure that all users have read/write access to ModelDifference and ModelDifferenceAspect types.

To ensure that all users have read / write access to model differences and differences in the type of model.

 

public class Updater : ModuleUpdater {
    public override void UpdateDatabaseAfterUpdateSchema() {
        base.UpdateDatabaseAfterUpdateSchema();

        PermissionPolicyRole defaultRole = ObjectSpace.FindObject<PermissionPolicyRole>(new BinaryOperator("Name", "Default"));
        if(defaultRole == null) {
            defaultRole = ObjectSpace.CreateObject<PermissionPolicyRole>();
            defaultRole.Name = "Default";
            defaultRole.AddObjectPermission<PermissionPolicyUser>(SecurityOperations.Read, "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
            defaultRole.AddNavigationPermission(@"Application/NavigationItems/Items/Default/Items/MyDetails", SecurityPermissionState.Allow);
            defaultRole.AddMemberPermission<PermissionPolicyUser>(SecurityOperations.Write, "ChangePasswordOnFirstLogon", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
            defaultRole.AddMemberPermission<PermissionPolicyUser>(SecurityOperations.Write, "StoredPassword", "[Oid] = CurrentUserId()", SecurityPermissionState.Allow);
            defaultRole.AddTypePermissionsRecursively<PermissionPolicyRole>(SecurityOperations.Read, SecurityPermissionState.Deny);
            defaultRole.AddTypePermissionsRecursively<ModelDifference>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
            defaultRole.AddTypePermissionsRecursively<ModelDifferenceAspect>(SecurityOperations.ReadWriteAccess, SecurityPermissionState.Allow);
            // The 'Create' permission is additionally required if you use the Middle Tier Application Server
            defaultRole.AddTypePermissionsRecursively<ModelDifference>(SecurityOperations.Create, SecurityPermissionState.Allow);
            defaultRole.AddTypePermissionsRecursively<ModelDifferenceAspect>(SecurityOperations.Create, SecurityPermissionState.Allow);                
        }
        sampleUser.Roles.Add(defaultRole);
        // ...
        ObjectSpace.CommitChanges();
    }
    // ...
}

 

Tip Tip
Refer to the How to: Enable the Administrative UI for managing Users' Model Differences topic to learn how to enable UI elements for managing Model Differences stored in the database.
See "How to: Enable Management UI to model differences in user management" topic, learn how to enable UI elements to manage the difference model stored in the database.
Note Note
The following combination of features is not supported when used together.
  • SecuredObjectSpaceProvider or XPObjectSpaceProvider created using the constructor with the threadSafe parameter set to true (this parameter enables the ThreadSafeDataLayer).
  • Application-wide model differences are stored in the database using the XafApplication.CreateCustomModelDifferenceStore event (you can still store user-specific differences in the database using the XafApplication.CreateCustomUserModelDifferenceStore event).
  • Custom Persistent Fields declared in the application-level model differences.
  • When used together, it does not support the following combination of features.
  • Use thread-safe parameter setting security object spaces created for constructors true provider or XPObjectSpaceProvider (This parameter enables thread-safe data layer).  
  • Model application range of the difference using XafApplication stored in the database. Xaf application. Creating a custom user model difference store events).   
  • Custom persistent fields declared in application-level model differences.
In this configuration, your application loads information on custom persistent fields from the database and then updates the database schema. However, a thread-safe data layer does not support altering the data model after the database connection is established.
In this configuration, the application is loaded from the database persistence custom information field, and then update the database schema. However, thread-safe data layer does not support changing the data model in the establishment of a database connection.

Guess you like

Origin www.cnblogs.com/foreachlife/p/How-to-Store-the-Application-Model-Differences-in-the-Database.html