public override void ElementDeleted(ElementDeletedEventArgs e)
        {
            DataContractBaseCanBeContainedOnContracts link = e.ModelElement as DataContractBaseCanBeContainedOnContracts;

            Debug.Assert(link != null, "link != null");

            DataContractBase sourceDataContractBase = link.DataContractBase;
            Contract         targetContractElement  = link.Contract;

            if (targetContractElement is DataContract)
            {
                DataContract dataContractElement = targetContractElement as DataContract;

                RemoveDataElement(
                    dataContractElement.Store,
                    dataContractElement.DataMembers,
                    GetDataElement(dataContractElement.DataMembers, link.Id));
            }
            else if (targetContractElement is FaultContract)
            {
                FaultContract faultContractElement = targetContractElement as FaultContract;

                RemoveDataElement(
                    faultContractElement.Store,
                    faultContractElement.DataMembers,
                    GetDataElement(faultContractElement.DataMembers, link.Id));
            }

            base.ElementDeleted(e);
        }
예제 #2
0
 public override void ElementPropertyChanged(ElementPropertyChangedEventArgs e)
 {
     if (e.DomainProperty.Id == DataContractBase.NameDomainPropertyId)
     {
         DataContractBase dataContract = e.ModelElement as DataContractBase;
         string           oldValue     = e.OldValue.ToString();
         foreach (Contract element in dataContract.Contracts)
         {
             if (element is DataContract)
             {
                 ((DataContract)element).DataMembers.ForEach(delegate(DataMember dataElement)
                 {
                     UpdatedElement(dataElement as ModelElementReference, e);
                 });
             }
             else if (element is FaultContract)
             {
                 ((FaultContract)element).DataMembers.ForEach(delegate(DataMember dataElement)
                 {
                     UpdatedElement(dataElement as ModelElementReference, e);
                 });
             }
         }
     }
 }
예제 #3
0
        public static ElementLink Connect(ModelElement source, ModelElement target, string targetDataElementName)
        {
            Guard.ArgumentNotNull(source, "source");
            Guard.ArgumentNotNull(target, "target");

            if (CanAcceptSourceAndTarget(source, target))
            {
                if (source is DataContractBase)
                {
                    if (target is DataContract)
                    {
                        DataContractBase sourceAccepted = (DataContractBase)source;
                        Contract         targetAccepted = (Contract)target;
                        ElementLink      result         = new DataContractBaseCanBeContainedOnContracts(sourceAccepted, targetAccepted);
                        if (DomainClassInfo.HasNameProperty(result))
                        {
                            DomainClassInfo.SetUniqueName(result);
                        }

                        using (Transaction transaction = targetAccepted.Store.TransactionManager.BeginTransaction())
                        {
                            ModelElementReference dataElement = target.Store.ElementFactory.CreateElement(ModelElementReference.DomainClassId) as ModelElementReference;
                            dataElement.ModelElementGuid = result.Id;
                            dataElement.Type             = sourceAccepted.Name;

                            LinkedElementCollection <DataMember> members = ((DataContract)target).DataMembers;

                            dataElement.Name = GetDataElementName(sourceAccepted.Name, targetAccepted.Name, members);
                            members.Add(dataElement);

                            transaction.Commit();
                        }
                        return(result);
                    }
                }
            }

            Debug.Fail("Having agreed that the connection can be accepted we should never fail to make one.");
            throw new InvalidOperationException();
        }
예제 #4
0
 private static bool HasNullReferences(DataContractBase candidateSource, Contract candidateTarget)
 {
     return(candidateSource == null || candidateTarget == null);
 }
		private List<DataMember> LoadLinkedElements(DataContractBase sourceElement)
		{
			DataContract targetElement = new DataContract(Store);
			targetElement.Name = DataContractLinkedElementType;
			DataContractBaseCanBeContainedOnContracts link = new DataContractBaseCanBeContainedOnContracts(sourceElement, targetElement);

			List<DataMember> dataElements = new List<DataMember>();
			ModelElementReference element1 = new ModelElementReference(Store);
			element1.Name = sourceElement.Name;
			element1.Type = sourceElement.Name;
			element1.SetLinkedElement(link.Id);

			dataElements.Add(element1);
			return dataElements;
		}
예제 #6
0
		public static DslModeling::LinkedElementCollection<Contract> GetContracts(DataContractBase element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Contract>, Contract>(element, DataContractBaseDomainRoleId);
		}
예제 #7
0
		/// <summary>
		/// Constructor
		/// Creates a DataContractBaseIsBeingReferenceOnDataContractCollections link in the same Partition as the given DataContractBase
		/// </summary>
		/// <param name="source">DataContractBase to use as the source of the relationship.</param>
		/// <param name="target">DataContractCollection to use as the target of the relationship.</param>
		public DataContractBaseIsBeingReferenceOnDataContractCollections(DataContractBase source, DataContractCollection target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DataContractBaseIsBeingReferenceOnDataContractCollections.DataContractBaseDomainRoleId, source), new DslModeling::RoleAssignment(DataContractBaseIsBeingReferenceOnDataContractCollections.DataContractCollectionDomainRoleId, target)}, null)
		{
		}
