Esempio n. 1
0
 public IElementaryChange ConvertIntoMove(ICompositionDeletion originChange)
 {
     return(new CompositionMoveToCollection
     {
         AffectedElement = AffectedElement,
         MovedElement = AddedElement,
         Feature = Feature,
         Origin = originChange
     });
 }
Esempio n. 2
0
 public IElementaryChange ConvertIntoMove(ICompositionDeletion originChange)
 {
     return(new CompositionMoveIntoProperty
     {
         AffectedElement = AffectedElement,
         OldValue = OldValue,
         NewValue = NewValue,
         Feature = Feature,
         Origin = originChange
     });
 }
Esempio n. 3
0
        private IModelChange CreateMove(ICompositionDeletion deletion)
        {
            var parent = deletion.DeletedElement.Parent;
            int index;
            var reference = parent.GetContainerReference(deletion.DeletedElement, out index);

            if (reference == null || !reference.IsContainment)
            {
                throw new InvalidOperationException("There is something wrong with your generated code. Please regenerate and try again. If the problem persists, please contact the NMF developers.");
            }
            if (reference.UpperBound == 1)
            {
                return(new CompositionMoveIntoProperty
                {
                    AffectedElement = parent,
                    Feature = reference,
                    NewValue = deletion.DeletedElement,
                    OldValue = null,
                    Origin = deletion
                });
            }
            else
            {
                if (reference.IsOrdered)
                {
                    return(new CompositionMoveToList
                    {
                        AffectedElement = parent,
                        Feature = reference,
                        MovedElement = deletion.DeletedElement,
                        Index = index,
                        Origin = deletion
                    });
                }
                else
                {
                    return(new CompositionMoveToCollection
                    {
                        AffectedElement = parent,
                        Feature = reference,
                        MovedElement = deletion.DeletedElement,
                        Origin = deletion
                    });
                }
            }
        }
Esempio n. 4
0
        private void ConnectInsertionsAndDeletions(List <IModelChange> list)
        {
            for (int i = list.Count - 1; i >= 0; i--)
            {
                IElementaryChange elementary = list[i] as IElementaryChange;
                if (elementary != null && elementary.AffectedElement != null && elementSources.ContainsKey(elementary.AffectedElement))
                {
                    list.RemoveAt(i);
                }
                else
                {
                    var t = list[i] as IChangeTransaction;
                    if (t != null && t.NestedChanges.Count == 1)
                    {
                    }
                }
            }
            int currentIndex = 0;

            while (currentIndex < list.Count)
            {
                ICompositionDeletion deletion = list[currentIndex] as ICompositionDeletion;
                if (deletion != null && deletion.DeletedElement.Parent != null)
                {
                    ElementSourceInfo sourceInfo;
                    if (elementSources.TryGetValue(deletion.DeletedElement, out sourceInfo))
                    {
                        elementSources.Remove(deletion.DeletedElement);
                        foreach (var item in deletion.DeletedElement.Descendants())
                        {
                            elementSources.Remove(item);
                        }
                        list.RemoveAt(currentIndex);
                        continue;
                    }
                    if (currentIndex < list.Count)
                    {
                        TryEliminateDeletion(list, ref currentIndex, deletion);
                    }
                }
                currentIndex++;
            }
        }
Esempio n. 5
0
 private void TryEliminateDeletion(List <IModelChange> list, ref int currentIndex, ICompositionDeletion deletion)
 {
     for (int i = 0; i < list.Count; i++)
     {
         var insertion = list[i] as ICompositionInsertion;
         if (insertion == null)
         {
             var transaction = list[i] as IChangeTransaction;
             if (transaction != null && transaction.NestedChanges.Count == 1)
             {
                 insertion = transaction.NestedChanges[0] as ICompositionInsertion;
             }
         }
         if (insertion != null && insertion.AddedElement == deletion.DeletedElement)
         {
             RemoveAllElementSources(insertion.AddedElement);
             list[i] = insertion.ConvertIntoMove(deletion);
             list.RemoveAt(currentIndex);
             currentIndex--;
             return;
         }
         else if (insertion != null && IsAncestor(insertion.AddedElement, deletion.DeletedElement))
         {
             RemoveAllElementSources(deletion.DeletedElement);
             list.RemoveAt(currentIndex);
             list.Insert(currentIndex, CreateMove(deletion));
             currentIndex--;
             return;
         }
     }
 }