public override void ElementAdded(ElementAddedEventArgs e)
        {
            PrimitiveDataTypeCollection dataContractPrimitiveCollection = e.ModelElement as PrimitiveDataTypeCollection;

            if (dataContractPrimitiveCollection == null)
            {
                return;
            }

            DataContractModel root = dataContractPrimitiveCollection.DataContractModel;

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(dataContractPrimitiveCollection, root.ImplementationTechnology);
            }

            if (string.IsNullOrEmpty(dataContractPrimitiveCollection.ItemType))
            {
                dataContractPrimitiveCollection.ItemType = typeof(string).FullName;
            }

            if (String.IsNullOrEmpty(dataContractPrimitiveCollection.Namespace))
            {
                dataContractPrimitiveCollection.Namespace = ArtifactLinkHelper.DefaultNamespace(e.ModelElement);
            }

            UpdateDataContractCollectionType(dataContractPrimitiveCollection, CollectionTypes.Values[CollectionTypes.ListKey]);
        }
Пример #2
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            FaultContract     faultContract = e.ModelElement as FaultContract;
            DataContractModel root          = faultContract.DataContractModel;

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(faultContract, root.ImplementationTechnology);
            }
        }
Пример #3
0
        public void OnStatusChangeOrderAllDataMembers(object sender, EventArgs e)
        {
            MenuCommand       command = sender as MenuCommand;
            DataContractModel dcModel = this.CurrentDocData.RootElement as DataContractModel;

            command.Visible = command.Enabled = !this.IsCurrentDiagramEmpty() &&
                                                this.SingleSelection is DataContractDiagram &&
                                                dcModel != null &&
                                                dcModel.ImplementationTechnology != null &&
                                                dcModel.Contracts.Count > 0;
        }
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            DataContractCollection dataContractCollection = e.ModelElement as DataContractCollection;
            DataContractModel      root = dataContractCollection.DataContractModel;

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(dataContractCollection, root.ImplementationTechnology);
            }
        }
Пример #5
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            Contract          contract = e.ModelElement as Contract;
            DataContractModel root     = contract.DataContractModel;

            if (root != null)
            {
                if (String.IsNullOrEmpty(contract.Namespace))
                {
                    contract.Namespace = root.Namespace;
                }
            }
        }
        public void TestInitialize()
        {
            serviceProvider = new MockMappingServiceProvider();

			attributes = new NameValueCollection();
			attributes.Add("elementNameProperty", "Name");

            #region Data Contract
            dcStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));
            dcDomainModel = dcStore.GetDomainModel<DataContractDslDomainModel>();
            dcTransaction = dcStore.TransactionManager.BeginTransaction();
            dcModel = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null);
            dcModel.ProjectMappingTable = projectMappingTableName;
            dc = dcStore.ElementFactory.CreateElement(DataContract.DomainClassId) as DataContract;
			primitiveDataElement = dcStore.ElementFactory.CreateElement(PrimitiveDataType.DomainClassId) as PrimitiveDataType;
            primitiveDataElement.Name = primitiveDataElementName;
			dc.DataMembers.Add(primitiveDataElement);
			dcModel.Contracts.Add(dc);
            #endregion

			#region Service Contract
			scStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
			scDomainModel = scStore.GetDomainModel<ServiceContractDslDomainModel>();
			scTransaction = scStore.TransactionManager.BeginTransaction();
			scModel = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null);
			scModel.ProjectMappingTable = projectMappingTableName;
			msg = scStore.ElementFactory.CreateElement(Message.DomainClassId) as Message;
			msg.Name = messageName;

            //Create the moniker
            //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE]
            string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                primitiveDataElement.GetType().Namespace,
                primitiveDataElement.GetType().Name,
                primitiveDataElement.Id.ToString(),
                dataContractModelProjectName, dataContractModelFileName);

			part = scStore.ElementFactory.CreateElement(DataContractMessagePart.DomainClassId) as DataContractMessagePart;
			part.Name = partName;
            part.Type = new MockModelBusReference(primitiveDataElement);
			
            msg.MessageParts.Add(part);
			scModel.Messages.Add(msg);
            #endregion
        }
        public void TestInitialize()
        {
            serviceProvider = new MockMappingServiceProvider();

			attributes = new NameValueCollection();
			attributes.Add("elementNameProperty", "Name");

            #region Data Contract
            dcStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(DataContractDslDomainModel));
            dcDomainModel = dcStore.GetDomainModel<DataContractDslDomainModel>();
            dcTransaction = dcStore.TransactionManager.BeginTransaction();
            dcModel = (DataContractModel)dcDomainModel.CreateElement(new Partition(dcStore), typeof(DataContractModel), null);
            dcModel.ProjectMappingTable = projectMappingTableName;
            fc = dcStore.ElementFactory.CreateElement(FaultContract.DomainClassId) as FaultContract;
            fc.Name = faultContractName;
			dcModel.Contracts.Add(fc);
            #endregion

			#region Service Contract
			scStore = new Store(serviceProvider, typeof(CoreDesignSurfaceDomainModel), typeof(ServiceContractDslDomainModel));
			scDomainModel = scStore.GetDomainModel<ServiceContractDslDomainModel>();
			scTransaction = scStore.TransactionManager.BeginTransaction();
			scModel = (ServiceContractModel)scDomainModel.CreateElement(new Partition(scStore), typeof(ServiceContractModel), null);
			scModel.ProjectMappingTable = projectMappingTableName;
            operation = scStore.ElementFactory.CreateElement(Operation.DomainClassId) as Operation;
            operation.Name = operationName;

            //Create the moniker
            //mel://[DSLNAMESPACE]\[MODELELEMENTTYPE]\[MODELELEMENT.GUID]@[PROJECT]\[MODELFILE]
            string requestMoniker = string.Format(@"mel://{0}\{1}\{2}@{3}\{4}",
                fc.GetType().Namespace,
                fc.GetType().Name,
                fc.Id.ToString(),
                dataContractModelProjectName, dataContractModelFileName);

            dcfault = scStore.ElementFactory.CreateElement(DataContractFault.DomainClassId) as DataContractFault;
			dcfault.Name = dcfaultName;
            dcfault.Type = new MockModelBusReference(fc);
            
            operation.Faults.Add(dcfault);
			scModel.Operations.Add(operation);
            #endregion
        }
