实现动态数据导入工具有什么好的设计模式?

时间:2021-04-19 13:04:55

We are planning to build a dynamic data import tool. Basically taking information on one end in a specified format (access, excel, csv) and upload it into an web service.

我们计划构建一个动态数据导入工具。基本上以指定格式(access,excel,csv)在一端获取信息并将其上载到Web服务中。

The situation is that we do not know the export field names, so the application will need to be able to see the wsdl definition and map to the valid entries in the other end.

情况是我们不知道导出字段名称,因此应用程序需要能够查看wsdl定义并映射到另一端的有效条目。

In the import section we can define most of the fields, but usually they have a few that are custom. Which I see no problem with that.

在导入部分,我们可以定义大多数字段,但通常它们有一些是自定义的。我认为没有问题。

I just wonder if there is a design pattern that will fit this type of application or help with the development of it.

我只是想知道是否有适合此类应用程序的设计模式或帮助开发它。

5 个解决方案

#1


I am not sure where the complexity is in your application, so I will just give an example of how I have used patterns for importing data of different formats. I created a factory which takes file format as argument and returns a parser for particular file format. Then I use the builder pattern. The parser is provided with a builder which the parser calls as it is parsing the file to construct desired data objects in application.

我不确定应用程序的复杂性在哪里,所以我将举例说明我如何使用模式导入不同格式的数据。我创建了一个工厂,它将文件格式作为参数,并返回特定文件格式的解析器。然后我使用构建器模式。解析器提供有一个构建器,解析器在解析文件时调用该构建器以在应用程序中构造所需的数据对象。

// In this example file format describes a house (complex data object)
AbstractReader reader = factory.createReader("name of file format");
AbstractBuilder builder = new HouseBuilder(list_of_houses);
reader.import(text_stream, builder);

// now the list_of_houses should contain an extra house
// as defined in the text_stream

#2


I would say the Adaptor Pattern, as you are "adapting" the data from a file to an object, like the SqlDataDataAdapter does it from a Sql table to a DataTable

我会说适配器模式,因为你正在“调整”从文件到对象的数据,就像SqlDataDataAdapter从Sql表到DataTable一样

have a different Adaptor for each file type/format? example SqlDataAdptor, MySqlDataAdapter, they handle the same commands but different datasources, to achive the same output DataTable

每种文件类型/格式都有不同的适配器?示例SqlDataAdptor,MySqlDataAdapter,它们处理相同的命令但不同的数据源,以获得相同的输出DataTable

Adaptor pattern

HTH

Bones

#3


Probably Bridge could fit, since you have to deal with different file formats. And Façade to simplify the usage. Handle my reply with care, I'm just learning design patterns :)

可能Bridge很适合,因为你必须处理不同的文件格式。和Façade简化用法。小心处理我的回复,我只是学习设计模式:)

#4


You will probably also need Abstract Factory and Command patterns.

您可能还需要抽象工厂和命令模式。

If the data doesn't match the input format you will probably need to transform it somehow. That's where the command pattern come in. Because the formats are dynamic, you will need to base the commands you generate off of the input. That's where Abstract factory is useful.

如果数据与输入格式不匹配,您可能需要以某种方式对其进行转换。这就是命令模式的用武之地。由于格式是动态的,因此您需要根据输入生成命令。这就是抽象工厂有用的地方。

#5


Our situation is that we need to import parametric shapes from competitors files. The layout of their screen and data fields are similar but different enough so that there is a conversion process. In addition we have over a half dozen competitor and maintenance would be a nightmare if done through code only. Since most of them use tables to store their parameters for their shapes we wrote a general purpose collection of objects to convert X into Y.

我们的情况是我们需要从竞争对手的文件中导入参数形状。它们的屏幕和数据字段的布局相似但足够不同,因此存在转换过程。此外,我们有超过六打竞争对手,如果仅通过代码进行维护将是一场噩梦。由于他们中的大多数使用表来存储他们的形状参数,我们编写了一个通用的对象集合来将X转换为Y.

In my CAD/CAM application the file import is a Command. However the conversion magic is done by a Ruleset via the following steps.

在我的CAD / CAM应用程序中,文件导入是一个命令。但是,转换魔法由规则集通过以下步骤完成。

  1. Import the data into a table. The field names are pulled in as well depending on the format.
  2. 将数据导入表中。根据格式,字段名称也会被拉入。

  3. We pass the table to a RuleSet. I will explain the structure the ruleset in a minute.
  4. 我们将表传递给RuleSet。我将在一分钟内解释规则集的结构。

  5. The Ruleset transform the data into a new set of objects (or tables) which we retrieve
  6. 规则集将数据转换为我们检索的一组新对象(或表)

  7. We pass the result to the rest of the software.
  8. 我们将结果传递给软件的其余部分。

