/// <summary> /// AddRule: typeof(FactTypeHasRole) /// Rule to detect when a Role is added to the FactType so that it /// can also be added to the ReadingOrders and their Readings. /// </summary> private static void FactTypeHasRoleAddedRule(ElementAddedEventArgs e) { FactTypeHasRole link = (FactTypeHasRole)e.ModelElement; if (CopyMergeUtility.GetIntegrationPhase(link.Store) != CopyClosureIntegrationPhase.Integrating) { // UNDONE: COPYMERGE Do we need to run a similar rule on integration complete // to handle merge cases where roles are added to a model with additional // readings on the merged fact type. ValidateReadingOrdersRoleCollection(link.FactType, link.Role); } }
/// <summary> /// DeleteRule: typeof(FactTypeHasRole), FireTime=LocalCommit, Priority=ORMCoreDomainModel.BeforeDelayValidateRulePriority; /// Block roles from being removed from a subtype /// after it is included in a model. /// </summary> private static void LimitSubtypeRolesDeleteRule(ElementDeletedEventArgs e) { FactTypeHasRole link = (FactTypeHasRole)e.ModelElement; SubtypeFact subtypeFact = link.FactType as SubtypeFact; if (null != (subtypeFact = link.FactType as SubtypeFact) && !subtypeFact.IsDeleted && subtypeFact.ResolvedModel != null) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(subtypeFact.Store); } }
/// <summary> /// AddRule: typeof(FactTypeHasRole) /// Block roles from being added to a subtype /// after it is included in a model. /// </summary> private static void LimitSubtypeRolesAddRule(ElementAddedEventArgs e) { FactTypeHasRole link = (FactTypeHasRole)e.ModelElement; SubtypeFact subtypeFact; if (null != (subtypeFact = link.FactType as SubtypeFact)) { Store store; if (subtypeFact.ResolvedModel != null && CopyMergeUtility.GetIntegrationPhase(store = link.Store) == CopyClosureIntegrationPhase.None) { // Allow before adding to model, not afterwards ThrowPatternModifiedException(store); } } else { RoleBase role = link.Role; if (role is SubtypeMetaRole || role is SupertypeMetaRole) { throw new InvalidOperationException(ResourceStrings.ModelExceptionSubtypeFactMustBeParentOfMetaRole); } } }
/// <summary> /// AddRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.FactTypeHasRole) /// Rules are defined to respond to changes in the object /// model that occur during user editing. In this case, we're adding /// our custom extension element to a Role object when it is added to /// a FactType via the FactTypeHasRole relationship. See the /// ExtensionDomainModel.AttachRules.xml file to see how this /// method is attached as a rule. /// </summary> private static void RoleAddRule(ElementAddedEventArgs e) { FactTypeHasRole factTypeHasRole = (FactTypeHasRole)e.ModelElement; ExtensionElementUtility.AddExtensionElement(factTypeHasRole.Role, new MyCustomExtensionElement(factTypeHasRole.Store)); }