Exemplo n.º 1
0
        // 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);
            }
        }
Exemplo n.º 2
0
        // 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);
            }
        }
Exemplo n.º 3
0
        // Creates a member that causes a validation issue, processes the validation and gets the list of validation issues.
        private static void GetBRValidationIssue(string modelName, string entityName, string ruleName, string versionName)
        {
            try
            {
                // Set Model, Entity, and Version objects.
                Identifier modelId = new Identifier { Name = modelName };
                Identifier entityId = new Identifier { Name = entityName };
                Identifier versionId = new Identifier { Name = versionName };

                // Create the request object.
                MDSTestService.BusinessRulesCreateRequest ruleCreateRequest = new MDSTestService.BusinessRulesCreateRequest();
                ruleCreateRequest.ReturnCreatedIdentifiers = true;
                ruleCreateRequest.BusinessRuleSet = new BusinessRules();

                // Create the request object.
                MDSTestService.EntityMembersCreateRequest memberCreateRequest = new MDSTestService.EntityMembersCreateRequest();
                memberCreateRequest.Members = new EntityMembers();
                memberCreateRequest.Members.ModelId = modelId;
                memberCreateRequest.Members.EntityId = entityId;
                memberCreateRequest.Members.VersionId = versionId;
                memberCreateRequest.Members.MemberType = MemberType.Leaf;
                Member aMember = new Member();
                aMember.MemberId = new MemberIdentifier();
                aMember.MemberId.Code = "Test12";
                aMember.MemberId.Name = "AA";
                aMember.MemberId.MemberType = MemberType.Leaf;
                memberCreateRequest.Members.Members = new System.Collections.ObjectModel.Collection<Member> { };
                memberCreateRequest.Members.Members.Add(aMember);

                // Add a member that triggers the validation error.
                MDSTestService.EntityMembersCreateResponse memberCreateResponse = clientProxy.EntityMembersCreate(memberCreateRequest);
                HandleOperationErrors(memberCreateResponse.OperationResult);

                // Create the request object.
                MDSTestService.ValidationProcessRequest validationProcessRequest = new MDSTestService.ValidationProcessRequest();
                validationProcessRequest.ValidationProcessCriteria = new ValidationProcessCriteria();
                validationProcessRequest.ValidationProcessCriteria.ModelId = modelId;
                validationProcessRequest.ValidationProcessCriteria.EntityId = entityId;
                validationProcessRequest.ValidationProcessCriteria.VersionId = versionId;
                validationProcessRequest.ValidationProcessOptions = new ValidationProcessOptions();
                validationProcessRequest.ValidationProcessOptions.ReturnValidationResults = true;

                // Process validation and get a validation issue.
                MDSTestService.ValidationProcessResponse validationProcessResponse = clientProxy.ValidationProcess(validationProcessRequest);
                HandleOperationErrors(validationProcessResponse.OperationResult);

                // Show the validation issue's description.
                if (validationProcessResponse.ValidationIssueList.Count > 0)
                {
                    ValidationIssue validationIssue = validationProcessResponse.ValidationIssueList[0];
                    Console.WriteLine("Validation issue: " + validationIssue.Description);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }
        }
Exemplo n.º 4
0
        // Creates a member that causes a validation issue, processes the validation and gets the list of validation issues.
        private static void GetBRValidationIssue(string modelName, string entityName, string ruleName, string versionName)
        {
            try
            {
                // Set Model, Entity, and Version objects.
                Identifier modelId = new Identifier {
                    Name = modelName
                };
                Identifier entityId = new Identifier {
                    Name = entityName
                };
                Identifier versionId = new Identifier {
                    Name = versionName
                };

                // Create the request object.
                MDSTestService.BusinessRulesCreateRequest ruleCreateRequest = new MDSTestService.BusinessRulesCreateRequest();
                ruleCreateRequest.ReturnCreatedIdentifiers = true;
                ruleCreateRequest.BusinessRuleSet          = new BusinessRules();

                // Create the request object.
                MDSTestService.EntityMembersCreateRequest memberCreateRequest = new MDSTestService.EntityMembersCreateRequest();
                memberCreateRequest.Members            = new EntityMembers();
                memberCreateRequest.Members.ModelId    = modelId;
                memberCreateRequest.Members.EntityId   = entityId;
                memberCreateRequest.Members.VersionId  = versionId;
                memberCreateRequest.Members.MemberType = MemberType.Leaf;
                Member aMember = new Member();
                aMember.MemberId                    = new MemberIdentifier();
                aMember.MemberId.Code               = "Test12";
                aMember.MemberId.Name               = "AA";
                aMember.MemberId.MemberType         = MemberType.Leaf;
                memberCreateRequest.Members.Members = new System.Collections.ObjectModel.Collection <Member> {
                };
                memberCreateRequest.Members.Members.Add(aMember);

                // Add a member that triggers the validation error.
                MDSTestService.EntityMembersCreateResponse memberCreateResponse = clientProxy.EntityMembersCreate(memberCreateRequest);
                HandleOperationErrors(memberCreateResponse.OperationResult);

                // Create the request object.
                MDSTestService.ValidationProcessRequest validationProcessRequest = new MDSTestService.ValidationProcessRequest();
                validationProcessRequest.ValidationProcessCriteria           = new ValidationProcessCriteria();
                validationProcessRequest.ValidationProcessCriteria.ModelId   = modelId;
                validationProcessRequest.ValidationProcessCriteria.EntityId  = entityId;
                validationProcessRequest.ValidationProcessCriteria.VersionId = versionId;
                validationProcessRequest.ValidationProcessOptions            = new ValidationProcessOptions();
                validationProcessRequest.ValidationProcessOptions.ReturnValidationResults = true;

                // Process validation and get a validation issue.
                MDSTestService.ValidationProcessResponse validationProcessResponse = clientProxy.ValidationProcess(validationProcessRequest);
                HandleOperationErrors(validationProcessResponse.OperationResult);

                // Show the validation issue's description.
                if (validationProcessResponse.ValidationIssueList.Count > 0)
                {
                    ValidationIssue validationIssue = validationProcessResponse.ValidationIssueList[0];
                    Console.WriteLine("Validation issue: " + validationIssue.Description);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: {0}", ex);
            }
        }