A RuleSet is comprise of set of Rules. A Rule can contain another Rule. A rule has a CONDITION that it tests, and a MAP TABLE.

RuleSet由一组规则组成。规则可以包含另一个规则。规则具有它测试的CONDITION和MAP TABLE。

The MAP TABLE maps the incoming field with a field (or property) in the result. There are can be one mapping or a multitude. The mapping doesn't have to involve just poking the input value into a output field. We have a syntax for calculation and string concatenation as well.

MAP TABLE将传入字段与结果中的字段(或属性)进行映射。可以有一个映射或多个。映射不必仅涉及将输入值戳入输出字段。我们还有一个计算和字符串连接的语法。

This syntax is also used in the Condition and can incorporate multiple files like ([INFIELD1] & "-" & [INFIELD2])="A-B" or [DIM1] + [DIM2] > 10. Anything between the brackets is substituted with a incoming field.

此语法也用于条件,并且可以合并多个文件,如([INFIELD1]&“ - ”&[INFIELD2])=“AB”或[DIM1] + [DIM2]> 10.括号内的任何内容都替换为传入的领域。

Rules can contain other Rules. The way this works is that in order for a sub Rule mapping to apply both it's condition and those of it's parent (or parents) have to be true. If a subRule has a mapping that conflicts with a parent's mapping then the subRule Mapping applies.

规则可以包含其他规则。这种方法的工作方式是,为了使子规则映射同时应用它的条件,并且它的父级(或父级)的条件必须为真。如果subRule的映射与父映射冲突,则应用subRule映射。

If two Rules on the same level have condition that are true and have conflicting mapping then the rule with the higher index (or lower on the list if you are looking at tree view) will have it's mapping apply.

如果同一级别上的两个规则具有真实且具有冲突映射的条件,则具有较高索引的规则(如果您正在查看树视图,则列表中的较低规则)将应用它的映射。

Nested Rules is equivalent to ANDs while rules on the same level are equivalent of ORs.

嵌套规则等同于AND,而同一级别的规则等同于OR。

The result is a mapping table that is applied to the incoming data to transform it to the needed output.

结果是一个映射表,应用于传入数据以将其转换为所需的输出。

It is amicable to be being displayed in a UI. Namely a Treeview showing the rules hierarchy and a side panel showing the mapping table and conditions of the rule. Just as importantly you can create wizards that automate common rule structures.

在UI中显示是友好的。即显示规则层次结构的Treeview和显示规则的映射表和条件的侧面板。同样重要的是,您可以创建自动执行常见规则结构的向导。

#1


I am not sure where the complexity is in your application, so I will just give an example of how I have used patterns for importing data of different formats. I created a factory which takes file format as argument and returns a parser for particular file format. Then I use the builder pattern. The parser is provided with a builder which the parser calls as it is parsing the file to construct desired data objects in application.

我不确定应用程序的复杂性在哪里,所以我将举例说明我如何使用模式导入不同格式的数据。我创建了一个工厂,它将文件格式作为参数,并返回特定文件格式的解析器。然后我使用构建器模式。解析器提供有一个构建器,解析器在解析文件时调用该构建器以在应用程序中构造所需的数据对象。

// In this example file format describes a house (complex data object)
AbstractReader reader = factory.createReader("name of file format");
AbstractBuilder builder = new HouseBuilder(list_of_houses);
reader.import(text_stream, builder);

// now the list_of_houses should contain an extra house
// as defined in the text_stream

#2


I would say the Adaptor Pattern, as you are "adapting" the data from a file to an object, like the SqlDataDataAdapter does it from a Sql table to a DataTable

我会说适配器模式,因为你正在“调整”从文件到对象的数据,就像SqlDataDataAdapter从Sql表到DataTable一样

have a different Adaptor for each file type/format? example SqlDataAdptor, MySqlDataAdapter, they handle the same commands but different datasources, to achive the same output DataTable

每种文件类型/格式都有不同的适配器?示例SqlDataAdptor,MySqlDataAdapter,它们处理相同的命令但不同的数据源,以获得相同的输出DataTable

Adaptor pattern

HTH

Bones

#3


Probably Bridge could fit, since you have to deal with different file formats. And Façade to simplify the usage. Handle my reply with care, I'm just learning design patterns :)

可能Bridge很适合,因为你必须处理不同的文件格式。和Façade简化用法。小心处理我的回复,我只是学习设计模式:)