예제 #8
0
		public static void SetDataContract(DataContractCollection element, DataContractBase newDataContractBase)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, DataContractCollectionDomainRoleId, newDataContractBase);
		}
예제 #9
0
		/// <summary>
		/// Constructor
		/// Creates a DataContractBaseCanBeContainedOnContracts link in the same Partition as the given DataContractBase
		/// </summary>
		/// <param name="source">DataContractBase to use as the source of the relationship.</param>
		/// <param name="target">Contract to use as the target of the relationship.</param>
		public DataContractBaseCanBeContainedOnContracts(DataContractBase source, Contract target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DataContractBaseCanBeContainedOnContracts.DataContractBaseDomainRoleId, source), new DslModeling::RoleAssignment(DataContractBaseCanBeContainedOnContracts.ContractDomainRoleId, target)}, null)
		{
		}
		private static bool HasNullReferences(DataContractBase candidateSource, Contract candidateTarget)
		{
			return candidateSource == null || candidateTarget == null;
		}
예제 #11
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, DataContractBase element, global::System.Xml.XmlWriter writer)
		{
			// DataContractBaseCanBeContainedOnContracts
			global::System.Collections.ObjectModel.ReadOnlyCollection<DataContractBaseCanBeContainedOnContracts> allDataContractBaseCanBeContainedOnContractsInstances = DataContractBaseCanBeContainedOnContracts.GetLinksToContracts(element);
			if (!serializationContext.Result.Failed && allDataContractBaseCanBeContainedOnContractsInstances.Count > 0)
			{
				writer.WriteStartElement("contracts");
				foreach (DataContractBaseCanBeContainedOnContracts eachDataContractBaseCanBeContainedOnContractsInstance in allDataContractBaseCanBeContainedOnContractsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					DslModeling::DomainClassXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(eachDataContractBaseCanBeContainedOnContractsInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for " + eachDataContractBaseCanBeContainedOnContractsInstance.GetDomainClass().Name + "!");
					relSerializer.Write(serializationContext, eachDataContractBaseCanBeContainedOnContractsInstance, writer);
				}
				writer.WriteEndElement();
			}
	
			// DataContractBaseIsBeingReferenceOnDataContractCollections
			global::System.Collections.ObjectModel.ReadOnlyCollection<DataContractBaseIsBeingReferenceOnDataContractCollections> allDataContractBaseIsBeingReferenceOnDataContractCollectionsInstances = DataContractBaseIsBeingReferenceOnDataContractCollections.GetLinksToDataContractCollections(element);
			if (!serializationContext.Result.Failed && allDataContractBaseIsBeingReferenceOnDataContractCollectionsInstances.Count > 0)
			{
				DslModeling::DomainRelationshipXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(DataContractBaseIsBeingReferenceOnDataContractCollections.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
				global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for DataContractBaseIsBeingReferenceOnDataContractCollections!");
	
				writer.WriteStartElement("dataContractCollections");
				global::System.Type typeofDataContractBaseIsBeingReferenceOnDataContractCollections = typeof(DataContractBaseIsBeingReferenceOnDataContractCollections);
				foreach (DataContractBaseIsBeingReferenceOnDataContractCollections eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance in allDataContractBaseIsBeingReferenceOnDataContractCollectionsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance.GetType() != typeofDataContractBaseIsBeingReferenceOnDataContractCollections)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachDataContractBaseIsBeingReferenceOnDataContractCollectionsInstance.DataContractCollection;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.WriteMoniker(serializationContext, targetElement, writer, element, relSerializer);
					}
				}
				writer.WriteEndElement();
			}
	
		}
