private void ClassifyNodes(DetectedChangeInstancesSet changeInstances, PSMSchema psmSchema) { FindRedNodes(changeInstances); #region blue and green nodes Queue <PSMAssociationMember> toDo = new Queue <PSMAssociationMember>(); foreach (PSMAssociationMember m in ModelIterator.GetLeaves(psmSchema)) { if (changeInstances.RedNodes.Contains(m)) { toDo.Enqueue(m); } } foreach (PSMAssociationMember redNode in changeInstances.RedNodes.OfType <PSMAssociationMember>()) { toDo.Enqueue(redNode); } foreach (PSMAttribute psmAttribute in changeInstances.RedNodes.OfType <PSMAttribute>()) { if (!changeInstances.RedNodes.Contains(psmAttribute.PSMClass)) { changeInstances.BlueNodes.AddIfNotContained(psmAttribute.PSMClass); toDo.Enqueue(psmAttribute.PSMClass); } } while (!toDo.IsEmpty()) { PSMAssociationMember m = toDo.Dequeue(); if (m.ParentAssociation != null) { if (!changeInstances.RedNodes.Contains(m.ParentAssociation.Parent) && !changeInstances.BlueNodes.Contains(m.ParentAssociation.Parent)) { changeInstances.BlueNodes.Add(m.ParentAssociation.Parent); if (!(m.ParentAssociation.Parent is PSMSchemaClass)) { toDo.Enqueue(m.ParentAssociation.Parent); } } } } changeInstances.GreenNodes.AddRange(psmSchema.SchemaComponents.Where(c => !(c is PSMAssociation) && !(c is PSMSchemaClass) && !changeInstances.RedNodes.Contains(c) && !changeInstances.BlueNodes.Contains(c)).Cast <PSMComponent>()); foreach (PSMComponent psmComponent in changeInstances.AllNodes) { if (!psmComponent.ExistsInVersion(changeInstances.OldVersion)) { changeInstances.AddedNodes.Add(psmComponent); } } #endregion }
private void FindRedNodes(DetectedChangeInstancesSet changeInstances) { #region all OCL-initialized associations and attributes make the node red foreach (PSMAttribute initializedAttribute in changeInstances.AttributeInitializations.Keys) { changeInstances.RedNodes.AddIfNotContained(initializedAttribute); } foreach (PSMAssociation initializedAssociation in changeInstances.AssociationInitializations.Keys) { changeInstances.RedNodes.AddIfNotContained(initializedAssociation.Parent); } #endregion foreach (KeyValuePair <Type, List <ChangeInstance> > kvp in changeInstances) { foreach (ChangeInstance changeInstance in kvp.Value) { PSMComponent node = changeInstance.Component is PSMAssociation ? ((PSMAssociation)changeInstance.Component).Parent : changeInstance.Component; if (changeInstance is IMigratoryChange) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); CurrentParentAsRedNode(changeInstances.RedNodes, changeInstance); } if (changeInstance is IAdditionChange) { changeInstances.RedNodes.AddIfNotContained(node); CurrentParentAsRedNode(changeInstances.RedNodes, changeInstance); } if (changeInstance is IRemovalChange) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); } if (changeInstance is ISedentaryChange) { if (changeInstance is IRenameChange) { AssociationRenamedInstance associationRenamedInstance = changeInstance as AssociationRenamedInstance; AttributeRenamedInstance attributeRenamedInstance = changeInstance as AttributeRenamedInstance; if (attributeRenamedInstance != null) { changeInstances.RedNodes.AddIfNotContained(attributeRenamedInstance.PSMAttribute); } if (associationRenamedInstance != null) { changeInstances.RedNodes.AddIfNotContained(associationRenamedInstance.PSMAssociation.Child); /* * again for technical reasons (in order to process the whole instance * by the node template), the parent must be invalidated as well in * the case the name of the association was empty in the old version */ if (!associationRenamedInstance.ComponentOldVersion.IsNamed) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); } } } if (changeInstance is ICardinalityChange) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); { /* * again for technical reasons (in order to process the whole instance * by the node template), the parent must be invalidated as well */ AssociationCardinalityChangedInstance associationRenamedInstance = changeInstance as AssociationCardinalityChangedInstance; if (associationRenamedInstance != null && !associationRenamedInstance.ComponentOldVersion.IsNamed) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); } } } if (changeInstance is AttributeXFormChangedInstance) { FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); /* * A to E and E to A convertor templates will be used for green nodes */ if (((AttributeXFormChangedInstance)changeInstance).NewXFormElement) { changeInstances.ConvertedAttributesAE.Add((PSMAttribute)changeInstance.Component); } else { changeInstances.ConvertedAttributesEA.Add((PSMAttribute)changeInstance.Component); } } if (changeInstance is AttributeTypeChangedInstance) { changeInstances.RedNodes.AddIfNotContained(node); FormerParentAsRedNode(changeInstances.RedNodes, changeInstance); } if (changeInstance is ContentModelTypeChangedInstance) { changeInstances.RedNodes.AddIfNotContained(node); /* * technically this is required so the whole instance * of a content model is processed as a whole */ CurrentParentAsRedNode(changeInstances.RedNodes, changeInstance); } } } } /* parent node of every red inlined node is marked red */ List <PSMComponent> redNodesCopy = changeInstances.RedNodes.ToList(); foreach (PSMComponent c in redNodesCopy) { if (changeInstances.IsInlinedNode(c)) { CurrentParentAsRedNode(changeInstances.RedNodes, c); } } }
private static void testConstructs <TPSMComponent>(IEnumerable <TPSMComponent> components, Version oldVersion, Version newVersion, DetectedChangeInstancesSet changeInstancesSet, EChangePredicateScope scope) where TPSMComponent : ExolutioObject { foreach (TPSMComponent component in components) { if (changePredicatesByScope.ContainsKey(scope)) { foreach (Type type in changePredicatesByScope[scope]) { object[] testParams = new object[] { component, oldVersion, newVersion }; bool result = (bool)testMethods[type].Invoke(null, testParams); if (result) { changeInstancesSet.CreateSubCollectionIfNeeded(type); ChangeInstance instance = (ChangeInstance)createInstanceMethods[type].Invoke(null, testParams); changeInstancesSet[type].Add(instance); } } } } }
public DetectedChangeInstancesSet DetectChanges(PSMSchema schema1, PSMSchema schema2) { Version oldVersion = schema1.Version; Version newVersion = schema2.Version; Debug.Assert(oldVersion != newVersion); DetectedChangeInstancesSet changeInstancesSet = new DetectedChangeInstancesSet(); changeInstancesSet.OldVersion = oldVersion; changeInstancesSet.NewVersion = newVersion; #region attributes testConstructs(schema1.PSMAttributes, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMAttribute); testConstructs(schema2.PSMAttributes, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMAttribute); #endregion #region associations testConstructs(schema1.PSMAssociations, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMAssociation); testConstructs(schema2.PSMAssociations, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMAssociation); #endregion #region classes testConstructs(schema1.PSMClasses, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMClass); testConstructs(schema2.PSMClasses, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMClass); #endregion #region contentModels testConstructs(schema1.PSMContentModels, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMContentModel); testConstructs(schema2.PSMContentModels, oldVersion, newVersion, changeInstancesSet, EChangePredicateScope.PSMContentModel); #endregion foreach (OCLScript oclScript in schema2.OCLScripts) { if (oclScript.Type == OCLScript.EOclScriptType.Evolution) { try { OclCompilerResult r = oclScript.CompileToAst(); changeInstancesSet.OclCompilerResult = r; foreach (PropertyInitializationBlock propertyInitializationBlock in r.PropertyInitializations.PropertyInitializationBlocks) { foreach (PropertyInitialization propertyInitialization in propertyInitializationBlock.PropertyInitializations) { propertyInitialization.InitializationExpression.ConstraintContext = propertyInitializationBlock; if (propertyInitialization.Property is PSMBridgeAttribute) { PSMAttribute p = ((PSMBridgeAttribute)propertyInitialization.Property).SourceAttribute; changeInstancesSet.AttributeInitializations[p] = propertyInitialization.InitializationExpression; } if (propertyInitialization.Property is PSMBridgeAssociation) { PSMAssociation p = ((PSMBridgeAssociation)propertyInitialization.Property).SourceAsscociation; changeInstancesSet.AssociationInitializations[p] = propertyInitialization.InitializationExpression; } } } } catch { } } } ClassifyNodes(changeInstancesSet, schema2); return(changeInstancesSet); }