How to: Allow an Administrator to Create Custom Persistent Fields in an XPO-Based Application How to: XPO allows administrators to create applications based custom persistence fields

You can allow an application administrator to create custom persistent fields and display the added fields' data in the UI without recompiling the application. In this example, the SkypeID field will be added to the Contact business object in the MainDemo application.

You can allow administrators to create custom applications persistent fields, and add data fields displayed in the UI, without having to recompile the application. In this example, SkypeID field will be added to the MainDemo application "Contacts" business objects.

CustomPersistentFields_Result

The following sections describe the process of implementation custom persistent fields from application settings to runtime customization.

  • Prerequisites
  • Setup the Application
  • Choose the Model Editor Type
  • Implement the Persistent Field and Display It
  • Apply Changes to the Database

 

The following sections describe the settings from the application process to achieve a custom run-time custom persistent fields.

  • prerequisites
  • Setting Application
  • Select the model type of editor
  • Lasting field and display it
  • The changes to the database

Prerequisites

prerequisites

Ensure that your application does not contradict the following conditions. Otherwise, creating new persistent fields is impossible at runtime.

  • WinForms and ASP.NET applications should be based on the XPO data model.
  • Mobile applications do not support UI customization without recompilation, so the approach described in this topic is not supported by the Mobile platform.
  • The following features should not be used together.

  • SecuredObjectSpaceProvider or XPObjectSpaceProvider created using the constructor with the threadSafe parameter set to true (this parameter enables ThreadSafeDataLayer).
  • An Administrator's Model Differences stored in the database using the XafApplication.CreateCustomModelDifferenceStore event (you can still store the User's differences in the database using the XafApplication.CreateCustomUserModelDifferenceStore event).
  • Custom Persistent Fields declared in the Administrator's Model Differences.

Make sure that your application is not inconsistent with the following conditions. Otherwise, you can not create a new persistent fields at runtime.

  • WinForms and ASP.NET applications XPO data model should be based.
  • Mobile application does not support custom UI without recompilation, so the mobile platform approach described in this topic is not supported.
  • The following features should not be used together.
  • Use thread-safe parameter setting security object spaces created for constructors true provider or XPObjectSpaceProvider (This parameter enables thread-safe data layer).
  • Administrators use the model differences Xaf applications are stored in the database. Creating custom model difference store event (you can still use the application user Xaf differences stored in the database. Event).
  • Custom persistent fields declared in the model differences in the administrator's.

 

With 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.

  • Middle Tier Security - WCF Service, Workflow Server Service, or any other appllication that creates and configures a ServerApplication/XafApplication cannot access custom fields added in the client XAF application project (in code or in XAFML), or by customizing the application model at runtime. You should add a custom field in a common module and reference it in all applications where you are going to use it.

With this configuration, the application from the database to load custom persistence 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.

  • Security interlayer - WCF services, workflow server service, or any other to create and configure server applications / Application Application Xaf application can not access the client XAF application project to add custom fields (in code or in XAFML in), also can not customize the application model at runtime. You should add custom fields in a common module, and reference the field in all the applications you want to use.

Setup the Application

Setting Application

Apply the following changes in the application code to allow application administrators to create and display custom persistent field data in the UI.

  • Set the static ModelMemberReadOnlyCalculator.AllowPersistentCustomProperties property to true to allow creating persistent fields at runtime. Open the Module.cs (Module.vb) file and add the following code to the module's constructor.

Apply the following changes in the application code to allow application administrators to create and display custom persistent fields of data in the UI.

  • The static model member ReadOnly calculator allows lasting Custom Attributes property is set to true, in order to create a persistent field at run time. Open Module.cs (module.vb) file, add the following code to the constructor module.