Пример #8
0
        public override void ElementAdded(ElementAddedEventArgs e)
        {
            DataMember        dataElement = e.ModelElement as DataMember;
            DataContractModel root        = null;

            if (dataElement.DataContract != null)
            {
                root = dataElement.DataContract.DataContractModel;
            }
            else if (dataElement.FaultContract != null)
            {
                root = dataElement.FaultContract.DataContractModel;
            }

            if (root != null &&
                root.ImplementationTechnology != null)
            {
                ExtensionProviderHelper.AttachObjectExtender(dataElement, root.ImplementationTechnology);
            }
        }
Пример #9
0
		/// <summary>
		/// Reads all instances of relationship DataContractModelHasContracts.
		/// </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 DataContractModel instance that will get the deserialized data.</param>
		/// <param name="reader">XmlReader to read serialized data from.</param>
		private static void ReadDataContractModelHasContractsInstances(DslModeling::SerializationContext serializationContext, DataContractModel element, global::System.Xml.XmlReader reader)
		{
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newContractOfDataContractModelHasContractsSerializer = serializationContext.Directory.GetSerializer(Contract.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newContractOfDataContractModelHasContractsSerializer != null, "Cannot find serializer for Contract!");
				Contract newContractOfDataContractModelHasContracts = newContractOfDataContractModelHasContractsSerializer.TryCreateInstance(serializationContext, reader, element.Partition) as Contract;
				if (newContractOfDataContractModelHasContracts != null)
				{
					element.Contracts.Add(newContractOfDataContractModelHasContracts);
					DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newContractOfDataContractModelHasContracts.GetDomainClass().Id);	
					global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newContractOfDataContractModelHasContracts.GetDomainClass().Name + "!");
					targetSerializer.Read(serializationContext, newContractOfDataContractModelHasContracts, reader);
				}
				else
				{
					global::System.Type typeofDataContractModelHasContracts = typeof(DataContractModelHasContracts);
					DslModeling::DomainRelationshipXmlSerializer newDataContractModelHasContractsSerializer = serializationContext.Directory.GetSerializer(DataContractModelHasContracts.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newDataContractModelHasContractsSerializer != null, "Cannot find serializer for DataContractModelHasContracts!");
					DataContractModelHasContracts newDataContractModelHasContracts = newDataContractModelHasContractsSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as DataContractModelHasContracts;
					if (newDataContractModelHasContracts != null)
					{
						if (newDataContractModelHasContracts.GetType() == typeofDataContractModelHasContracts)
						{	// The relationship should be serialized in short-form.
							DataContractDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(DataContractModelHasContracts));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newDataContractModelHasContracts, DataContractModelHasContracts.DataContractModelDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newDataContractModelHasContracts.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newDataContractModelHasContracts.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newDataContractModelHasContracts, reader);
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Пример #10
0
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8).
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">DataContractModel instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">DataContractDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		/// <param name="writeOptionalPropertiesWithDefaultValue">Whether optional properties with default value will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, DataContractModel modelRoot, string modelFileName, DataContractDiagram diagram, string diagramFileName, bool writeOptionalPropertiesWithDefaultValue)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, writeOptionalPropertiesWithDefaultValue);
		}
