public void ShouldReturnAsmxDataContractEnumLink()
		{
			DataContractEnum enumElement = new DataContractEnum(Store);
			enumElement.DataContractModel = new DataContractModel(Store);
			AsmxDataContractEnum asmxDCEnum = new AsmxDataContractEnum();
			asmxDCEnum.ModelElement = enumElement;

			Assert.IsInstanceOfType(asmxDCEnum.ArtifactLink, typeof(AsmxDataContractEnumLink));
		}
Exemple #2
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            DataContractEnum  dataContractEnum = e.ModelElement as DataContractEnum;
            DataContractModel root             = dataContractEnum.DataContractModel;

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(dataContractEnum, root.ImplementationTechnology);
            }
        }
		private DataContractEnum CreateDefaultDataContractEnum()
		{
			DataContractEnum rootElement = new DataContractEnum(Store);
			rootElement.DataContractModel = new DataContractModel(Store);
			rootElement.DataContractModel.ProjectMappingTable = "ASMX";
			rootElement.Name = ElementName;
			rootElement.Namespace = ElementNamespace;
			return rootElement;
		}
		/// <summary>
		/// Constructor
		/// Creates a DataContractEnumHasEnumNamedValues link in the same Partition as the given DataContractEnum
		/// </summary>
		/// <param name="source">DataContractEnum to use as the source of the relationship.</param>
		/// <param name="target">EnumNamedValue to use as the target of the relationship.</param>
		public DataContractEnumHasEnumNamedValues(DataContractEnum source, EnumNamedValue target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DataContractEnumHasEnumNamedValues.DataContractEnumDomainRoleId, source), new DslModeling::RoleAssignment(DataContractEnumHasEnumNamedValues.EnumNamedValueDomainRoleId, target)}, null)
		{
		}
		public void TestMembersWithPrimitiveEnumTypeGeneration()
		{
			ProjectMappingManagerSetup.InitializeManager(ServiceProvider, "ProjectMapping.DataContractDsl.Tests.xml");
			DataContract rootElement = CreateDefaultDataContract();
			DataContractEnum enumElement = new DataContractEnum(Store);
			enumElement.Name = PrimitiveDataElementName1;
			rootElement.DataContractModel.Contracts.Add(enumElement);
			rootElement.DataMembers.AddRange(LoadLinkedElements(enumElement));
			string content = RunTemplate(rootElement);
			
			this.EnsureType(ref content, PrimitiveDataElementName1);
			Type generatedType = CompileAndGetType(content);
			KnownTypeAttribute knownTypeAttr = TypeAsserter.AssertAttribute<KnownTypeAttribute>(generatedType);
			
			Assert.AreEqual<string>(PrimitiveDataElementName1, knownTypeAttr.Type.Name);
		}
		public static DslModeling::LinkedElementCollection<EnumNamedValue> GetEnumNamedValues(DataContractEnum element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<EnumNamedValue>, EnumNamedValue>(element, DataContractEnumDomainRoleId);
		}
		public static void SetDataContractEnum(EnumNamedValue element, DataContractEnum newDataContractEnum)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, EnumNamedValueDomainRoleId, newDataContractEnum);
		}
Exemple #8
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, DataContractEnum element, global::System.Xml.XmlWriter writer)
		{
			// DataContractEnumHasEnumNamedValues
			global::System.Collections.ObjectModel.ReadOnlyCollection<DataContractEnumHasEnumNamedValues> allDataContractEnumHasEnumNamedValuesInstances = DataContractEnumHasEnumNamedValues.GetLinksToEnumNamedValues(element);
			if (!serializationContext.Result.Failed && allDataContractEnumHasEnumNamedValuesInstances.Count > 0)
			{
				writer.WriteStartElement("enumNamedValues");
				global::System.Type typeofDataContractEnumHasEnumNamedValues = typeof(DataContractEnumHasEnumNamedValues);
				foreach (DataContractEnumHasEnumNamedValues eachDataContractEnumHasEnumNamedValuesInstance in allDataContractEnumHasEnumNamedValuesInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachDataContractEnumHasEnumNamedValuesInstance.GetType() != typeofDataContractEnumHasEnumNamedValues)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachDataContractEnumHasEnumNamedValuesInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachDataContractEnumHasEnumNamedValuesInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachDataContractEnumHasEnumNamedValuesInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachDataContractEnumHasEnumNamedValuesInstance.EnumNamedValue;
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer(targetElement.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(targetSerializer != null, "Cannot find serializer for " + targetElement.GetDomainClass().Name + "!");			
						targetSerializer.Write(serializationContext, targetElement, writer);
					}
				}
				writer.WriteEndElement();
			}
	
		}