DevExpress.ExpressApp.Model.Core.ModelMemberReadOnlyCalculator.AllowPersistentCustomProperties = true;
  • Set the IObjectSpaceProvider.CheckCompatibilityType property to CheckCompatibilityType.DatabaseSchema to catch the database changes and update the database if the schema is modified.

  • The IObjectSpaceProvider.Check type compatibility property to CheckCompatibilityType. Database schema to capture database changes, and updates the database when you modify the schema.

    CheckCompatibilityType

  • To allow the database schema updates, set the XafApplication.DatabaseUpdateMode property to DatabaseUpdateMode.UpdateDatabaseAlways or DatabaseUpdateMode.UpdateOldDatabase.
  • Copy the DBUpdater.v19.2.exe and DBUpdater.v19.2.config files from the %PROGRAMFILES(x86)%\DevExpress 19.2\Components\Tools\eXpressAppFramework\DBUpdater\ folder to the application's installation folder.
  • 要允许数据库架构更新,请将 XafApplication.DatabaseUpdateMode 属性设置为数据库更新模式.始终更新数据库或数据库更新模式。更新旧数据库。
  • 将 DBUpdater.v19.2.exe 和 DBUpdater.v19.2.config 文件从 %PROGRAMFILES(x86)%_DevExpress 19.2_组件_工具_eXpressAppFramework_DBUpdater_文件夹复制到应用程序的安装文件夹。

Choose the Model Editor Type

选择模型编辑器类型

It is necessary to determine which type of the Model Editor is appropriate for your application: standalone or built-in.

  • A built-in Model Editor

    When an administrator uses a WinForms application, it is possible to invoke the built-in Model Editor tool to add a custom field to the application model. Using this Model Editor type, the administrator can edit both Model Differences stored in the application database and Model Differences from the XAFML file.

  • A standalone Model Editor

    The use of the standalone Model Editor is preferred if an administrator uses only an ASP.NET application and Model Differences are stored in the XAFML file. For information on how to use this tool, refer to the Deploy and Run the Standalone Model Editor section of the Ways to Invoke the Model Editor topic.

Implement the Persistent Field and Display It

Follow the steps below to add a custom persistent field at an end-user workstation.

  1. Invoke the built-in Model Editor using the Tools | Edit Model command at runtime or close the application and start the standalone Model Editor by running the DevExpress.ExpressApp.ModelEditor.v19.2.exe executable file.

    If you use the standalone Model Editor, specify the path to the application configuration file (e.g., MainDemo.Win.exe.config or Web.config) and click Open in the Open Model dialog.

    CustomPersistentFields_RunME

  2. Navigate to the BO_Model | Contact node in the tree on the left. Right-click the OwnMembers child node and choose Add... | Member.

    CustomPersistentFields_AddMember

  3. Set the Name property of the newly added node to "SkypeID". Then, set the IsCalculated property to "False", Type to "System.String", Size to "32", and Caption to "Skype ID".

    CustomPersistentFields_MemberProperties

  4. If the built-in Model Editor is in use, copy the differences that you have introduced in the administrator's layer using the Merge Differences command. Otherwise, skip this step and move to the next one.

    CustomPersistentFields_Merge

  5. Save changes using the Save button or the CTRL+S shortcut and restart the Model Editor.
  6. Navigate to the Views | Contact_DetailView node in the tree on the left. Right-click the Items child node and choose Add... | PropertyEditor.

    CustomPersistentFields_AddEditor1

  7. Set PropertyName and Id to "SkypeID".

    CustomPersistentFields_AddEditor2

  8. Focus the Layout node. Right-click the empty space within the form preview displayed on the right and select Customize Layout.

    CustomPersistentFields_AddEditor3

  9. Drag the Skype ID item from the invoked Customization window to an appropriate position within the form.

    CustomPersistentFields_AddEditor4

    You can also add the Skype ID column to the Contact List View using a similar approach (see List View Columns Customization).

  10. If the built-in Model Editor is in use, merge the differences as described at the forth step.
  11. Save the changes and close the Model Editor.
  12. Update your database schema as described in the Apply Changes to the Database section.
  13. Restart the application and open the Contact Detail View to see the result demonstrated in the introduction of this topic.
Important

If the application is installed on several PCs and the Administrator's Model Differences are stored in the Model.xafml file, copy it from the application's working folder to each PC. Otherwise, the created field will be available only at the workstation where you added it.

Apply Changes to the Database

Use the DBUpdater tool to add the column mapped to the newly created custom persistent field to the database.

Open the Command Prompt, change the current directory to the applications working directory, and run the following command.

DBUpdater.v19.2.exe MainDemo.Win.exe.config -forceUpdate

Guess you like

Origin www.cnblogs.com/foreachlife/p/12073128.html