/// <summary> /// Constuctor. /// </summary> /// <param name="viewModelStore">The store this view model belongs to.</param> /// <param name="serializedDomainProperty">SerializedDomainProperty.</param> public SerializedDomainPropertyViewModel(ViewModelStore viewModelStore, SerializedDomainProperty serializedDomainProperty, SerializationClassViewModel parent) : base(viewModelStore, serializedDomainProperty, serializedDomainProperty.DomainProperty, parent) { if (this.SerializationElement != null) { // subscribe this.EventManager.GetEvent <ModelElementPropertyChangedEvent>().Subscribe(this.SerializationElement.Id, new Action <ElementPropertyChangedEventArgs>(OnSerializedPropertyPropertyChanged)); if (this.SerializationElement.DomainProperty != null) { // TODO: Add, Change, Delete property type } } }
public void ValidateSerializationClass(ValidationContext context) { // Only one property's serialization representation type can be declared as "inner value" per element. bool bHasInnerValueAttribute = false; foreach (SerializationAttributeElement element in this.Attributes) { if (element is SerializedDomainProperty) { SerializedDomainProperty p = element as SerializedDomainProperty; if (p.SerializationRepresentationType == SerializationRepresentationType.InnerValue) { if (!bHasInnerValueAttribute) { bHasInnerValueAttribute = true; if (this is SerializedDomainClass) { // Abstract classes can not have a property with serialization representation type set to "inner value". if ((this as SerializedDomainClass).DomainClass.InheritanceModifier == InheritanceModifier.Abstract) { context.LogError("Abstract classes can not have a property with serialization representation type set to 'inner value'. Error on " + this.SerializationName, "InnerValuePropertyOnAbstractElement", null); //this); } } else if (this is SerializedReferenceRelationship) { // Abstract classes can not have a property with serialization representation type set to "inner value". if ((this as SerializedReferenceRelationship).ReferenceRelationship.InheritanceModifier == InheritanceModifier.Abstract) { context.LogError("Abstract classes can not have a property with serialization representation type set to 'inner value'. Error on " + this.SerializationName, "InnerValuePropertyOnAbstractElement", null); //this); } } else if (this is SerializedEmbeddingRelationship) { // Abstract classes can not have a property with serialization representation type set to "inner value". if ((this as SerializedEmbeddingRelationship).EmbeddingRelationship.InheritanceModifier == InheritanceModifier.Abstract) { context.LogError("Abstract classes can not have a property with serialization representation type set to 'inner value'. Error on " + this.SerializationName, "InnerValuePropertyOnAbstractElement", null); //this); } } } else { context.LogError("Only one property's serialization representation type can be declared as 'inner value' per element. Error on " + this.SerializationName, "MultipleInnerValueProperties", null); //this); } } } } }
private static SerializedDomainProperty CreateSerializedDomainProperty(DomainProperty domainProperty) { SerializedDomainProperty serializedDomainProperty = new SerializedDomainProperty(domainProperty.Store); serializedDomainProperty.DomainProperty = domainProperty; if (serializedDomainProperty.SerializationName != domainProperty.SerializationName) { serializedDomainProperty.SerializationName = domainProperty.SerializationName; serializedDomainProperty.SerializationRepresentationType = domainProperty.SerializationRepresentationType; if (domainProperty.IsSerializationNameTracking == TrackingEnum.True) { serializedDomainProperty.IsSerializationNameTracking = TrackingEnum.IgnoreOnce; } } serializedDomainProperty.SerializationRepresentationType = serializedDomainProperty.SerializationRepresentationType; return(serializedDomainProperty); }
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; }
public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e) { if (e.ModelElement != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction != null) { if (e.ModelElement.Store.TransactionManager.CurrentTransaction.IsSerializing) { return; } } } if (e.ModelElement == null) { return; } if (ImmutabilityExtensionMethods.GetLocks(e.ModelElement) != Locks.None) { return; } SerializedDomainProperty serializedDomainProperty = e.ModelElement as SerializedDomainProperty; if (serializedDomainProperty != null) { if (e.DomainProperty.Id == SerializedDomainProperty.SerializationNameDomainPropertyId) { if (serializedDomainProperty.IsSerializationNameTracking == TrackingEnum.True) { serializedDomainProperty.IsSerializationNameTracking = TrackingEnum.False; } else if (serializedDomainProperty.IsSerializationNameTracking == TrackingEnum.IgnoreOnce) { serializedDomainProperty.IsSerializationNameTracking = TrackingEnum.True; } if (serializedDomainProperty.DomainProperty.SerializationName != serializedDomainProperty.SerializationName) { serializedDomainProperty.DomainProperty.SerializationName = serializedDomainProperty.SerializationName; serializedDomainProperty.DomainProperty.IsSerializationNameTracking = serializedDomainProperty.IsSerializationNameTracking; } } else if (e.DomainProperty.Id == SerializedDomainProperty.SerializationRepresentationTypeDomainPropertyId) { serializedDomainProperty.DomainProperty.SerializationRepresentationType = serializedDomainProperty.SerializationRepresentationType; if (serializedDomainProperty.SerializationRepresentationType != SerializationRepresentationType.Attribute) { for (int i = serializedDomainProperty.ParentAttributedElements.Count - 1; i >= 0; i--) { serializedDomainProperty.ParentAttributedElements[i].Children.Add(serializedDomainProperty); serializedDomainProperty.ParentAttributedElements[i].Attributes.Remove(serializedDomainProperty); } } if (serializedDomainProperty.SerializationRepresentationType == SerializationRepresentationType.Attribute) { for (int i = serializedDomainProperty.ParentEmbeddedElements.Count - 1; i >= 0; i--) { serializedDomainProperty.ParentEmbeddedElements[i].Attributes.Add(serializedDomainProperty); serializedDomainProperty.ParentEmbeddedElements[i].Children.Remove(serializedDomainProperty); } } } } }
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(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; }