Exemple #9
0
		/// <summary>
		/// Reads all instances of relationship DataContractEnumHasEnumNamedValues.
		/// </summary>
		/// <remarks>
		/// The caller will position the reader at the open tag of the first XML element inside the relationship tag, so it can be
		/// either the first instance, or a bogus tag. This method will deserialize all instances and ignore all bogus tags. When the
		/// method returns, the reader will be positioned at the end tag of the relationship (or EOF if somehow that happens).
		/// </remarks>
		/// <param name="serializationContext">Serialization context.</param>
		/// <param name="element">In-memory DataContractEnum instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDataContractEnumHasEnumNamedValuesInstances(DslModeling::SerializationContext serializationContext, DataContractEnum element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newEnumNamedValueOfDataContractEnumHasEnumNamedValuesSerializer = serializationContext.Directory.GetSerializer(EnumNamedValue.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newEnumNamedValueOfDataContractEnumHasEnumNamedValuesSerializer != null, "Cannot find serializer for EnumNamedValue!");
				EnumNamedValue newEnumNamedValueOfDataContractEnumHasEnumNamedValues = newEnumNamedValueOfDataContractEnumHasEnumNamedValuesSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as EnumNamedValue;
				if (newEnumNamedValueOfDataContractEnumHasEnumNamedValues != null)
				{
					element.EnumNamedValues.Add(newEnumNamedValueOfDataContractEnumHasEnumNamedValues);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newEnumNamedValueOfDataContractEnumHasEnumNamedValues.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newEnumNamedValueOfDataContractEnumHasEnumNamedValues.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newEnumNamedValueOfDataContractEnumHasEnumNamedValues, reader);
				}
				else
				{
					global::System.Type typeofDataContractEnumHasEnumNamedValues = typeof(DataContractEnumHasEnumNamedValues);
					DslModeling::DomainRelationshipXmlSerializer newDataContractEnumHasEnumNamedValuesSerializer = serializationContext.Directory.GetSerializer(DataContractEnumHasEnumNamedValues.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newDataContractEnumHasEnumNamedValuesSerializer != null, "Cannot find serializer for DataContractEnumHasEnumNamedValues!");
					DataContractEnumHasEnumNamedValues newDataContractEnumHasEnumNamedValues = newDataContractEnumHasEnumNamedValuesSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DataContractEnumHasEnumNamedValues;
					if (newDataContractEnumHasEnumNamedValues != null)
					{
						if (newDataContractEnumHasEnumNamedValues.GetType() == typeofDataContractEnumHasEnumNamedValues)
						{	// The relationship should be serialized in short-form.
							DataContractDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(DataContractEnumHasEnumNamedValues));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newDataContractEnumHasEnumNamedValues, DataContractEnumHasEnumNamedValues.DataContractEnumDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataContractEnumHasEnumNamedValues.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataContractEnumHasEnumNamedValues.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newDataContractEnumHasEnumNamedValues, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Exemple #10
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 DataContractEnum instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, DataContractEnum element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "enumNamedValues", global::System.StringComparison.CurrentCulture) == 0)
				{
					if (reader.IsEmptyElement)
					{	// No instance of this relationship, just skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
					else
					{
						DslModeling::SerializationUtilities.SkipToFirstChild(reader);  // Skip the open tag of <enumNamedValues>
						ReadDataContractEnumHasEnumNamedValuesInstances(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </enumNamedValues>
					}
				}
			}
		}