/// <summary> /// Perfom initial gateway checks when an <see cref="ORMModel"/> is first considered for absorption /// </summary> /// <param name="model">The <see cref="ORMModel"/> to verify and exclude elements in</param> /// <param name="notifyExcluded">A callback notifying when an element is being excluded. Used during deserialization. Can be <see langword="null"/>.</param> public static void Initialize(ORMModel model, NotifyORMElementExcluded notifyExcluded) { AbstractionModel abstractionModel = AbstractionModelIsForORMModel.GetAbstractionModel(model); foreach (ObjectType objectType in model.ObjectTypeCollection) { if (!IsElementExcluded(objectType) && !ShouldConsiderObjectType(objectType, null, false)) { ExcludeObjectType(objectType, abstractionModel, true, notifyExcluded); } } foreach (FactType factType in model.FactTypeCollection) { if (!IsElementExcluded(factType) && !ShouldConsiderFactType(factType, null, false)) { ExcludeFactType(factType, abstractionModel, true, notifyExcluded); } } }
private static void ExcludeObjectType(ObjectType objectType, AbstractionModel model, bool forceCreate, NotifyORMElementExcluded notifyExcluded) { if (forceCreate || null == ExcludedORMModelElement.GetAbstractionModel(objectType)) { new ExcludedORMModelElement(objectType, model); if (notifyExcluded != null) { notifyExcluded(objectType); } // Excluding an object type leaves a FactType with a null role player, // so the associated fact types also need to be excluded. foreach (Role playedRole in objectType.PlayedRoleCollection) { ExcludeFactType(playedRole.FactType, model, false, notifyExcluded); RoleProxy proxy = playedRole.Proxy; if (proxy != null) { ExcludeFactType(proxy.FactType, model, false, notifyExcluded); } } if (!objectType.IsValueType) { // Excluding an object type can leave a downstream subtype without an // identifier, so exclude those as well. Note we only go one level deep // as this will recurse naturally on the next level. ObjectType.WalkSubtypes(objectType, delegate(ObjectType type, int depth, bool isPrimary) { switch (depth) { case 0: return ObjectTypeVisitorResult.Continue; case 1: if (isPrimary) { if (type.PreferredIdentifier == null) { ExcludeObjectType(type, model, false, notifyExcluded); } } return ObjectTypeVisitorResult.SkipChildren; default: return ObjectTypeVisitorResult.Stop; } }); } } }
private static void ExcludeFactType(FactType factType, AbstractionModel model, bool forceCreate, NotifyORMElementExcluded notifyExcluded) { if (forceCreate || null == ExcludedORMModelElement.GetAbstractionModel(factType)) { if (null == factType.Objectification || factType.UnaryRole != null) { new ExcludedORMModelElement(factType, model); } if (notifyExcluded != null) { notifyExcluded(factType); } foreach (IFactConstraint constraint in factType.FactConstraintCollection) { ObjectType preferredFor = constraint.Constraint.PreferredIdentifierFor; if (preferredFor != null) { ExcludeObjectType(preferredFor, model, false, notifyExcluded); } } Objectification objectification; if (null != (objectification = factType.ImpliedByObjectification)) { ExcludeObjectType(objectification.NestingType, model, false, notifyExcluded); } } }