/// <summary>
            /// Make sure we have our tracker attached to all loaded models.
            /// </summary>
            /// <param name="element">An ORMModel element</param>
            /// <param name="store">The context store</param>
            /// <param name="notifyAdded">The listener to notify if elements are added during fixup</param>
            protected sealed override void ProcessElement(ORMModel element, Store store, INotifyElementAdded notifyAdded)
            {
                AbstractionModel oil = AbstractionModelIsForORMModel.GetAbstractionModel(element);

                if (oil == null)
                {
                    // UNDONE: DelayValidateModel currently deletes and recreates any existing
                    // bridge relationship, so there is no point deleting it up front, we'll
                    // just retrieve it later. Also note that DelayValidateModel does not call notifyAdded.
                    DelayValidateModel(element);
                    oil = AbstractionModelIsForORMModel.GetAbstractionModel(element);
                    if (oil != null)
                    {
                        notifyAdded.ElementAdded(oil, true);
                    }
                }
                else
                {
                    AbstractionModelGenerationSetting generationSetting;
                    bool regenerateForVersion   = null == (generationSetting = GenerationSettingTargetsAbstractionModel.GetGenerationSetting(oil)) || generationSetting.AlgorithmVersion != CurrentAlgorithmVersion;
                    bool excludedBridgedElement = false;
                    ORMElementGateway.Initialize(
                        element,
                        regenerateForVersion ? (ORMElementGateway.NotifyORMElementExcluded) null :
                        delegate(ORMModelElement modelElement)
                    {
                        if (excludedBridgedElement)
                        {
                            return;
                        }
                        ObjectType objectType;
                        FactType factType;
                        // Note that the types we're checking here are synchronized with the ORMElementGateway.ExclusionAdded method
                        if (null != (objectType = modelElement as ObjectType))
                        {
                            if (null != ConceptTypeIsForObjectType.GetLinkToConceptType(objectType) ||
                                null != InformationTypeFormatIsForValueType.GetLinkToInformationTypeFormat(objectType))
                            {
                                excludedBridgedElement = true;
                            }
                        }
                        else if (null != (factType = modelElement as FactType))
                        {
                            if (null != FactTypeMapsTowardsRole.GetLinkToTowardsRole(factType) ||
                                ConceptTypeChildHasPathFactType.GetLinksToConceptTypeChild(factType).Count != 0)
                            {
                                excludedBridgedElement = true;
                            }
                        }
                    });
                    if (regenerateForVersion || excludedBridgedElement)
                    {
                        // Something is very wrong, regenerate (does not regenerate the excluded elements we already have)
                        DelayValidateModel(element);
                    }
                }
            }
Ejemplo n.º 2
0
 /// <summary>
 /// ChangeRule: typeof(ORMSolutions.ORMArchitect.Core.ObjectModel.ORMModel)
 /// Synchronize the <see cref="P:AbstractionModel.Name">name</see> of the <see cref="AbstractionModel"/>
 /// with the <see cref="P:ORMModel.Name">name</see> of the <see cref="ORMModel"/>
 /// </summary>
 private static void ORMModelChangedRule(ElementPropertyChangedEventArgs e)
 {
     if (e.DomainProperty.Id == ORMModel.NameDomainPropertyId)
     {
         ORMModel         model            = (ORMModel)e.ModelElement;
         AbstractionModel abstractionModel = AbstractionModelIsForORMModel.GetAbstractionModel(model);
         if (abstractionModel != null)
         {
             abstractionModel.Name = model.Name;
         }
     }
 }
Ejemplo n.º 3
0
		private static void DelayValidateModel(ModelElement element)
		{
			Dictionary<object, object> contextDictionary = element.Store.TransactionManager.CurrentTransaction.TopLevelTransaction.Context.ContextInfo;

			if (contextDictionary.ContainsKey(Key))
			{
				// Get the elements affected within the transaction
				Dictionary<ModelElement, int> elementList = (Dictionary<ModelElement, int>)contextDictionary[Key];

				// Elements that were both added & deleted in the transaction can be ignored for map change analysis
				EliminateRedundantElements(elementList);

				// TODO: scan for changes that actually affect the model; all others can be filtered out

				if (elementList.Count == 0)
				{
					return;
				}
			}

			ORMModel model = (ORMModel)element;
			Store store = model.Store;

			// Get the link from the given ORMModel
			AbstractionModelIsForORMModel oialModelIsForORMModel = AbstractionModelIsForORMModel.GetLinkToAbstractionModel(model);
			AbstractionModel oialModel = null;

			// If the link exists, clear it out. There is no need to recreate it completely.
			if (oialModelIsForORMModel != null)
			{
				// Make sure the RebuildingAbstractionModel returns true during the rebuild
				oialModelIsForORMModel.myRebuildingAbstractionModel = true;
				try
				{
					oialModel = oialModelIsForORMModel.AbstractionModel;
					oialModel.ConceptTypeCollection.Clear();
					oialModel.InformationTypeFormatCollection.Clear();

					ReadOnlyCollection<FactTypeMapsTowardsRole> factTypeMaps = store.ElementDirectory.FindElements<FactTypeMapsTowardsRole>(false);
					int factTypeMapCount = factTypeMaps.Count;
					for (int i = factTypeMapCount - 1; i >= 0; --i)
					{
						FactTypeMapsTowardsRole factTypeMap = factTypeMaps[i];
						if (factTypeMap.FactType.Model == model)
						{
							factTypeMap.Delete();
						}
					}
					// Apply ORM to OIAL algorithm
					oialModelIsForORMModel.TransformORMtoOial();
				}
				finally
				{
					oialModelIsForORMModel.myRebuildingAbstractionModel = false;
				}
			}
			else
			{
				oialModel = new AbstractionModel(
					store,
					new PropertyAssignment(AbstractionModel.NameDomainPropertyId, model.Name));
				oialModelIsForORMModel = new AbstractionModelIsForORMModel(oialModel, model);

				// Set initial object exclusion states
				ORMElementGateway.Initialize(model, null);

				// Apply ORM to OIAL algorithm
				oialModelIsForORMModel.TransformORMtoOial();
			}
			if (oialModel != null)
			{
				AbstractionModelGenerationSetting generationSetting = GenerationSettingTargetsAbstractionModel.GetGenerationSetting(oialModel);
				if (generationSetting == null)
				{
					generationSetting = new AbstractionModelGenerationSetting(store, new PropertyAssignment(AbstractionModelGenerationSetting.AlgorithmVersionDomainPropertyId, CurrentAlgorithmVersion));
					new GenerationSettingTargetsAbstractionModel(generationSetting, oialModel);
					new GenerationStateHasGenerationSetting(GenerationState.EnsureGenerationState(store), generationSetting);
				}
				else
				{
					generationSetting.AlgorithmVersion = CurrentAlgorithmVersion;
				}
			}
		}