public static void SetServiceContractModel(Service element, ServiceContractModel newServiceContractModel)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ServiceDomainRoleId, newServiceContractModel);
		}
		/// <summary>
		/// Constructor
		/// Creates a ServiceContractModelHasServices link in the same Partition as the given ServiceContractModel
		/// </summary>
		/// <param name="source">ServiceContractModel to use as the source of the relationship.</param>
		/// <param name="target">Service to use as the target of the relationship.</param>
		public ServiceContractModelHasServices(ServiceContractModel source, Service target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ServiceContractModelHasServices.ServiceContractModelDomainRoleId, source), new DslModeling::RoleAssignment(ServiceContractModelHasServices.ServiceDomainRoleId, target)}, null)
		{
		}
		public static ServiceContractModel GetServiceContractModel(Service element)
		{
			return DslModeling::DomainRoleInfo.GetLinkedElement(element, ServiceDomainRoleId) as ServiceContractModel;
		}
		/// <summary>
		/// Constructor
		/// Creates a ServiceReferencesServiceContract link in the same Partition as the given Service
		/// </summary>
		/// <param name="source">Service to use as the source of the relationship.</param>
		/// <param name="target">ServiceContract to use as the target of the relationship.</param>
		public ServiceReferencesServiceContract(Service source, ServiceContract target)
			: base((source != null ? source.Partition : null), new DslModeling::RoleAssignment[]{new DslModeling::RoleAssignment(ServiceReferencesServiceContract.ServiceDomainRoleId, source), new DslModeling::RoleAssignment(ServiceReferencesServiceContract.ServiceContractDomainRoleId, target)}, null)
		{
		}
		public static void SetService(ServiceContract element, Service newService)
		{
			DslModeling::DomainRoleInfo.SetLinkedElement(element, ServiceContractDomainRoleId, newService);
		}
		private Service CreateDefaultService()
		{
			Service rootElement = new Service(Store);
			rootElement.Name = ServiceName;
			rootElement.ServiceContractModel = new ServiceContractModel(Store);
			rootElement.ServiceContractModel.ProjectMappingTable = "ASMX";
			return rootElement;
		}
		private Service CreateDefaultService()
		{
			Service rootElement = new Service(Store);
			WCFService wcfService = new WCFService();
			wcfService.ModelElement = rootElement;
			rootElement.ObjectExtender = wcfService;
			rootElement.Name = ServiceName;
			rootElement.ServiceContractModel = new ServiceContractModel(Store);
			rootElement.ServiceContractModel.ProjectMappingTable = "WCF";
			return rootElement;
		}
		private static DslModeling::ElementLink ConnectServiceToServiceContract(Service sourceBeforePathTraverse, ServiceContract targetBeforePathTraverse)
		{
			DslModeling::ElementLink result = new ServiceReferencesServiceContract(sourceBeforePathTraverse, targetBeforePathTraverse);

			SetUniqueName(result);

			return result;
		}