예제 #12
0
		private static void ReadDataContractBaseIsBeingReferenceOnDataContractCollectionsInstances(DslModeling::SerializationContext serializationContext, DataContractBase element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer = serializationContext.Directory.GetSerializer(DataContractCollection.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer != null, "Cannot find serializer for DataContractCollection!");
				DslModeling::Moniker newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollections = newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer.TryCreateMonikerInstance(serializationContext, reader, element, DataContractBaseIsBeingReferenceOnDataContractCollections.DomainClassId, element.Partition);
				if (newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollections != null)
				{
					new DataContractBaseIsBeingReferenceOnDataContractCollections(element.Partition, new DslModeling::RoleAssignment(DataContractBaseIsBeingReferenceOnDataContractCollections.DataContractBaseDomainRoleId, element), new DslModeling::RoleAssignment(DataContractBaseIsBeingReferenceOnDataContractCollections.DataContractCollectionDomainRoleId, newDataContractCollectionMonikerOfDataContractBaseIsBeingReferenceOnDataContractCollections));
					DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
				}
				else
				{
					global::System.Type typeofDataContractBaseIsBeingReferenceOnDataContractCollections = typeof(DataContractBaseIsBeingReferenceOnDataContractCollections);
					DslModeling::DomainRelationshipXmlSerializer newDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer = serializationContext.Directory.GetSerializer(DataContractBaseIsBeingReferenceOnDataContractCollections.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer != null, "Cannot find serializer for DataContractBaseIsBeingReferenceOnDataContractCollections!");
					DataContractBaseIsBeingReferenceOnDataContractCollections newDataContractBaseIsBeingReferenceOnDataContractCollections = newDataContractBaseIsBeingReferenceOnDataContractCollectionsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DataContractBaseIsBeingReferenceOnDataContractCollections;
					if (newDataContractBaseIsBeingReferenceOnDataContractCollections != null)
					{
						if (newDataContractBaseIsBeingReferenceOnDataContractCollections.GetType() == typeofDataContractBaseIsBeingReferenceOnDataContractCollections)
						{	// The relationship should be serialized in short-form.
							DataContractDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(DataContractBaseIsBeingReferenceOnDataContractCollections));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newDataContractBaseIsBeingReferenceOnDataContractCollections, DataContractBaseIsBeingReferenceOnDataContractCollections.DataContractBaseDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataContractBaseIsBeingReferenceOnDataContractCollections.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataContractBaseIsBeingReferenceOnDataContractCollections.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newDataContractBaseIsBeingReferenceOnDataContractCollections, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
예제 #13
0
		private static void ReadDataContractBaseCanBeContainedOnContractsInstances(DslModeling::SerializationContext serializationContext, DataContractBase element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newDataContractBaseCanBeContainedOnContractsSerializer = serializationContext.Directory.GetSerializer(DataContractBaseCanBeContainedOnContracts.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newDataContractBaseCanBeContainedOnContractsSerializer != null, "Cannot find serializer for DataContractBaseCanBeContainedOnContracts!");
				DataContractBaseCanBeContainedOnContracts newDataContractBaseCanBeContainedOnContracts = newDataContractBaseCanBeContainedOnContractsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DataContractBaseCanBeContainedOnContracts;
				if (newDataContractBaseCanBeContainedOnContracts != null)
				{
					DslModeling::DomainRoleInfo.SetRolePlayer (newDataContractBaseCanBeContainedOnContracts, DataContractBaseCanBeContainedOnContracts.DataContractBaseDomainRoleId, element);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataContractBaseCanBeContainedOnContracts.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataContractBaseCanBeContainedOnContracts.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newDataContractBaseCanBeContainedOnContracts, reader);
				}
				else
				{	// Maybe the relationship is serialized in short-form by mistake.
					DslModeling::DomainClassXmlSerializer newContractMonikerOfDataContractBaseCanBeContainedOnContractsSerializer = serializationContext.Directory.GetSerializer(Contract.DomainClassId);
					global::System.Diagnostics.Debug.Assert(newContractMonikerOfDataContractBaseCanBeContainedOnContractsSerializer != null, "Cannot find serializer for Contract!");
					DslModeling::Moniker newContractMonikerOfDataContractBaseCanBeContainedOnContracts = newContractMonikerOfDataContractBaseCanBeContainedOnContractsSerializer.TryCreateMonikerInstance(serializationContext, reader, element, DataContractBaseCanBeContainedOnContracts.DomainClassId, element.Partition);
					if (newContractMonikerOfDataContractBaseCanBeContainedOnContracts != null)
					{
						DataContractDslSerializationBehaviorSerializationMessages.ExpectingFullFormRelationship(serializationContext, reader, typeof(DataContractBaseCanBeContainedOnContracts));
						new DataContractBaseCanBeContainedOnContracts(element.Partition, new DslModeling::RoleAssignment(DataContractBaseCanBeContainedOnContracts.DataContractBaseDomainRoleId, element), new DslModeling::RoleAssignment(DataContractBaseCanBeContainedOnContracts.ContractDomainRoleId, newContractMonikerOfDataContractBaseCanBeContainedOnContracts));
						DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
					}
					else
					{	// Unknown element, skip.
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
예제 #14
0
		/// <summary>
		/// This method deserializes all child model elements.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first child XML element to deserialized.
		/// This method will read as many child elements as it can. It returns under three circumstances:
		/// 1) When an unknown child XML element is encountered. In this case, this method will position the reader at the 
		///    open tag of the unknown element. This implies that if the first child XML element is unknown, this method 
		///    should return immediately and do nothing.
		/// 2) When all child XML elemnets are read. In this case, the reader will be positioned at the end tag of the parent element.
		/// 3) EOF.
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		/// <param name="element">In-memory DataContractBase instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, DataContractBase element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				switch (reader.LocalName)
				{
					case "contracts":	// Relationship "DataContractBaseCanBeContainedOnContracts"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <contracts>
							ReadDataContractBaseCanBeContainedOnContractsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </contracts>
						}
						break;
					case "dataContractCollections":	// Relationship "DataContractBaseIsBeingReferenceOnDataContractCollections"
						if (reader.IsEmptyElement)
						{	// No instance of this relationship, just skip
							DslModeling::SerializationUtilities.Skip(reader);
						}
						else
						{
							DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <dataContractCollections>
							ReadDataContractBaseIsBeingReferenceOnDataContractCollectionsInstances(serializationContext, element, reader);
							DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </dataContractCollections>
						}
						break;
					default:
						return;  // Don't know this element.
				}
			}
		}