Пример #11
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, DataContractModel element, global::System.Xml.XmlWriter writer)
		{
			// DataContractModelHasContracts
			global::System.Collections.ObjectModel.ReadOnlyCollection<DataContractModelHasContracts> allDataContractModelHasContractsInstances = DataContractModelHasContracts.GetLinksToContracts(element);
			if (!serializationContext.Result.Failed && allDataContractModelHasContractsInstances.Count > 0)
			{
				writer.WriteStartElement("contracts");
				global::System.Type typeofDataContractModelHasContracts = typeof(DataContractModelHasContracts);
				foreach (DataContractModelHasContracts eachDataContractModelHasContractsInstance in allDataContractModelHasContractsInstances)
				{
					if (serializationContext.Result.Failed)
						break;
	
					if (eachDataContractModelHasContractsInstance.GetType() != typeofDataContractModelHasContracts)
					{	// Derived relationships will be serialized in full-form.
						DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(eachDataContractModelHasContractsInstance.GetDomainClass().Id);
						global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + eachDataContractModelHasContractsInstance.GetDomainClass().Name + "!");			
						derivedRelSerializer.Write(serializationContext, eachDataContractModelHasContractsInstance, writer);
					}
					else
					{	// No need to serialize the relationship itself, just serialize the role-player directly.
						DslModeling::ModelElement targetElement = eachDataContractModelHasContractsInstance.Contract;
						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();
			}
	
		}
		private DataContractModel CreateDataContractRoot()
		{
			DataContractModel dataContractModel =
				new DataContractModel(DataContractStore);

			dataContractModel.ProjectMappingTable = "WCF";

			return dataContractModel;
		}
Пример #13
0
		internal global::System.IO.MemoryStream InternalSaveModel(DslModeling::SerializationResult serializationResult, DataContractModel modelRoot, string fileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			global::System.Diagnostics.Debug.Assert(serializationResult != null);
			global::System.Diagnostics.Debug.Assert(modelRoot != null);
			global::System.Diagnostics.Debug.Assert(!serializationResult.Failed);
			#endregion
	
			serializationResult.Encoding = encoding;
	
			DslModeling::DomainXmlSerializerDirectory directory = this.GetDirectory(modelRoot.Store);
	
			
			global::System.IO.MemoryStream newFileContent = new global::System.IO.MemoryStream();
			
			DslModeling::SerializationContext serializationContext = new DslModeling::SerializationContext(directory, fileName, serializationResult);
			this.InitializeSerializationContext(modelRoot.Partition, serializationContext, false);
			// MonikerResolver shouldn't be required in Save operation, so not calling SetupMonikerResolver() here.
			serializationContext.WriteOptionalPropertiesWithDefaultValue = writeOptionalPropertiesWithDefaultValue;
			global::System.Xml.XmlWriterSettings settings = DataContractDslSerializationHelper.Instance.CreateXmlWriterSettings(serializationContext, false, encoding);
			using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(newFileContent, settings))
			{
				this.WriteRootElement(serializationContext, modelRoot, writer);
			}
				
			return newFileContent;
		}
Пример #14
0
		/// <summary>
		/// Saves the given model root to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">DataContractModel instance to be saved.</param>
		/// <param name="fileName">Name of the file in which the DataContractModel instance will be saved.</param>
		public virtual void SaveModel(DslModeling::SerializationResult serializationResult, DataContractModel modelRoot, string fileName)
		{
			this.SaveModel(serializationResult, modelRoot, fileName, global::System.Text.Encoding.UTF8, false);
		}
