The eXpressApp Framework is based on the modules concept. As a rule, every module implements a certain feature. Entities implemented in a module, such as persistent classes or extra Application Model nodes - can be customized by users of the application via the Model Editor. Such customizations are saved as Application Model differences in XafML files. Legacy Application Model differences might pose a problem when a module is updated to a new version, and its internal structure is changed. So, developers implementing modules should provide means to convert Application Model differences with new versions. The eXpressApp Frameworkprovides easy ways to implement such converters. This topic describes them.

Basically, Application Model differences are converted in two steps.

  1. The XafML files stored in XML format can be processed by a module implementing the IModelXmlConverter interface. This step allows the application to start correctly, where otherwise, legacy Application Model differences would cause an exception at the application start. In simple conversion scenarios, this may be the only required step.
  2. For complex conversion scenarios, special updaters implementing the IModelNodeUpdater<T> interface should be used. Such updaters can perform much more versatile conversions.

Depending on a particular scenario, you may need to perform either both of these steps or just one. So, for example, in one scenario you may need to implement an XML converter, so that the application could start, and a node updater, to perform a complex conversion. In other scenarios, you may need to implement only an XML converter or a node updater.

 

 Implement an XML converter

 

An XML converter is represented by a module implementing the IModelXmlConverter interface. The interface declares the IModelXmlConverter.ConvertXml method, which is invoked for each node customized in Application Model differences. The method takes the ConvertXmlParameters object, supplying differences as a parameter. You can handle changes to a node in the method's body, by converting differences and making them correspond to the actual model. Consider the following example.

Suppose your application uses a module which adds an OperatingMode string property to the Application Model's Options node. This property is designed to take either a "Simple" or "Complex" word as a value. Originally, the module extends the Application Model in the following way:

C#
VB
 
using DevExpress.ExpressApp.Model;

public interface IModelMyOptions{
string OperatingMode { get; set; }
}
public sealed partial class MyModule : ModuleBase {
//... 
public override void ExtendModelInterfaces(ModelInterfaceExtenders extenders) {
base.ExtendModelInterfaces(extenders);
extenders.Add<IModelOptions, IModelMyOptions>();
}
}

Users of your application customize this property value and it is stored to their Application Model differences. Then, the module is updated to a new version which introduces a couple of changes. First, the OperatingMode property type is changed to a newly introduced enumeration. Second, string representations of the new enumeration values are different from the previously used string values:

C#
VB
 
public interface IModelMyOptions {
OperatingMode OperatingMode { get; set; }
}
public enum OperatingMode { Basic, Advanced }

If you now recompile the application with the updated module and redistribute it, existing users will not be able to use the application. At the application start, a message will be displayed stating that an error has occurred while loading the Application Model differences. To avoid this, an XML converter should be implemented in the module. The following code snippet illustrates a possible solution:

C#
VB
 
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Updating; public sealed partial class MyModule : ModuleBase, IModelXmlConverter {
//... 
public void ConvertXml(ConvertXmlParameters parameters) {
if(typeof(IModelOptions).IsAssignableFrom(parameters.NodeType)) {
string property = "OperatingMode";
if(parameters.ContainsKey(property)) {
string value = parameters.Values[property];
if(!Enum.IsDefined(typeof(OperatingMode), value)) {
switch(value.ToLower()) {
case "complex":
parameters.Values[property] = OperatingMode.Advanced.ToString();
break;
default:
parameters.Values[property] = OperatingMode.Basic.ToString();
break;
}
}
}
}
}
}

The converter checks whether the currently processed node is the Options node. If it is, the converter checks whether the OperatingMode property has a legacy value. Then, the "Complex" value becomes OperatingMode.Advanced and all other values become OperatingMode.Basic.

Now, consider another very common scenario when a node's property is renamed. Suppose, a Mode property declared in the Options node was renamed to OperatingMode. The following code snippet illustrates a possible XML converter:

C#
VB
 
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Updating; public sealed partial class MyModule : ModuleBase, IModelXmlConverter {
//... 
public void ConvertXml(ConvertXmlParameters parameters) {
if(typeof(IModelOptions).IsAssignableFrom(parameters.NodeType)) {
string oldProperty = "Mode";
string newProperty = "OperatingMode";
if(parameters.ContainsKey(oldProperty)) {
parameters.Values[newProperty] = parameters.Values[oldProperty];
parameters.Values.Remove(oldProperty);
}
}
}
}

As illustrated by the examples, an XML converter works with one node at a time. So, complex conversions, affecting several nodes at once, are not possible. In these cases, special updaters implementing the IModelNodeUpdater<T> interface should be used.

 

 Implement a Node Updater

 

A node updater is represented by a class implementing the IModelNodeUpdater<T> interface. The generic type parameter specifies the type of the nodes for which the updater is intended. The interface declares a single IModelNodeUpdater<T>.UpdateNode method, which takes two parameters. The first parameter is the Application Model node in process, represented by an object implementing the IModelNode interface. The second parameter is the application's Application Model, represented by an object, implementing the IModelApplication interface. Since you have access to the whole Application Model, complex conversions affecting multiple nodes can be performed. Consider the following example.

Suppose your application uses a module which adds an OperatingMode string property to the Application Model's Options node. Originally, the interface extending the Application Model looks like this:

C#
VB
 
public interface IModelMyOptions {
OperatingMode OperatingMode { get; set; }
}
public enum OperatingMode { Basic, Advanced }

Then, the module is updated to a new version which moves the property to a newly introduced child node:

C#
VB
 
using DevExpress.ExpressApp.Model;

public interface IModelMyOptions {
IModelChildOptions ChildOptions { get; }
}
public interface IModelChildOptions : IModelNode {
OperatingMode OperatingMode { get; set; }
}
public enum OperatingMode { Basic, Advanced }

