Beispiel #1
0
            /// <summary>
            /// Internal constraints are not fully connected at this point (FactSetConstraint instances
            /// are not implicitly constructed until a later phase), so we need to work a little harder
            /// to remove them.
            /// </summary>
            /// <param name="factType">The fact to clear of external constraints</param>
            private static void RemoveFactType(FactType factType)
            {
                LinkedElementCollection <RoleBase> factRoles = factType.RoleCollection;
                int roleCount = factRoles.Count;

                for (int i = 0; i < roleCount; ++i)
                {
                    Role role = factRoles[i].Role;
                    LinkedElementCollection <ConstraintRoleSequence> sequences = role.ConstraintRoleSequenceCollection;
                    int sequenceCount = sequences.Count;
                    for (int j = sequenceCount - 1; j >= 0; --j)
                    {
                        SetConstraint ic = sequences[j] as SetConstraint;
                        if (ic != null && ic.Constraint.ConstraintIsInternal)
                        {
                            ic.Delete();
                        }
                    }
                }
                factType.Delete();
            }
Beispiel #2
0
        /// <summary>
        /// DeleteRule: typeof(ConstraintRoleSequenceHasRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority;
        /// Block roles from being removed from a subtype fact
        /// after it is included in a model.
        /// </summary>
        private static void LimitSubtypeConstraintRolesDeleteRule(ElementDeletedEventArgs e)
        {
            ConstraintRoleSequenceHasRole link = e.ModelElement as ConstraintRoleSequenceHasRole;
            SetConstraint ic = link.ConstraintRoleSequence as SetConstraint;
            LinkedElementCollection <FactType> facts;

            if (ic != null &&
                !ic.IsDeleted &&
                ic.Constraint.ConstraintIsInternal &&
                1 == (facts = ic.FactTypeCollection).Count)
            {
                SubtypeFact subtypeFact = facts[0] as SubtypeFact;
                if (null != (subtypeFact = facts[0] as SubtypeFact) &&
                    !subtypeFact.IsDeleted &&
                    subtypeFact.ResolvedModel != null)
                {
                    // Allow before adding to model, not afterwards
                    ThrowPatternModifiedException(subtypeFact.Store);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// ChangeRule: typeof(SetConstraint)
        /// Block the IsSimple, IsInternal, and Modality properties from being changed on
        /// internal constraints of subtype facts
        /// </summary>
        private static void LimitSubtypeConstraintChangeRule(ElementPropertyChangedEventArgs e)
        {
            Guid          attributeId = e.DomainProperty.Id;
            SetConstraint constraint  = e.ModelElement as SetConstraint;

            if (!constraint.IsDeleted &&
                !constraint.IsDeleting)
            {
                LinkedElementCollection <FactType> testFacts = null;
                if (attributeId == UniquenessConstraint.IsInternalDomainPropertyId ||
                    attributeId == MandatoryConstraint.IsSimpleDomainPropertyId)
                {
                    testFacts = constraint.FactTypeCollection;
                }
                else if (attributeId == SetConstraint.ModalityDomainPropertyId)
                {
                    if (constraint.Constraint.ConstraintIsInternal)
                    {
                        testFacts = constraint.FactTypeCollection;
                    }
                }
                if (testFacts != null)
                {
                    int   testFactsCount = testFacts.Count;
                    Store store          = constraint.Store;
                    for (int i = 0; i < testFactsCount; ++i)
                    {
                        if (testFacts[i] is SubtypeFact)
                        {
                            // We never do this internally, so block any modification,
                            // not just those after the subtype fact is added to the model
                            ThrowPatternModifiedException(store);
                        }
                    }
                }
            }
        }