#4


You will probably also need Abstract Factory and Command patterns.

您可能还需要抽象工厂和命令模式。

If the data doesn't match the input format you will probably need to transform it somehow. That's where the command pattern come in. Because the formats are dynamic, you will need to base the commands you generate off of the input. That's where Abstract factory is useful.

如果数据与输入格式不匹配,您可能需要以某种方式对其进行转换。这就是命令模式的用武之地。由于格式是动态的,因此您需要根据输入生成命令。这就是抽象工厂有用的地方。

#5


Our situation is that we need to import parametric shapes from competitors files. The layout of their screen and data fields are similar but different enough so that there is a conversion process. In addition we have over a half dozen competitor and maintenance would be a nightmare if done through code only. Since most of them use tables to store their parameters for their shapes we wrote a general purpose collection of objects to convert X into Y.

我们的情况是我们需要从竞争对手的文件中导入参数形状。它们的屏幕和数据字段的布局相似但足够不同,因此存在转换过程。此外,我们有超过六打竞争对手,如果仅通过代码进行维护将是一场噩梦。由于他们中的大多数使用表来存储他们的形状参数,我们编写了一个通用的对象集合来将X转换为Y.

In my CAD/CAM application the file import is a Command. However the conversion magic is done by a Ruleset via the following steps.

在我的CAD / CAM应用程序中,文件导入是一个命令。但是,转换魔法由规则集通过以下步骤完成。

  1. Import the data into a table. The field names are pulled in as well depending on the format.
  2. 将数据导入表中。根据格式,字段名称也会被拉入。

  3. We pass the table to a RuleSet. I will explain the structure the ruleset in a minute.
  4. 我们将表传递给RuleSet。我将在一分钟内解释规则集的结构。

  5. The Ruleset transform the data into a new set of objects (or tables) which we retrieve
  6. 规则集将数据转换为我们检索的一组新对象(或表)

  7. We pass the result to the rest of the software.
  8. 我们将结果传递给软件的其余部分。

A RuleSet is comprise of set of Rules. A Rule can contain another Rule. A rule has a CONDITION that it tests, and a MAP TABLE.

RuleSet由一组规则组成。规则可以包含另一个规则。规则具有它测试的CONDITION和MAP TABLE。

The MAP TABLE maps the incoming field with a field (or property) in the result. There are can be one mapping or a multitude. The mapping doesn't have to involve just poking the input value into a output field. We have a syntax for calculation and string concatenation as well.

MAP TABLE将传入字段与结果中的字段(或属性)进行映射。可以有一个映射或多个。映射不必仅涉及将输入值戳入输出字段。我们还有一个计算和字符串连接的语法。

This syntax is also used in the Condition and can incorporate multiple files like ([INFIELD1] & "-" & [INFIELD2])="A-B" or [DIM1] + [DIM2] > 10. Anything between the brackets is substituted with a incoming field.

此语法也用于条件,并且可以合并多个文件,如([INFIELD1]&“ - ”&[INFIELD2])=“AB”或[DIM1] + [DIM2]> 10.括号内的任何内容都替换为传入的领域。

Rules can contain other Rules. The way this works is that in order for a sub Rule mapping to apply both it's condition and those of it's parent (or parents) have to be true. If a subRule has a mapping that conflicts with a parent's mapping then the subRule Mapping applies.

规则可以包含其他规则。这种方法的工作方式是,为了使子规则映射同时应用它的条件,并且它的父级(或父级)的条件必须为真。如果subRule的映射与父映射冲突,则应用subRule映射。

If two Rules on the same level have condition that are true and have conflicting mapping then the rule with the higher index (or lower on the list if you are looking at tree view) will have it's mapping apply.

如果同一级别上的两个规则具有真实且具有冲突映射的条件,则具有较高索引的规则(如果您正在查看树视图,则列表中的较低规则)将应用它的映射。

Nested Rules is equivalent to ANDs while rules on the same level are equivalent of ORs.

嵌套规则等同于AND,而同一级别的规则等同于OR。

The result is a mapping table that is applied to the incoming data to transform it to the needed output.

结果是一个映射表,应用于传入数据以将其转换为所需的输出。

It is amicable to be being displayed in a UI. Namely a Treeview showing the rules hierarchy and a side panel showing the mapping table and conditions of the rule. Just as importantly you can create wizards that automate common rule structures.

在UI中显示是友好的。即显示规则层次结构的Treeview和显示规则的映射表和条件的侧面板。同样重要的是,您可以创建自动执行常见规则结构的向导。