/// <summary> /// Finalize. This method is called on each copied element once all the elements and links are processed. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> public virtual void ModelFinalize(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; Guid elementID = options.ElementId; ModelProtoElement elementP = groupMerger.GetElementById(elementID); if (elementP != null) { (this.Element as IModelMergeElements).ModelFinalize(elementP, groupMerger); } NodeShape shape = this.Store.ElementDirectory.FindElement( groupMerger.GetIdMapping(protoElement.ElementId)) as NodeShape; // restore layout Store store = new Microsoft.VisualStudio.Modeling.Store(typeof(DiagramsDSLDomainModel)); LayoutInfo info; using (Transaction t = store.TransactionManager.BeginTransaction()) { info = options.GetLayoutInfo(store); t.Commit(); } LayoutHelper.ApplyLayout(this, this.Diagram, info); store.Dispose(); if (!shape.IsRelativeChildShape) { shape.SetLocation(new PointD(RelativePastePoint.X + options.RelativeLocation.X, RelativePastePoint.Y + options.RelativeLocation.Y)); } } }
/// <summary> /// Moves a proto element to the current element. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> public virtual void ModelMove(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { /* * if (protoElement.CustomArguments is DiagramModelMergeOptions) * { * DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; * * Guid elementID = options.ElementId; * ModelProtoElement elementP = groupMerger.ProtoGroup.GetProtoElementFor(elementID, this.Partition); * if (elementP != null) * { * (this.Element as IModelMergeElements).ModelMove(elementP, groupMerger); * } * * ModelElement movedElement = this.Store.ElementDirectory.FindElement(options.ElementId); * NodeShape shape = DiagramHelper.FindShape(this.Store, options.ShapeDomainClassId, movedElement.Id) as NodeShape; * if (shape != null) * { * if (shape.IsRelativeChildShape) * this.AddRelativeChild(shape); * else * this.AddNestedChild(shape); * * groupMerger.AddIdMapping(protoElement.ElementId, shape.Id); * } * }*/ }
/// <summary> /// Adds a proto element to the current element. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> /// <param name="isRoot">Root element?</param> public virtual void ModelMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool isRoot) { if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; Guid elementID = options.ElementId; ModelProtoElement elementP = groupMerger.GetElementById(elementID); if (elementP != null) { (this.Element as IModelMergeElements).ModelMerge(elementP, groupMerger, isRoot); } ModelElement copiedElement = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(options.ElementId)); // create shape for that element this.FixUpMissingShapes(); NodeShape shape = DiagramHelper.FindShape(this.Store, options.ShapeDomainClassId, copiedElement.Id) as NodeShape; if (shape != null) { groupMerger.SetIdMapping(protoElement.ElementId, shape.Id); } } }
public override void ModelFinalizeMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { base.ModelFinalizeMerge(protoElement, groupMerger); if (protoElement.Name == "DomainClass") { FinalizeDomainClassMerge(protoElement, groupMerger); } }
private static int SortProtoElements(ModelProtoElement x, ModelProtoElement y) { if (x.Name == "DomainClass" && y.Name != "DomainClass") { return(-1); } else if (x.Name != "DomainClass" && y.Name == "DomainClass") { return(1); } return(0); }
/// <summary> /// Create a proto element representation of the element, which can be used for paste later. /// </summary> /// <param name="protoGroup">Proto group to add the element to.</param> /// <returns>Proto element representation of the element.</returns> public virtual ModelProtoElement ModelCreateMoveCopy(ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) if (!ModelIsMoveAllowed()) return null; if (protoGroup.Operation == ModelProtoGroupOperation.Copy) return null; ModelProtoElement protoElement = new ModelProtoElement(this); protoGroup.AddNewElement(protoElement); ModelProcessMergeCopy(protoElement, protoGroup); return protoElement; }
private void FinalizeReferenceRelationshipMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool bCreateSInfo) { ReferenceRelationship refRel = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as ReferenceRelationship; if (bCreateSInfo) { SerializationDomainRelationshipAddRule.OnReferenceRelationshipAdded(refRel); } if (refRel == null) { return; } ModelTreeHelper.AddNewReferenceRelationship(refRel, refRel.Source.RolePlayer as DomainClass, refRel.Target.RolePlayer); }
private void FinalizeEmbeddingRelationshipsMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool bCreateSInfo) { EmbeddingRelationship embRel = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as EmbeddingRelationship; if (bCreateSInfo) { SerializationDomainRelationshipAddRule.OnEmbeddingRelationshipAdded(embRel); } if (embRel == null) { return; } ModelTreeHelper.AddNewEmbeddingRS(embRel, embRel.Source.RolePlayer as DomainClass, embRel.Target.RolePlayer, false); }
/// <summary> /// Decides whether the element that is represented by the proto element can be pasted or not. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> /// <returns>True if the element can be pasted. False otherwise.</returns> public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) { return(false); } if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; return(this.CanHostShape(options.ShapeDomainClassId)); } return(false); }
/// <summary> /// Decides whether the element that is represented by the proto element can be pasted or not. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> /// <returns>True if the element can be pasted. False otherwise.</returns> public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) { return(false); } if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; Guid elementID = options.ElementId; ModelProtoElement elementP = protoGroup.GetProtoElementFor(elementID, this.Partition); if (elementP != null) { return((this.Element as IModelMergeElements).ModelCanMerge(elementP, protoGroup)); } } return(false); }
/// <summary> /// Create a proto element representation of the element, which can be used for paste later. /// </summary> /// <param name="protoGroup">Proto group to add the element to.</param> /// <returns>Proto element representation of the element.</returns> public virtual ModelProtoElement ModelCreateMoveCopy(ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) { if (!ModelIsMoveAllowed()) { return(null); } } if (protoGroup.Operation == ModelProtoGroupOperation.Copy) { return(null); } ModelProtoElement protoElement = new ModelProtoElement(this); protoGroup.AddNewElement(protoElement); ModelProcessMergeCopy(protoElement, protoGroup); return(protoElement); }
/// <summary> /// Processes a proto element representation of the element and adds required proto links. /// This method is called on base classes from derived classes. /// /// Hint: Properties do not need to be added in this method. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Copy) { (this.Element as IModelMergeElements).ModelCreateMergeCopy(protoGroup); } else { (this.Element as IModelMergeElements).ModelCreateMoveCopy(protoGroup); } // TODO: get parent element. this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush; using (Transaction t = this.Store.TransactionManager.BeginTransaction()) { DiagramModelMergeOptions operations = new DiagramModelMergeOptions(LayoutHelper.CreateLayoutInfo( this, this.Diagram), this.Element.Id, this.Element.GetDomainClass().Id, this.GetDomainClass().Id); PointD relativeLocation = this.Location; if (!this.IsRelativeChildShape) { if (RelativeMinCopyPoint.X <= relativeLocation.X) { relativeLocation.X -= RelativeMinCopyPoint.X; } if (RelativeMinCopyPoint.Y <= relativeLocation.Y) { relativeLocation.Y -= RelativeMinCopyPoint.Y; } operations.RelativeLocation = relativeLocation; protoElement.CustomArguments = operations; } t.Commit(); } this.Store.UndoManager.UndoState = UndoState.Enabled; }
/// <summary> /// Finalize merge. This method is called on the root element once all the elements and links are processed. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> /// <remarks> /// This is called after the finalize method. /// </remarks> public virtual void ModelFinalizeMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { (this.Element as IModelMergeElements).ModelFinalizeMerge(protoElement, groupMerger); }
/// <summary> /// Moves a proto element to the current element. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> public virtual void ModelMove(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { /* if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; Guid elementID = options.ElementId; ModelProtoElement elementP = groupMerger.ProtoGroup.GetProtoElementFor(elementID, this.Partition); if (elementP != null) { (this.Element as IModelMergeElements).ModelMove(elementP, groupMerger); } ModelElement movedElement = this.Store.ElementDirectory.FindElement(options.ElementId); NodeShape shape = DiagramHelper.FindShape(this.Store, options.ShapeDomainClassId, movedElement.Id) as NodeShape; if (shape != null) { if (shape.IsRelativeChildShape) this.AddRelativeChild(shape); else this.AddNestedChild(shape); groupMerger.AddIdMapping(protoElement.ElementId, shape.Id); } }*/ }
/// <summary> /// Decides whether the element that is represented by the proto element can be pasted or not. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> /// <returns>True if the element can be pasted. False otherwise.</returns> public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) return false; if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; return this.CanHostShape(options.ShapeDomainClassId); } return false; }
/// <summary> /// Decides whether the element that is represented by the proto element can be pasted or not. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> /// <returns>True if the element can be pasted. False otherwise.</returns> public virtual bool ModelCanMerge(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if (protoGroup.Operation == ModelProtoGroupOperation.Move) return false; if (protoElement.CustomArguments is DiagramModelMergeOptions) { DiagramModelMergeOptions options = protoElement.CustomArguments as DiagramModelMergeOptions; Guid elementID = options.ElementId; ModelProtoElement elementP = protoGroup.GetProtoElementFor(elementID, this.Partition); if (elementP != null) { return (this.Element as IModelMergeElements).ModelCanMerge(elementP, protoGroup); } } return false; }
/// <summary> /// Finalize. This method is called on each copied element once all the elements and links are processed. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> public virtual void ModelFinalize(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { }
/// <summary> /// Adds a proto element to the current element. /// </summary> /// <param name="protoElement">Proto element representation of the element that is to be added.</param> /// <param name="groupMerger"> /// Group merger class used to track id mapping, merge errors/warnings and /// postprocess merging by rebuilding reference relationships. /// </param> /// <param name="isRoot">Root element?</param> public virtual void ModelMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger, bool isRoot) { }
/// <summary> /// Processes a proto element representation of the element and adds required proto links. /// This method is called on base classes from derived classes. /// /// Hint: Properties do not need to be added in this method. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { }
public override void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { base.ModelProcessMergeCopy(protoElement, protoGroup); bool isInFull = false; bool isTargetInc = false; SerializationClass sClass; if (this is ReferenceRelationship) { sClass = (this as ReferenceRelationship).SerializedReferenceRelationship; isInFull = (this as ReferenceRelationship).SerializedReferenceRelationship.IsInFullSerialization; } else { sClass = (this as EmbeddingRelationship).SerializedEmbeddingRelationship; isInFull = (this as EmbeddingRelationship).SerializedEmbeddingRelationship.IsInFullSerialization; isTargetInc = (this as EmbeddingRelationship).SerializedEmbeddingRelationship.IsTargetIncludedSubmodel; } // copy order of attributes and children DomainRelationshipSerializationInfo info = new DomainRelationshipSerializationInfo( sClass.Children.Count, sClass.Attributes.Count); info.IsInFullSerialization = isInFull; info.IsTargetIncludedSubmodel = isTargetInc; for (int i = 0; i < sClass.Attributes.Count; i++) { SerializationAttributeElement aatr = sClass.Attributes[i]; if (aatr is SerializedDomainProperty) { SerializedDomainProperty sP = aatr as SerializedDomainProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo( sP.DomainProperty.Name, sP.DomainProperty.Id); if (sP.OmitProperty) { sInfo.OmitElement = true; } info.AttributesOrder.Add(sInfo); } else if (aatr is SerializedIdProperty) { SerializedIdProperty sI = aatr as SerializedIdProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo("SerializedIdProperty", Guid.Empty); if (sI.OmitIdProperty) { sInfo.OmitElement = true; } info.AttributesOrder.Add(sInfo); } } for (int i = 0; i < sClass.Children.Count; i++) { SerializationElement sE = sClass.Children[i]; if (sE is SerializedDomainProperty) { SerializedDomainProperty sP = sE as SerializedDomainProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo( sP.DomainProperty.Name, sP.DomainProperty.Id); if (sP.OmitProperty) { sInfo.OmitElement = true; } info.ChildrenOrder.Add(sInfo); } } protoElement.CustomArguments = info; }
/// <summary> /// Processes a proto element representation of the element and adds required proto links. /// This method is called on base classes from derived classes. /// /// Hint: Properties do not need to be added in this method. /// </summary> /// <param name="protoElement">Proto element representation of the element.</param> /// <param name="protoGroup">Proto group the proto element belongs to.</param> public virtual void ModelProcessMergeCopy(ModelProtoElement protoElement, ModelProtoGroup protoGroup) { if( protoGroup.Operation == ModelProtoGroupOperation.Copy ) (this.Element as IModelMergeElements).ModelCreateMergeCopy(protoGroup); else (this.Element as IModelMergeElements).ModelCreateMoveCopy(protoGroup); // TODO: get parent element. this.Store.UndoManager.UndoState = UndoState.DisabledNoFlush; using (Transaction t = this.Store.TransactionManager.BeginTransaction()) { DiagramModelMergeOptions operations = new DiagramModelMergeOptions(LayoutHelper.CreateLayoutInfo( this, this.Diagram), this.Element.Id, this.Element.GetDomainClass().Id, this.GetDomainClass().Id); PointD relativeLocation = this.Location; if (!this.IsRelativeChildShape) { if (RelativeMinCopyPoint.X <= relativeLocation.X) relativeLocation.X -= RelativeMinCopyPoint.X; if (RelativeMinCopyPoint.Y <= relativeLocation.Y) relativeLocation.Y -= RelativeMinCopyPoint.Y; operations.RelativeLocation = relativeLocation; protoElement.CustomArguments = operations; } t.Commit(); } this.Store.UndoManager.UndoState = UndoState.Enabled; }
private void FinalizeDomainClassMerge(ModelProtoElement protoElement, ModelProtoGroupMerger groupMerger) { DomainClass domainClass = this.Store.ElementDirectory.FindElement(groupMerger.GetIdMapping(protoElement.ElementId)) as DomainClass; if (domainClass == null) { return; } if (protoElement.CustomArguments != null) { if (protoElement.CustomArguments is DomainClassSerializationInfo) { DomainClassSerializationInfo info = (DomainClassSerializationInfo)protoElement.CustomArguments; if (info != null) { for (int i = 0; i < info.AttributesOrder.Count; i++) { #region Attributes ElementSerializationInfo eInfo = info.AttributesOrder[i] as ElementSerializationInfo; Guid newId = Guid.Empty; if (eInfo.ElementName != "SerializedIdProperty") { try { newId = groupMerger.GetIdMapping(eInfo.ElementId); } catch { newId = Guid.Empty; } if (newId == Guid.Empty) { ModelElement m = this.Store.ElementDirectory.FindElement(eInfo.ElementId); if (m != null) { newId = m.Id; } } } for (int y = 0; y < domainClass.SerializedDomainClass.Attributes.Count; y++) { if (domainClass.SerializedDomainClass.Attributes[y] is SerializedIdProperty && eInfo.ElementName == "SerializedIdProperty") { (domainClass.SerializedDomainClass.Attributes[y] as SerializedIdProperty).OmitIdProperty = eInfo.OmitElement; if (y != i) { domainClass.SerializedDomainClass.Attributes.Move(y, i); } break; } else if (eInfo.ElementName != "SerializedIdProperty" && !(domainClass.SerializedDomainClass.Attributes[y] is SerializedIdProperty)) { SerializedDomainProperty p = domainClass.SerializedDomainClass.Attributes[y] as SerializedDomainProperty; p.OmitProperty = eInfo.OmitElement; if (p.DomainProperty.Id == newId && y != i) { domainClass.SerializedDomainClass.Attributes.Move(y, i); break; } } } #endregion } for (int i = 0; i < info.ChildrenOrder.Count; i++) { #region Children ElementSerializationInfo eInfo = info.ChildrenOrder[i] as ElementSerializationInfo; Guid newId = Guid.Empty; try { newId = groupMerger.GetIdMapping(eInfo.ElementId); } catch { newId = Guid.Empty; } if (newId == Guid.Empty) { ModelElement m = this.Store.ElementDirectory.FindElement(eInfo.ElementId); if (m != null) { newId = m.Id; } } for (int y = i; y < domainClass.SerializedDomainClass.Children.Count; y++) { if (domainClass.SerializedDomainClass.Children[y] is SerializedReferenceRelationship) { SerializedReferenceRelationship sDomainRel = domainClass.SerializedDomainClass.Children[y] as SerializedReferenceRelationship; if (sDomainRel.ReferenceRelationship.Id == newId) { sDomainRel.OmitRelationship = eInfo.OmitElement; if (y != i) { domainClass.SerializedDomainClass.Children.Move(y, i); } break; } } else if (domainClass.SerializedDomainClass.Children[y] is SerializedEmbeddingRelationship) { SerializedEmbeddingRelationship sDomainRel = domainClass.SerializedDomainClass.Children[y] as SerializedEmbeddingRelationship; if (sDomainRel.EmbeddingRelationship.Id == newId) { sDomainRel.OmitRelationship = eInfo.OmitElement; if (y != i) { domainClass.SerializedDomainClass.Children.Move(y, i); } break; } } else if (domainClass.SerializedDomainClass.Children[y] is SerializedDomainProperty) { SerializedDomainProperty p = domainClass.SerializedDomainClass.Children[y] as SerializedDomainProperty; if (p.DomainProperty.Id == newId) { p.OmitProperty = eInfo.OmitElement; if (y != i) { domainClass.SerializedDomainClass.Children.Move(y, i); } break; } } } #endregion } } } } }
public override void ModelProcessMergeCopy(CopyPaste.ModelProtoElement protoElement, CopyPaste.ModelProtoGroup protoGroup) { base.ModelProcessMergeCopy(protoElement, protoGroup); // copy rs and target elements if required if (CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyEmbeddingTree || CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyAllTree || CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyReferenceTree) { foreach (DomainRole role in this.RolesPlayed) { if (role.Relationship is EmbeddingRelationship && role.Relationship.Source == role) { if (CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyEmbeddingTree || CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyAllTree) { ModelProtoElement e = (role.Relationship as IModelMergeElements).ModelCreateMergeCopy(protoGroup); protoGroup.AddNewRootElement(e); // continue with target element if (ImmutabilityExtensionMethods.GetLocks(role.Relationship.Target.RolePlayer) == Locks.None) { if (!protoGroup.HasProtoElementFor(role.Relationship.Target.RolePlayer.Id, this.Partition)) { ModelProtoElement d = (role.Relationship.Target.RolePlayer as IModelMergeElements).ModelCreateMergeCopy(protoGroup); protoGroup.InsertNewRootElement(d, 0); } } } } else if (role.Relationship is ReferenceRelationship && role.Relationship.Source == role) { if (CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyAllTree || CopyPaste.CopyAndPasteOperations.Operation == CopyPaste.CopyAndPasteOperation.CopyReferenceTree) { ModelProtoElement e = (role.Relationship as IModelMergeElements).ModelCreateMergeCopy(protoGroup); protoGroup.AddNewRootElement(e); } } } // sort proto elements: bring domain classes to the top protoGroup.SortProtoElements(SortProtoElements); } // copy order of attributes and children DomainClassSerializationInfo info = new DomainClassSerializationInfo( this.SerializedDomainClass.Children.Count, this.SerializedDomainClass.Attributes.Count); for (int i = 0; i < this.SerializedDomainClass.Attributes.Count; i++) { SerializationAttributeElement aatr = this.SerializedDomainClass.Attributes[i]; if (aatr is SerializedDomainProperty) { SerializedDomainProperty sP = aatr as SerializedDomainProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo( sP.DomainProperty.Name, sP.DomainProperty.Id); if (sP.OmitProperty) { sInfo.OmitElement = true; } info.AttributesOrder.Add(sInfo); } else if (aatr is SerializedIdProperty) { SerializedIdProperty sI = aatr as SerializedIdProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo("SerializedIdProperty", Guid.Empty); if (sI.OmitIdProperty) { sInfo.OmitElement = true; } info.AttributesOrder.Add(sInfo); } } for (int i = 0; i < this.SerializedDomainClass.Children.Count; i++) { SerializationElement sE = this.SerializedDomainClass.Children[i]; if (sE is SerializedReferenceRelationship) { SerializedReferenceRelationship sDomainRel = sE as SerializedReferenceRelationship; ElementSerializationInfo sInfo = new ElementSerializationInfo( sDomainRel.ReferenceRelationship.Name, sDomainRel.ReferenceRelationship.Id); if (sDomainRel.OmitRelationship) { sInfo.OmitElement = true; } info.ChildrenOrder.Add(sInfo); } else if (sE is SerializedEmbeddingRelationship) { SerializedEmbeddingRelationship sDomainRel = sE as SerializedEmbeddingRelationship; ElementSerializationInfo sInfo = new ElementSerializationInfo( sDomainRel.EmbeddingRelationship.Name, sDomainRel.EmbeddingRelationship.Id); if (sDomainRel.OmitRelationship) { sInfo.OmitElement = true; } info.ChildrenOrder.Add(sInfo); } else if (sE is SerializedDomainProperty) { SerializedDomainProperty sP = sE as SerializedDomainProperty; ElementSerializationInfo sInfo = new ElementSerializationInfo( sP.DomainProperty.Name, sP.DomainProperty.Id); if (sP.OmitProperty) { sInfo.OmitElement = true; } info.ChildrenOrder.Add(sInfo); } } protoElement.CustomArguments = info; }