{"id":151,"date":"2011-09-21T12:20:18","date_gmt":"2011-09-21T10:20:18","guid":{"rendered":"https:\/\/blog.avxt.fr\/?p=151"},"modified":"2011-10-18T15:12:09","modified_gmt":"2011-10-18T13:12:09","slug":"master-data-services-business-rules-copy-import-export-cross-model","status":"publish","type":"post","link":"https:\/\/blog.avxt.fr\/fr\/master-data-services-business-rules-copy-import-export-cross-model\/","title":{"rendered":"Master Data Services : Copie \/ Import \/ Export des Business Rules (Inter mod\u00e8les)"},"content":{"rendered":"<p><span style=\"color: #ff0000;\">updated article (Oct 2011)<\/span><\/p>\n<p><span style=\"color: #ff0000;\">(code refactored)<\/span><\/p>\n<p>Hi All,<\/p>\n<p>One other missing feature of MDS is Import \/ Export \/ Copy Business rules from a model to another (or copy business rules to the same model)<\/p>\n<p>my code is still in beta, but it is already (partially) working.<\/p>\n<p>you can find it on my \u00ab\u00a0MDS Manager\u00a0\u00bb tool on codeplex:<\/p>\n<p><a href=\"http:\/\/mdsmanager.codeplex.com\">http:\/\/mdsmanager.codeplex.com<\/a><\/p>\n<p><a href=\"https:\/\/blog.avxt.fr\/wp-content\/uploads\/2011\/09\/ScreenShot555.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-152\" title=\"ScreenShot555\" src=\"https:\/\/blog.avxt.fr\/wp-content\/uploads\/2011\/09\/ScreenShot555.jpg\" alt=\"\" width=\"474\" height=\"727\" srcset=\"https:\/\/blog.avxt.fr\/wp-content\/uploads\/2011\/09\/ScreenShot555.jpg 474w, https:\/\/blog.avxt.fr\/wp-content\/uploads\/2011\/09\/ScreenShot555-195x300.jpg 195w\" sizes=\"auto, (max-width: 474px) 100vw, 474px\" \/><\/a><br \/>\nGet business rules from modelId, quite easy with service client method \u00ab\u00a0business rules get\u00a0\u00bb, returns a business rule set<\/p>\n<pre class=\"brush:c#\"> public BusinessRules GetBusinessRules(string fileName)\r\n        {\r\n            BusinessRules brs = null;\r\n            Stream str = null;\r\n            try\r\n            {\r\n\r\n                if (File.Exists(fileName))\r\n                {\r\n                    str = new FileStream(@fileName, FileMode.Open, FileAccess.Read, FileShare.Read);\r\n\r\n                    if (str == null)\r\n                    {\r\n                        throw new BusinessRulesException(\"error while opening file!\");\r\n                    }\r\n\r\n                    XmlSerializer xs = new XmlSerializer(typeof(BusinessRules));\r\n                    \/\/ Load the object saved above by using the Deserialize function\r\n                     brs = (BusinessRules)xs.Deserialize(str);\r\n\r\n                }\r\n                else\r\n                {\r\n                    throw new BusinessRulesException(\"Cannot find specified file!\");\r\n                }\r\n\r\n                return brs;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                throw ex;\r\n            }\r\n            finally\r\n            {\r\n\r\n                \/\/ Cleanup                 if (str != null)\r\n                    str.Close();\r\n\r\n            }\r\n\r\n        }<\/pre>\n<pre>then we export business rules to a XML file<\/pre>\n<pre>note:<\/pre>\n<pre>\/\/this is needed to avoid a serialization error (more info on <a title=\"http:\/\/www.johnsoer.com\/blog\/?p=125\" href=\"http:\/\/www.johnsoer.com\/blog\/?p=125\" target=\"_blank\">http:\/\/www.johnsoer.com\/blog\/?p=125<\/a> ) :<\/pre>\n<pre> \/\/XmlSerializer xs = new XmlSerializer(typeof(BusinessRules), new Type[] { typeof(BRAttributeValueArgument),typeof(BRBlankArgument)\r\n   \/\/                                                                                     ,typeof(BRDomainBasedAttributeArgument)});<\/pre>\n<pre>here is the export method :<\/pre>\n<pre class=\"brush:c#\"> public void ExportBusinessRules(string exportFileName, BusinessRules brs)\r\n        {\r\n            TextWriter WriteFileStream = null;\r\n            try\r\n            {<\/pre>\n<p>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<del><span style=\"color: #339966;\">\u00a0\/\/new\u00a0type\u00a0needed\u00a0to\u00a0avoir\u00a0error\u00a0because\u00a0serialization\u00a0of\u00a0an\u00a0inherited\u00a0class\u00a0<\/span> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0XmlSerializer\u00a0xs\u00a0=\u00a0new\u00a0XmlSerializer(typeof(BusinessRules),\u00a0new\u00a0Type[]\u00a0{\u00a0typeof(Common.ServiceReference1.BRAttributeValueArgument)\u00a0});<\/del><br \/>\n<span style=\"color: #ff0000;\">\/\/update oct 2011!<\/span><br \/>\n \/\/new type needed to avoir error because serialization of an inherited class <\/p>\n<pre class=\"brush:c#\">               XmlSerializer xs = new XmlSerializer(typeof(BusinessRules), new Type[] { typeof(BRAttributeValueArgument),typeof(BRBlankArgument)\r\n                                                                                        ,typeof(BRDomainBasedAttributeArgument)});<\/pre>\n<pre class=\"brush:c#\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Create\u00a0a\u00a0new\u00a0file\u00a0stream\u00a0to\u00a0write\u00a0the\u00a0serialized\u00a0object\u00a0to\u00a0a\u00a0file \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WriteFileStream\u00a0=\u00a0new\u00a0StreamWriter(@exportFileName);\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0xs.Serialize(WriteFileStream,\u00a0brs);\r\n\r\n               \/\/custom exception class , but not required \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0new\u00a0BusinessRulesException(\"Business\u00a0Rules\u00a0successfully\u00a0exported\u00a0to\u00a0file\u00a0\"\u00a0+\u00a0exportFileName);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0catch\u00a0(Exception\u00a0exc)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0exc;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0finally\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Cleanup \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(WriteFileStream\u00a0!=\u00a0null)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0WriteFileStream.Close();\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<pre><\/pre>\n<pre>then we would like to import this XML file to another model:<\/pre>\n<pre>here is the method to get business rules set from a previously exported XML file :<\/pre>\n<pre class=\"brush:c#\">\u00a0\u00a0public\u00a0BusinessRules\u00a0GetBusinessRules(string\u00a0fileName)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0BusinessRules\u00a0brs\u00a0=\u00a0null;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0Stream\u00a0str\u00a0=\u00a0null;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0try\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(File.Exists(fileName))\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0str\u00a0=\u00a0new\u00a0FileStream(@fileName,\u00a0FileMode.Open,\u00a0FileAccess.Read,\u00a0FileShare.Read);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(str\u00a0==\u00a0null)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0new\u00a0BusinessRulesException(\"error\u00a0while\u00a0opening\u00a0file!\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0XmlSerializer\u00a0xs\u00a0=\u00a0new\u00a0XmlSerializer(typeof(BusinessRules));\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Load\u00a0the\u00a0object\u00a0saved\u00a0above\u00a0by\u00a0using\u00a0the\u00a0Deserialize\u00a0function \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0brs\u00a0=\u00a0(BusinessRules)xs.Deserialize(str);\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0else\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0new\u00a0BusinessRulesException(\"Cannot\u00a0find\u00a0specified\u00a0file!\");\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0return\u00a0brs;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0catch\u00a0(Exception\u00a0ex)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0ex;\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0finally\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\/\/\u00a0Cleanup \r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0if\u00a0(str\u00a0!=\u00a0null)\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0str.Close();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}<\/pre>\n<pre><\/pre>\n<pre><span style=\"color: #339966;\">\/\/then we can get the source modelID<\/span><\/pre>\n<pre>\u00a0sourceModelId\u00a0=brs.BusinessRulesMember.First().Identifier.ModelId\u00a0as\u00a0Identifier;<\/pre>\n<pre><span style=\"color: #339966;\">\/\/ and then clone business rule set with updated modelId:<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\/\/brs is the business rule set<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\/\/sourceModelId is the source Model Identifier (taken above from the Rules set from the XML file)<\/span><\/pre>\n<pre><span style=\"color: #339966;\">\/\/target ModelId is the model Identifier for the model we want to import back the B. rules to<\/span><\/pre>\n<pre>CloneBusinessRules(brs,sourceModelId,\u00a0targetModelId));<\/pre>\n<pre>Here is the CloneBusinessRules Method:<\/pre>\n<pre class=\"brush:c#\">public string CloneBusinessRules(BusinessRules brs, Identifier SourceModelId, Identifier targetModelId)\r\n        {\r\n\r\n            OperationResult or = null;\r\n            \/\/instanciate new BR members\r\n            try\r\n            {\r\n                int cptMissingEntity = 0;\r\n                StringBuilder sb = new StringBuilder(\"these business rule related entities does not exists in target model:\");\r\n                sb.AppendLine();\r\n                BusinessRules newBRS = new BusinessRules();\r\n                foreach (BusinessRule br in brs.BusinessRulesMember)\r\n                {\r\n                    Identifier EntityId = null;\r\n                    \/\/this is used to get the target entity Id with matching its name \r\n                    using (ServiceClient c = new ServiceClientWrapper().CreateServiceClient())\r\n                    {\r\n                        EntityId = GetEntityIdFromName(c, c.Endpoint.Address.Uri.OriginalString, targetModelId, br.Identifier.EntityId.Name);\r\n\r\n                    }\r\n                    if (EntityId != null)\r\n                    {\r\n                        newBRS.BusinessRulesMember = new Collection&lt;BusinessRule&gt;();\r\n\r\n                        \/\/create a new business rule based on the source one, and applying on it the target identifiers and names \r\n                        BusinessRule newBR = BusinessRuleInstanciate(Guid.NewGuid(), br.Identifier.Name, targetModelId.Name, br.Identifier.EntityId.Name,\r\n                            br.Identifier.MemberType, br.Priority, br.BRActions, br.Identifier.InternalId, br.RuleActionText, br.RuleConditionText);\r\n                        \/\/some required parameters to instanciate below:\r\n\r\n                        \/\/instanciate BRActions\r\n                        newBRS.BRActions = BRActionsInstanciate(brs.BRActions, newBR.Identifier);\r\n                        \/\/instanciate BRConditions\r\n                        newBRS.BRConditions = BRConditionsInstanciate(brs.BRConditions, newBR.Identifier);\r\n                        \/\/instanciate BRConditionTreeNodes\r\n                        newBRS.BRConditionTreeNodes = BRConditionTreeNodesInstanciate(brs.BRConditionTreeNodes, newBR.Identifier);\r\n                        newBRS.BusinessRulesMember.Add(newBR);\r\n                    }\r\n                    else\r\n                    {\r\n                        sb.AppendLine(br.Identifier.EntityId.Name);\r\n                        cptMissingEntity++;\r\n                        \/\/these business rule related entities do not exist in target model\r\n                    }\r\n                    \/\/then we clone modified BRSet\r\n                    using (ServiceClient c = new ServiceClientWrapper().CreateServiceClient())\r\n                    {\r\n\r\n                        or = c.BusinessRulesClone(new International(), newBRS);\r\n                        string err = Tools.HandleErrors(or);\r\n                        if (!string.IsNullOrEmpty(err))\r\n                        {\r\n                            throw new Exception(err);\r\n                        }\r\n                    }\r\n                    if (cptMissingEntity == 0)\r\n                    {\r\n                        sb = new StringBuilder();\r\n                    }\r\n                }\r\n\r\n                return sb.ToString();\r\n            }\r\n            catch (Exception exc)\r\n            {\r\n                throw exc;\r\n            }\r\n        }<\/pre>\n<p><span style=\"color: #ff0000;\">update oct 2011 code for BRActionsInstanciate, BRConditionsInstanciate,BRConditionTreeNodesInstanciate<\/span><\/p>\n<pre class=\"brush:c#\"> private Collection&lt;BRConditionTreeNode&gt; BRConditionTreeNodesInstanciate(Collection&lt;BRConditionTreeNode&gt; BRConditionTreeNodes, MemberTypeContextIdentifier BRId)\r\n        {\r\n\r\n            try\r\n            {\r\n                \/\/Add BRConditionTreeNode to BRConditionTreeNode Collection\r\n\r\n                Collection&lt;BRConditionTreeNode&gt; newBRConditionTreeNodes = new Collection&lt;BRConditionTreeNode&gt;();\r\n\r\n                foreach (BRConditionTreeNode brctn in BRConditionTreeNodes)\r\n                {\r\n                    BRConditionTreeNode BRConditionTreeNodeItem = new BRConditionTreeNode();\r\n                    \/\/Add Attribute and Action type to the collection\r\n                    BRConditionTreeNodeItem.BRConditions = BRConditionsInstanciate(brctn.BRConditions, BRId);\r\n                    BRConditionTreeNodeItem.BusinessRuleId = BRId;\r\n                    BRConditionTreeNodeItem.ConditionTreeChildNodes = brctn.ConditionTreeChildNodes;\r\n                    BRConditionTreeNodeItem.ConditionTreeParentNode = brctn.ConditionTreeParentNode;\r\n                    BRConditionTreeNodeItem.LogicalOperator = brctn.LogicalOperator;\r\n                    BRConditionTreeNodeItem.Identifier = new Identifier() { Name = brctn.Identifier.Name, Id = Guid.NewGuid() };\r\n\r\n                    \/\/All Action and Condition Items must have a sequence greater that zero\r\n                    BRConditionTreeNodeItem.Sequence = brctn.Sequence;\r\n                    newBRConditionTreeNodes.Add(BRConditionTreeNodeItem);\r\n                }\r\n                return newBRConditionTreeNodes;\r\n            }\r\n            catch (Exception exc)\r\n            {\r\n                throw exc;\r\n            }\r\n        }\r\n\r\n        private Collection&lt;BRAction&gt; BRActionsInstanciate(Collection&lt;BRAction&gt; BRActions, MemberTypeContextIdentifier BRId)\r\n        {\r\n\r\n            try\r\n            {\r\n                \/\/Add Action to Action Collection\r\n\r\n                Collection&lt;BRAction&gt; newBRActions = new Collection&lt;BRAction&gt;();\r\n\r\n                foreach (BRAction bra in BRActions)\r\n                {\r\n                    BRAction BRActionItem = new BRAction() { Identifier = new Identifier() { Id = Guid.NewGuid(), Name = bra.Identifier.Name }, BusinessRuleId = BRId };\r\n                    \/\/Add Attribute and Action type to the collection\r\n                    BRActionItem.PrefixArgument = new BRAttributeArgument();\r\n                    BRActionItem.PrefixArgument.PropertyName = bra.PrefixArgument.PropertyName;\r\n                    BRActionItem.PrefixArgument.AttributeId = new Identifier();\r\n                    BRActionItem.PrefixArgument.AttributeId.Id = Guid.NewGuid();\r\n                    BRActionItem.PrefixArgument.AttributeId.Name = bra.PrefixArgument.AttributeId.Name;\r\n                    BRActionItem.Operator = bra.Operator;\r\n                    var colBRffa = new Collection&lt;object&gt;();\r\n                    foreach (var brffa in bra.PostfixArguments)\r\n                    {\r\n                        BRBlankArgument BRba = brffa as BRBlankArgument;\r\n                        BRFreeformArgument BRffa = brffa as BRFreeformArgument;\r\n                        if (BRba != null)\r\n                        {\r\n                            colBRffa.Add(new BRBlankArgument() { Identifier = new Identifier() { Id = Guid.NewGuid(), Name = BRba.Identifier.Name }, PropertyName = BRba.PropertyName });\r\n\r\n                        }\r\n                        else\r\n                        {\r\n                            if (BRffa != null)\r\n                            {\r\n                                colBRffa.Add(new BRFreeformArgument() { Identifier = new Identifier() { Id = Guid.NewGuid(), Name = BRffa.Identifier.Name }, Value = BRffa.Value, PropertyName = BRffa.PropertyName });\r\n\r\n                            }\r\n                        }\r\n                    }\r\n                    BRActionItem.PostfixArguments = colBRffa;\r\n                    BRActionItem.Text = bra.Text;\r\n\r\n                    \/\/All Action and Condition Items must have a sequence greater that zero\r\n                    BRActionItem.Sequence = bra.Sequence;\r\n                    newBRActions.Add(BRActionItem);\r\n                }\r\n                return newBRActions;\r\n            }\r\n            catch (Exception exc)\r\n            {\r\n                throw exc;\r\n            }\r\n        }\r\n        public Collection&lt;BRCondition&gt; BRConditionsInstanciate(Collection&lt;BRCondition&gt; BRconditions, MemberTypeContextIdentifier BRId)\r\n        {\r\n\r\n            try\r\n            {\r\n                \/\/Add Action to Action Collection\r\n\r\n                Collection&lt;BRCondition&gt; newBRconditions = new Collection&lt;BRCondition&gt;();\r\n                BRCondition BRConditionItem = new BRCondition();\r\n\r\n                foreach (BRCondition brc in BRconditions)\r\n                {\r\n                    \/\/Add Attribute and Action type to the collection\r\n                    BRConditionItem.BusinessRuleId = BRId;\r\n\r\n                    BRConditionItem.ConditionTreeNodeId = new Identifier() { Name = brc.ConditionTreeNodeId.Name };\r\n                    BRConditionItem.Identifier = new Identifier() { Id = Guid.NewGuid(), Name = brc.Identifier.Name };\r\n                    BRConditionItem.Operator = brc.Operator;\r\n                    BRConditionItem.PrefixArgument = brc.PrefixArgument;\r\n                    BRConditionItem.PostfixArguments = brc.PostfixArguments;\r\n                    \/\/All Action and Condition Items must have a sequence greater that zero\r\n                    BRConditionItem.Sequence = brc.Sequence;\r\n                    BRConditionItem.Text = brc.Text;\r\n                    newBRconditions.Add(BRConditionItem);\r\n                }\r\n                return newBRconditions;\r\n            }\r\n            catch (Exception exc)\r\n            {\r\n                throw exc;\r\n            }\r\n        }<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>updated article (Oct 2011) (code refactored) Hi All, One other missing feature of MDS is Import \/ Export \/ Copy Business rules from a model to another (or copy business rules to the same model) my code is still in beta, but it is already (partially) working. you can find \u2026 <a class=\"continue-reading-link\" href=\"https:\/\/blog.avxt.fr\/fr\/master-data-services-business-rules-copy-import-export-cross-model\/\"> Continue reading <span class=\"meta-nav\">&rarr; <\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[14],"tags":[33,31,30,29,37,36,35,32,34,28],"class_list":["post-151","post","type-post","status-publish","format-standard","hentry","category-mds","tag-business-rules","tag-copie","tag-copy","tag-cross-model","tag-cross-models","tag-export","tag-import","tag-inter-modeles","tag-master-data-services","tag-mds-2"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/151","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/comments?post=151"}],"version-history":[{"count":18,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/151\/revisions"}],"predecessor-version":[{"id":208,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/posts\/151\/revisions\/208"}],"wp:attachment":[{"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/media?parent=151"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/categories?post=151"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.avxt.fr\/fr\/wp-json\/wp\/v2\/tags?post=151"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}