If you now recompile the application with the updated module and redistribute it, the original OperatingMode property values specified by users of the application will be lost. To avoid this, a node updater should be implemented. A possible place for the implementation is the updated module:

C#
VB
 
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Model.Core; public sealed partial class MyModule : ModuleBase, IModelNodeUpdater<IModelOptions> {
//... 
public void UpdateNode(IModelOptions node, IModelApplication application) {
string myProperty = "OperatingMode";
if(node.HasValue(myProperty)) {
string value = node.GetValue<string>(myProperty);
node.ClearValue(myProperty);
((IModelMyOptions)node).ChildOptions.OperatingMode =
(OperatingMode)Enum.Parse(typeof(OperatingMode), value);
}
}
}

The updater in the example checks whether the currently processed node has a legacy OperatingMode property value. If there is such a value, it is assigned to the new OperatingMode property, and the legacy property value is cleared.

Note that since a node updater can be implemented anywhere in the application, the updater should be registered via the ModuleBase.AddModelNodeUpdaters method:

C#
VB
 
using DevExpress.ExpressApp.Model;
using DevExpress.ExpressApp.Model.Core; public sealed partial class MyModule : ModuleBase, IModelNodeUpdater<IModelOptions> {
//... 
public override void AddModelNodeUpdaters(IModelNodeUpdaterRegistrator updaterRegistrator) {
base.AddModelNodeUpdaters(updaterRegistrator);
updaterRegistrator.AddUpdater<IModelOptions>(this);
}
}

Convert Application Model Differences的更多相关文章

  1. Core - Provide an easy way to store administrator and user model differences in a custom store (e.g., in a database)

    https://www.devexpress.com/Support/Center/Question/Details/S32444/core-provide-an-easy-way-to-store- ...

  2. Implement Property Value Validation in the Application Model 在应用程序模型中实现属性值验证

    In this lesson, you will learn how to check whether or not a property value satisfies a particular r ...

  3. How to map Actions to a certain RibbonPage and RibbonGroup using the Application Model or in code

    https://www.devexpress.com/Support/Center/Question/Details/S134617/how-to-map-actions-to-a-certain-r ...

  4. Windows Forms Application Creation and Initialization

    Windows Forms Application Creation and Initialization This topic details the steps performed after a ...

  5. ASP.NET Application Life Cycle

    The table in this topic details the steps performed while an XAF ASP.NET application is running. Not ...

  6. Unit Testing a zend-mvc application

    Unit Testing a zend-mvc application A solid unit test suite is essential for ongoing development in ...

  7. 【转载】Using the Web Service Callbacks in the .NET Application

    来源 This article describes a .NET Application model driven by the Web Services using the Virtual Web ...

  8. TensorFlow Lite demo——就是为嵌入式设备而存在的,底层调用NDK神经网络API,注意其使用的tf model需要转换下,同时提供java和C++ API,无法使用tflite的见后

    Introduction to TensorFlow Lite TensorFlow Lite is TensorFlow’s lightweight solution for mobile and ...

  9. [AngularJS] 5 simple ways to speed up your AngularJS application

    Nowdays, Single page apps are becoming increasingly popular among the fornt-end developers. It is th ...

随机推荐

  1. __iter__的有无

    迭代器和生成器 1.迭代器 我们之前⼀直在⽤可迭代对象进⾏迭代操作. 那么到底什么是可迭代对象.⾸先我们先回顾⼀下⽬前我们所熟知的可迭代对象有哪些: str, list, tuple, dict, s ...

  2. Centos7.3 坑爹网络配置

    1.目的: 我想在Vmvare配置成NAT模式的上网,因为这个模式宿主机可以访问虚拟机,虚拟机也可以访问宿主机,但仅主机模式只能是宿主机能访问虚拟机,但虚拟机不能访问宿主机.所以我为了能在虚拟机里面上 ...

  3. 操作系统的三个接口 shell gui api

    操作系统的三个接口 shell gui api 编程语言是用来告诉操作系统干什么的语言. 编程语言是人机交互语言. 程序.进程:任务集.

  4. 1562. [NOI2009]变换序列【二分图】

    Description Input Output Sample Input 5 1 1 2 2 1 Sample Output 1 2 4 0 3 HINT 30%的数据中N≤50: 60%的数据中N ...

  5. 1070. [SCOI2007]修车【费用流】

    Description 同一时刻有N位车主带着他们的爱车来到了汽车维修中心.维修中心共有M位技术人员,不同的技术人员对不同 的车进行维修所用的时间是不同的.现在需要安排这M位技术人员所维修的车及顺序, ...

  6. Android攻城狮学习笔记-进阶篇一

    点击快速抵达: 第1章 AndroidManifest配置文件 第2章 使用ListView显示信息列表 第3章 使用DatePicker及TimePicker显示当前日期和时间 第4章 使用Grid ...

  7. P1877 [HAOI2012]音量调节

    题目描述 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都需要改变一次音量.在演出开始之前,他已经做好一个列表,里面写着每首歌开始之前他想要改变的音量是多少. ...

  8. CANOPEN开发问题

    我是一名研二的学生,现在教研室要开发canopen,我已经看了几个月了,在网上找了canopen的开源代码CANfestival,现在想做移植,有几个问题想要请教:1,开发主站,只买beckhoff的 ...

  9. vbs获取当前主机IP

    Function GetIP GetIP = ""        Dim objWMIService, colAdapters, objAdapter    strComputer ...

  10. C++之指针指向二维数组

    一维指针通经常使用指针表示,其指向的地址是数组第一元素所在的内存地址,例如以下 int ary[4][5]; int(*aryp)[5] = ary; 那么ary[4]相当于int(*aryp).下面 ...