Пример #15
0
		public static void SetDataContractModel(Contract element, DataContractModel newDataContractModel)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ContractDomainRoleId, newDataContractModel);
		}
Пример #16
0
		public static DslModeling::LinkedElementCollection<Contract> GetContracts(DataContractModel element)
		{
			return GetRoleCollection<DslModeling::LinkedElementCollection<Contract>, Contract>(element, DataContractModelDomainRoleId);
		}
Пример #17
0
		/// <summary>
		/// Constructor
		/// Creates a DataContractModelHasContracts link in the same Partition as the given DataContractModel
		/// </summary>
		/// <param name="source">DataContractModel to use as the source of the relationship.</param>
		/// <param name="target">Contract to use as the target of the relationship.</param>
		public DataContractModelHasContracts(DataContractModel source, Contract target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(DataContractModelHasContracts.DataContractModelDomainRoleId, source), new DslModeling::RoleAssignment(DataContractModelHasContracts.ContractDomainRoleId, target)}, null)
		{
		}
Пример #18
0
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, DataContractModel modelRoot, string modelFileName, DataContractDiagram diagram, string diagramFileName, global::System.Text.Encoding encoding, bool writeOptionalPropertiesWithDefaultValue)
		{
			#region Check Parameters
			if (serializationResult == null)
				throw new global::System.ArgumentNullException("serializationResult");
			if (string.IsNullOrEmpty(modelFileName))
				throw new global::System.ArgumentNullException("modelFileName");
			if (diagram == null)
				throw new global::System.ArgumentNullException("diagram");
			if (string.IsNullOrEmpty(diagramFileName))
				throw new global::System.ArgumentNullException("diagramFileName");
			#endregion
	
			if (serializationResult.Failed)
				return;
	
			// Save the model file first
			using (global::System.IO.MemoryStream modelFileContent = this.InternalSaveModel(serializationResult, modelRoot, modelFileName, encoding, writeOptionalPropertiesWithDefaultValue))
			{
				if (serializationResult.Failed)
					return;
	
				using (global::System.IO.MemoryStream diagramFileContent = this.InternalSaveDiagram(serializationResult, diagram, diagramFileName, encoding, writeOptionalPropertiesWithDefaultValue))
				{
					if (!serializationResult.Failed)
					{
						// Only write the contents if there's no error encountered during serialization.
						if (modelFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(modelFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(modelFileContent.ToArray());
								}
							}
						}
						if (diagramFileContent != null)
						{
							using (global::System.IO.FileStream fileStream = new global::System.IO.FileStream(diagramFileName, global::System.IO.FileMode.Create, global::System.IO.FileAccess.Write, global::System.IO.FileShare.None))
							{
								using (global::System.IO.BinaryWriter writer = new global::System.IO.BinaryWriter(fileStream, encoding))
								{
									writer.Write(diagramFileContent.ToArray());
								}
							}
						}
					}
				}
			}
		}
Пример #19
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 DataContractModel instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, DataContractModel element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "contracts", 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 <contracts>
						ReadDataContractModelHasContractsInstances(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </contracts>
					}
				}
			}
		}
Пример #20
0
		/// <summary>
		/// Saves the given diagram to the given file, with default encoding (UTF-8), and optional properties with default value will not
		/// be written out.
		/// </summary>
		/// <param name="serializationResult">Stores serialization result from the save operation.</param>
		/// <param name="modelRoot">DataContractModel instance to be saved.</param>
		/// <param name="modelFileName">Name of the file in which the CanonicalSampleRoot instance will be saved.</param>
		/// <param name="diagram">DataContractDiagram to be saved.</param>
		/// <param name="diagramFileName">Name of the file in which the diagram will be saved.</param>
		public virtual void SaveModelAndDiagram(DslModeling::SerializationResult serializationResult, DataContractModel modelRoot, string modelFileName, DataContractDiagram diagram, string diagramFileName)
		{
			this.SaveModelAndDiagram(serializationResult, modelRoot, modelFileName, diagram, diagramFileName, global::System.Text.Encoding.UTF8, false);
		}
Пример #21
0
		/// <summary>
		/// Helper method to create and initialize a new DataContractModel.
		/// </summary>
		internal protected virtual DataContractModel CreateModelHelper(DslModeling::Partition modelPartition)
		{
			DataContractModel model = new DataContractModel(modelPartition);
			return model;
		}