public void ExactlyOneTest_1b(Store store)
        {
            myTestServices.LogValidationErrors("No errors expected");
            ORMModel            model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            FrequencyConstraint constraint = (FrequencyConstraint)model.ConstraintsDictionary.GetElement("FrequencyConstraint1").SingleElement;

            // DomainTypeDescriptor.CreatePropertyDescriptor(constraint, FrequencyConstraint.MaxFrequencyDomainPropertyId).SetValue(constraint, 1);
            myTestServices.LogValidationErrors("Introduce Error[FrequencyConstraintExactlyOneError]");
            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                constraint.MinFrequency = 1;
                constraint.MaxFrequency = 1;
                t.Commit();
            }
            myTestServices.LogValidationErrors("Fixing error with error activation service");
            ((IORMToolServices)store).ModelErrorActivationService.ActivateError(constraint, constraint.FrequencyConstraintExactlyOneError);
            myTestServices.LogValidationErrors("[FrequencyConstraintExactlyOneError] removed, different error introduced. Removing new error");

            // Deleting one of the two uniqnuess constraints...
            UniquenessConstraint uniqueC = (UniquenessConstraint)model.ConstraintsDictionary.GetElement("InternalUniquenessConstraint5").SingleElement;

            using (Transaction t = store.TransactionManager.BeginTransaction("Read the error"))
            {
                uniqueC.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("All errors resolved");
        }
Beispiel #2
0
            /// <summary>
            /// DeleteRule: typeof(UniquenessConstraintIsForUniqueness)
            /// Propagate deletion of a Uniqueness
            /// </summary>
            private static void UniquenessDeletedRule(ElementDeletedEventArgs e)
            {
                UniquenessConstraint constraint = ((UniquenessConstraintIsForUniqueness)e.ModelElement).UniquenessConstraint;

                if (!constraint.IsDeleted)
                {
                    constraint.Delete();
                }
            }
Beispiel #3
0
        public void UniqueUniqueImplied_1a(Store store)
        {
            myTestServices.LogValidationErrors("Start with one Implication Error");
            ORMModel             model      = store.ElementDirectory.FindElements <ORMModel>()[0];
            UniquenessConstraint constraint = (UniquenessConstraint)model.ConstraintsDictionary.GetElement("ExternalUniquenessConstraint_A").SingleElement;

            myTestServices.LogMessage("Removing the Implied Uniqueness Costraint...");
            using (Transaction t = store.TransactionManager.BeginTransaction("Remove Implied Uniqueness Costraint"))
            {
                constraint.Delete();
                t.Commit();
            }
            myTestServices.LogValidationErrors("Error is removed with removal of Implied Constraint");
        }
            /// <summary>
            /// Reverses the binarization process performed by <see cref="BinarizeUnary"/>. Typically used when
            /// <paramref name="binarizedUnaryFactRoleCollection"/> no longer qualifies as the roles for a
            /// binarized unary <see cref="FactType"/>.
            /// </summary>
            private static void DebinarizeUnary(LinkedElementCollection <RoleBase> binarizedUnaryFactRoleCollection, bool deleteImplicitBooleanRole, INotifyElementAdded notifyAdded)
            {
                // UNDONE: We need to make sure the debinarization happens BEFORE the implied Objectification rules run on the binarized unary FactType.

                // The default implied role is the second one, walk the collection backwards
                int roleCount = binarizedUnaryFactRoleCollection.Count;

                for (int i = roleCount - 1; i >= 0; --i)
                {
                    Role       implicitBooleanRole;
                    ObjectType implicitBooleanValueType;
                    if (null != (implicitBooleanRole = binarizedUnaryFactRoleCollection[i].Role) &&
                        null != (implicitBooleanValueType = implicitBooleanRole.RolePlayer) &&
                        implicitBooleanValueType.IsImplicitBooleanValue)
                    {
                        // Delete the implicit boolean value type (which will also remove any value constraints on it)
                        // Note that changes to IsImplicitBooleanValue are intentionally blocked so that the
                        // deleted implied ValueType can be identified as such by events as well as rules.
                        // implicitBooleanValueType.IsImplicitBooleanValue = false;
                        bool        ruleDisabled = false;
                        RuleManager ruleManager  = null;
                        try
                        {
                            if (notifyAdded == null)
                            {
                                ruleManager = implicitBooleanRole.Store.RuleManager;
                                ruleManager.DisableRule(typeof(ObjectTypePlaysRoleDeletedRuleClass));
                                ruleDisabled = true;
                            }
                            if (deleteImplicitBooleanRole)
                            {
                                // We delete the role first so that rules do not
                                // try to recreate and implied fact type for this rule
                                // if it is part of an objectified FactType.
                                implicitBooleanRole.Delete();
                                --roleCount;
                                if (!implicitBooleanValueType.IsDeleted)
                                {
                                    // The Objectification.RolePlayerDeletingRule rule will delet this automatically
                                    implicitBooleanValueType.Delete();
                                }
                            }
                            else
                            {
                                implicitBooleanValueType.Delete();
                            }
                        }
                        finally
                        {
                            if (ruleDisabled)
                            {
                                ruleManager.EnableRule(typeof(ObjectTypePlaysRoleDeletedRuleClass));
                            }
                        }

                        // Clear implied constraints
                        for (int j = 0; j < roleCount; ++j)
                        {
                            Role role = binarizedUnaryFactRoleCollection[j] as Role;
                            if (role != null)
                            {
                                if (role != implicitBooleanRole)
                                {
                                    role.Name = "";
                                    // Role cardinality is for unary fact types only, eliminate
                                    // it if we switch away.
                                    role.Cardinality = null;
                                }

                                UniquenessConstraint singleRoleAlethicUniquenessConstraint = role.SingleRoleAlethicUniquenessConstraint;
                                if (singleRoleAlethicUniquenessConstraint != null)
                                {
                                    // Delete the uniqueness constraint
                                    singleRoleAlethicUniquenessConstraint.Delete();
                                }

                                // UNDONE: We are using open-world assumption now
                                //MandatoryConstraint simpleMandatoryConstraint = role.SimpleMandatoryConstraint;
                                //if (simpleMandatoryConstraint != null && simpleMandatoryConstraint.Modality == ConstraintModality.Alethic)
                                //{
                                //    // Delete the simple mandatory constraint (for closed-world assumption), if present
                                //    simpleMandatoryConstraint.Delete();
                                //}
                            }
                        }
                        break;
                    }
                }
            }