// Create a new business rule and publish the rule to enable it in the validation process. private static void CreateAndPublishBR(string modelName, string entityName, string ruleName) { try { // Set Model and Entity objects. Identifier modelId = new Identifier { Name = modelName }; Identifier entityId = new Identifier { Name = entityName }; // Create the request object. MDSTestService.BusinessRulesCreateRequest ruleCreateRequest = new MDSTestService.BusinessRulesCreateRequest(); ruleCreateRequest.ReturnCreatedIdentifiers = true; ruleCreateRequest.BusinessRuleSet = new BusinessRules(); // Create a new business rule. BusinessRule newRule = new BusinessRule(); ruleCreateRequest.BusinessRuleSet.BusinessRulesMember = new System.Collections.ObjectModel.Collection <BusinessRule> { }; ruleCreateRequest.BusinessRuleSet.BusinessRulesMember.Add(newRule); newRule.Identifier = new MemberTypeContextIdentifier { Name = ruleName, ModelId = modelId, EntityId = entityId, MemberType = MemberType.Leaf }; newRule.Priority = 10; newRule.BRConditionTree = new BRConditionTreeNode(); newRule.BRConditionTree.LogicalOperator = LogicalOperator.And; newRule.BRConditionTree.Sequence = 1; // Create the rule condition "Code equals ABC". BRCondition ruleCondition = new BRCondition(); newRule.BRConditionTree.BRConditions = new System.Collections.ObjectModel.Collection <BRCondition> { }; newRule.BRConditionTree.BRConditions.Add(ruleCondition); ruleCondition.Sequence = 1; // Create the condition prefix argument for Code attribute. BRAttributeArgument conditionPrefix = new BRAttributeArgument(); ruleCondition.PrefixArgument = conditionPrefix; conditionPrefix.PropertyName = BRPropertyName.Anchor; conditionPrefix.AttributeId = new Identifier { Name = "Code" }; // Set the condition operator. ruleCondition.Operator = BRItemType.IsEqual; // Set the postfix argument "ABC". BRFreeformArgument conditionPostfix = new BRFreeformArgument(); ruleCondition.PostfixArguments = new System.Collections.ObjectModel.Collection <object> { }; ruleCondition.PostfixArguments.Add(conditionPostfix); conditionPostfix.PropertyName = BRPropertyName.Value; conditionPostfix.Value = "ABC"; // Create the rule action "Name must be equal to Test". BRAction ruleAction = new BRAction(); newRule.BRActions = new System.Collections.ObjectModel.Collection <BRAction> { }; newRule.BRActions.Add(ruleAction); ruleAction.Sequence = 1; // Set the action prefix argument for Name attribute. BRAttributeArgument actionPrefix = new BRAttributeArgument(); ruleAction.PrefixArgument = actionPrefix; actionPrefix.PropertyName = BRPropertyName.Anchor; actionPrefix.AttributeId = new Identifier { Name = "Name" }; // Set the action operator. ruleAction.Operator = BRItemType.MustBeEqual; // Set the action postfix argument. BRFreeformArgument actionPostfix = new BRFreeformArgument(); ruleAction.PostfixArguments = new System.Collections.ObjectModel.Collection <object> { }; ruleAction.PostfixArguments.Add(actionPostfix); actionPostfix.PropertyName = BRPropertyName.Value; actionPostfix.Value = "Test"; // Create the business rule. MDSTestService.BusinessRulesCreateResponse ruleCreateResponse = clientProxy.BusinessRulesCreate(ruleCreateRequest); HandleOperationErrors(ruleCreateResponse.OperationResult); // Create the request object. MDSTestService.BusinessRulesPublishRequest rulePublishRequest = new MDSTestService.BusinessRulesPublishRequest(); rulePublishRequest.BRPublishCriteria = new BRPublishCriteria(); rulePublishRequest.BRPublishCriteria.EntityId = entityId; rulePublishRequest.BRPublishCriteria.ModelId = modelId; rulePublishRequest.BRPublishCriteria.MemberType = BREntityMemberType.Leaf; // Publish the business rule. MDSTestService.MessageResponse rulePublishResponse = clientProxy.BusinessRulesPublish(rulePublishRequest); HandleOperationErrors(rulePublishResponse.OperationResult); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } }
// Create a new business rule and publish the rule to enable it in the validation process. private static void CreateAndPublishBR(string modelName, string entityName, string ruleName) { try { // Set Model and Entity objects. Identifier modelId = new Identifier { Name = modelName }; Identifier entityId = new Identifier { Name = entityName }; // Create the request object. MDSTestService.BusinessRulesCreateRequest ruleCreateRequest = new MDSTestService.BusinessRulesCreateRequest(); ruleCreateRequest.ReturnCreatedIdentifiers = true; ruleCreateRequest.BusinessRuleSet = new MDSTestService.BusinessRules(); // Create a new business rule. BusinessRule newRule = new BusinessRule(); ruleCreateRequest.BusinessRuleSet.BusinessRulesMember = new System.Collections.ObjectModel.Collection<BusinessRule> { }; ruleCreateRequest.BusinessRuleSet.BusinessRulesMember.Add(newRule); newRule.Identifier = new MemberTypeContextIdentifier { Name = ruleName, ModelId = modelId, EntityId = entityId, MemberType = MemberType.Leaf }; newRule.Priority = 10; newRule.BRConditionTree = new BRConditionTreeNode(); newRule.BRConditionTree.LogicalOperator = LogicalOperator.And; newRule.BRConditionTree.Sequence = 1; // Create the rule condition "Code equals ABC". BRCondition ruleCondition = new BRCondition(); newRule.BRConditionTree.BRConditions = new System.Collections.ObjectModel.Collection<BRCondition> { }; newRule.BRConditionTree.BRConditions.Add(ruleCondition); ruleCondition.Sequence = 1; // Create the condition prefix argument for Code attribute. BRAttributeArgument conditionPrefix = new BRAttributeArgument(); ruleCondition.PrefixArgument = conditionPrefix; conditionPrefix.PropertyName = BRPropertyName.Anchor; conditionPrefix.AttributeId = new Identifier { Name = "Code" }; // Set the condition operator. ruleCondition.Operator = BRItemType.IsEqual; // Set the postfix argument "ABC". BRFreeformArgument conditionPostfix = new BRFreeformArgument(); ruleCondition.PostfixArguments = new System.Collections.ObjectModel.Collection<object> { }; ruleCondition.PostfixArguments.Add(conditionPostfix); conditionPostfix.PropertyName = BRPropertyName.Value; conditionPostfix.Value = "ABC"; // Create the rule action "Name must be equal to Test". BRAction ruleAction = new BRAction(); newRule.BRActions = new System.Collections.ObjectModel.Collection<BRAction> { }; newRule.BRActions.Add(ruleAction); ruleAction.Sequence = 1; // Set the action prefix argument for Name attribute. BRAttributeArgument actionPrefix = new BRAttributeArgument(); ruleAction.PrefixArgument = actionPrefix; actionPrefix.PropertyName = BRPropertyName.Anchor; actionPrefix.AttributeId = new Identifier { Name = "Name" }; // Set the action operator. ruleAction.Operator = BRItemType.MustBeEqual; // Set the action postfix argument. BRFreeformArgument actionPostfix = new BRFreeformArgument(); ruleAction.PostfixArguments = new System.Collections.ObjectModel.Collection<object> { }; ruleAction.PostfixArguments.Add(actionPostfix); actionPostfix.PropertyName = BRPropertyName.Value; actionPostfix.Value = "Test"; // Create the business rule. MDSTestService.BusinessRulesCreateResponse ruleCreateResponse = clientProxy.BusinessRulesCreate(ruleCreateRequest); HandleOperationErrors(ruleCreateResponse.OperationResult); // Create the request object. MDSTestService.BusinessRulesPublishRequest rulePublishRequest = new MDSTestService.BusinessRulesPublishRequest(); rulePublishRequest.BRPublishCriteria = new BRPublishCriteria(); rulePublishRequest.BRPublishCriteria.EntityId = entityId; rulePublishRequest.BRPublishCriteria.ModelId = modelId; rulePublishRequest.BRPublishCriteria.MemberType = BREntityMemberType.Leaf; // Publish the business rule. MDSTestService.MessageResponse rulePublishResponse = clientProxy.BusinessRulesPublish(rulePublishRequest); HandleOperationErrors(rulePublishResponse.OperationResult); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } }
// Edits the business rule and publish to enable the changes in the validation process. private static void EditAndPublishBR(string modelName, string entityName, string ruleName) { try { // Set Model and Entity objects. Identifier modelId = new Identifier { Name = modelName }; Identifier entityId = new Identifier { Name = entityName }; // Create the request object. MDSTestService.BusinessRulesGetRequest ruleGetRequest = new MDSTestService.BusinessRulesGetRequest(); ruleGetRequest.ResultOptions = new BRResultOptions(); ruleGetRequest.ResultOptions.BusinessRules = ResultType.Details; ruleGetRequest.GetCriteria = new BRGetCriteria(); ruleGetRequest.GetCriteria.ModelId = modelId; ruleGetRequest.GetCriteria.EntityId = entityId; ruleGetRequest.GetCriteria.MemberType = BREntityMemberType.Leaf; ruleGetRequest.GetCriteria.BusinessRuleIds = new System.Collections.ObjectModel.Collection <Identifier> { }; ruleGetRequest.GetCriteria.BusinessRuleIds.Add(new Identifier { Name = ruleName }); // Get the business rules. MDSTestService.BusinessRulesGetResponse ruleGetResponse = clientProxy.BusinessRulesGet(ruleGetRequest); HandleOperationErrors(ruleGetResponse.OperationResult); BusinessRule selectedBusinessRule = ruleGetResponse.BusinessRuleSet.BusinessRulesMember[0]; // Change the condition to "Code starts with Test". BRCondition ruleCondition = selectedBusinessRule.BRConditionTree.BRConditions[0]; // Set the attribute name as "Code". BRAttributeArgument conditionPrefix = (BRAttributeArgument)ruleCondition.PrefixArgument; conditionPrefix.PropertyName = BRPropertyName.Anchor; conditionPrefix.AttributeId = new Identifier { Name = "Code" }; // Set the condition operator. ruleCondition.Operator = BRItemType.StartsWith; // Set the postfix argument "Test". BRFreeformArgument conditionPostfix = (BRFreeformArgument)ruleCondition.PostfixArguments[0]; conditionPostfix.PropertyName = BRPropertyName.Value; conditionPostfix.Value = "Test"; // Create the request object. MDSTestService.BusinessRulesUpdateRequest ruleUpdateRequest = new MDSTestService.BusinessRulesUpdateRequest(); ruleUpdateRequest.BusinessRuleSet = ruleGetResponse.BusinessRuleSet; // Update the business rule. MDSTestService.MessageResponse ruleUpdateResponse = clientProxy.BusinessRulesUpdate(ruleUpdateRequest); HandleOperationErrors(ruleUpdateResponse.OperationResult); // Create the request object. MDSTestService.BusinessRulesPublishRequest rulePublishRequest = new MDSTestService.BusinessRulesPublishRequest(); rulePublishRequest.BRPublishCriteria = new BRPublishCriteria(); rulePublishRequest.BRPublishCriteria.EntityId = entityId; rulePublishRequest.BRPublishCriteria.ModelId = modelId; rulePublishRequest.BRPublishCriteria.MemberType = BREntityMemberType.Leaf; // Publish the business rule. MDSTestService.MessageResponse rulePublishResponse = clientProxy.BusinessRulesPublish(rulePublishRequest); HandleOperationErrors(rulePublishResponse.OperationResult); } catch (Exception ex) { Console.WriteLine("Error: {0}", ex); } }