Esempio n. 9
0
		private static void WriteChildElements(DslModeling::SerializationContext serializationContext, Service element, global::System.Xml.XmlWriter writer)
		{
			// ServiceReferencesServiceContract
			ServiceReferencesServiceContract theServiceReferencesServiceContractInstance = ServiceReferencesServiceContract.GetLinkToServiceContract(element);
			if (!serializationContext.Result.Failed && theServiceReferencesServiceContractInstance != null)
			{
				DslModeling::DomainRelationshipXmlSerializer relSerializer = serializationContext.Directory.GetSerializer(ServiceReferencesServiceContract.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
				global::System.Diagnostics.Debug.Assert(relSerializer != null, "Cannot find serializer for ServiceReferencesServiceContract!");
	
				writer.WriteStartElement("serviceContract");
				global::System.Type typeofServiceReferencesServiceContract = typeof(ServiceReferencesServiceContract);
				if (theServiceReferencesServiceContractInstance.GetType() != typeofServiceReferencesServiceContract)
				{	// Derived relationships will be serialized in full-form.
					DslModeling::DomainClassXmlSerializer derivedRelSerializer = serializationContext.Directory.GetSerializer(theServiceReferencesServiceContractInstance.GetDomainClass().Id);
					global::System.Diagnostics.Debug.Assert(derivedRelSerializer != null, "Cannot find serializer for " + theServiceReferencesServiceContractInstance.GetDomainClass().Name + "!");			
					derivedRelSerializer.Write(serializationContext, theServiceReferencesServiceContractInstance, writer);
				}
				else
				{	// No need to serialize the relationship itself, just serialize the role-player directly.
					DslModeling::ModelElement targetElement = theServiceReferencesServiceContractInstance.ServiceContract;
					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();
			}
	
		}
Esempio n. 10
0
		private static void ReadServiceReferencesServiceContractInstance(DslModeling::SerializationContext serializationContext, Service element, global::System.Xml.XmlReader reader)
		{
			if (DslModeling::DomainRoleInfo.GetElementLinks<ServiceReferencesServiceContract> (element, ServiceReferencesServiceContract.ServiceDomainRoleId).Count > 0)
			{	// Only allow one instance, which already exists, so skip everything
				DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
				return;
			}
	
			while (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				DslModeling::DomainClassXmlSerializer newServiceContractMonikerOfServiceReferencesServiceContractSerializer = serializationContext.Directory.GetSerializer(ServiceContract.DomainClassId);
				global::System.Diagnostics.Debug.Assert(newServiceContractMonikerOfServiceReferencesServiceContractSerializer != null, "Cannot find serializer for ServiceContract!");
				DslModeling::Moniker newServiceContractMonikerOfServiceReferencesServiceContract = newServiceContractMonikerOfServiceReferencesServiceContractSerializer.TryCreateMonikerInstance(serializationContext, reader, element, ServiceReferencesServiceContract.DomainClassId, element.Partition);
				if (newServiceContractMonikerOfServiceReferencesServiceContract != null)
				{
					new ServiceReferencesServiceContract(element.Partition, new DslModeling::RoleAssignment(ServiceReferencesServiceContract.ServiceDomainRoleId, element), new DslModeling::RoleAssignment(ServiceReferencesServiceContract.ServiceContractDomainRoleId, newServiceContractMonikerOfServiceReferencesServiceContract));
					DslModeling::SerializationUtilities.Skip(reader);	// Moniker contains no child XML elements, so just skip.
					break;	// Only allow one instance.
				}
				else
				{
					global::System.Type typeofServiceReferencesServiceContract = typeof(ServiceReferencesServiceContract);
					DslModeling::DomainRelationshipXmlSerializer newServiceReferencesServiceContractSerializer = serializationContext.Directory.GetSerializer(ServiceReferencesServiceContract.DomainClassId) as DslModeling::DomainRelationshipXmlSerializer;
					global::System.Diagnostics.Debug.Assert(newServiceReferencesServiceContractSerializer != null, "Cannot find serializer for ServiceReferencesServiceContract!");
					ServiceReferencesServiceContract newServiceReferencesServiceContract = newServiceReferencesServiceContractSerializer.TryCreateInstance (serializationContext, reader, element.Partition) as ServiceReferencesServiceContract;
					if (newServiceReferencesServiceContract != null)
					{
						if (newServiceReferencesServiceContract.GetType() == typeofServiceReferencesServiceContract)
						{	// The relationship should be serialized in short-form.
							ServiceContractDslSerializationBehaviorSerializationMessages.ExpectingShortFormRelationship(serializationContext, reader, typeof(ServiceReferencesServiceContract));
						}
						DslModeling::DomainRoleInfo.SetRolePlayer (newServiceReferencesServiceContract, ServiceReferencesServiceContract.ServiceDomainRoleId, element);
						DslModeling::DomainClassXmlSerializer targetSerializer = serializationContext.Directory.GetSerializer (newServiceReferencesServiceContract.GetDomainClass().Id);	
						global::System.Diagnostics.Debug.Assert (targetSerializer != null, "Cannot find serializer for " + newServiceReferencesServiceContract.GetDomainClass().Name + "!");
						targetSerializer.Read(serializationContext, newServiceReferencesServiceContract, reader);
						break;	// Only allow one instance.
					}
					else
					{	// Unknown element, skip
						DslModeling::SerializationUtilities.Skip(reader);
					}
				}
			}
		}
Esempio n. 11
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 Service instance that will get the deserialized data.</param>
		private static void ReadChildElements(DslModeling::SerializationContext serializationContext, Service element, global::System.Xml.XmlReader reader)
		{
			if (!serializationContext.Result.Failed && !reader.EOF && reader.NodeType == global::System.Xml.XmlNodeType.Element)
			{
				if (string.Compare(reader.LocalName, "serviceContract", 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 <serviceContract>
						ReadServiceReferencesServiceContractInstance(serializationContext, element, reader);
						DslModeling::SerializationUtilities.Skip(reader);  // Skip the close tag of </serviceContract>
					}
				}
			}
		}
Esempio n. 12
0
        public CodeGenerationResults Generate(IArtifactLink link)
        {
            CodeGenerationResults result           = new CodeGenerationResults();
            string       serviceImplementationName = string.Empty;
            string       serviceContractName       = string.Empty;
            string       serviceNamespace          = string.Empty;
            const string behavior = "_Behavior";

            if (link is IModelReference)
            {
                this.serviceProvider = Utility.GetData <IServiceProvider>(link);
                ProjectNode project = Utility.GetData <ProjectNode>(link);

                ServiceDescription serviceDescription = ((IModelReference)link).ModelElement as ServiceDescription;
                Configuration      configuration      = GetConfiguration(link, project);

                // abort if we got errors in config file
                if (configuration == null)
                {
                    return(result);
                }

                try
                {
                    ServiceReference serviceReference = (ServiceReference)serviceDescription;
                    SCModel.Service  service          = GetMelReference <SCModel.Service>(serviceReference.ServiceImplementationType);
                    serviceImplementationName = ResolveTypeReference(service);
                    serviceContractName       = GetServiceContractName(service.ServiceContract);
                    serviceNamespace          = service.ServiceContract.Namespace;

                    ServiceModelConfigurationManager manager = new ServiceModelConfigurationManager(configuration);

                    ServiceElement serviceElement = new ServiceElement();
                    serviceElement.Name = serviceImplementationName;
                    serviceElement.BehaviorConfiguration = string.Concat(serviceImplementationName, behavior);

                    foreach (Endpoint endpoint in serviceDescription.Endpoints)
                    {
                        ServiceEndpointElement endpointElement = new ServiceEndpointElement();
                        endpointElement.Name             = endpoint.Name;
                        endpointElement.Contract         = serviceContractName;
                        endpointElement.Binding          = ((WcfEndpoint)endpoint.ObjectExtender).BindingType.ToString();
                        endpointElement.Address          = new Uri(endpoint.Address ?? string.Empty, UriKind.RelativeOrAbsolute);
                        endpointElement.BindingNamespace = serviceNamespace;
                        serviceElement.Endpoints.Add(endpointElement);
                    }

                    manager.UpdateService(serviceElement);

                    ServiceBehaviorElement behaviorElement = new ServiceBehaviorElement();
                    behaviorElement.Name = string.Concat(serviceImplementationName, behavior);
                    ServiceDebugElement debugElement = new ServiceDebugElement();
                    debugElement.IncludeExceptionDetailInFaults = false;
                    behaviorElement.Add(debugElement);

                    if (((WcfServiceDescription)serviceDescription.ObjectExtender).EnableMetadataPublishing)
                    {
                        ServiceMetadataPublishingElement metadataPublishingElement = new ServiceMetadataPublishingElement();
                        metadataPublishingElement.HttpGetEnabled = true;
                        behaviorElement.Add(metadataPublishingElement);
                        ServiceEndpointElement mexEndpointElement = ServiceModelConfigurationManager.GetMetadataExchangeEndpoint();
                        serviceElement.Endpoints.Add(mexEndpointElement);
                    }

                    manager.UpdateBehavior(behaviorElement);
                    manager.Save();

                    result.Add(link.ItemPath, File.ReadAllText(configuration.FilePath));
                }
                finally
                {
                    if (configuration != null && File.Exists(configuration.FilePath))
                    {
                        File.Delete(configuration.FilePath);
                    }
                }
            }

            return(result);
        }