コード例 #1
0
        private void AddSchemaType(ICollection <Tuple <string, XmlSchemaType> > schemaTypes, string namespaceName, XmlSchemaType schemaType)
        {
            if (!schemaLocations.ContainsKey(namespaceName))
            {
                schemaLocations.Add(namespaceName, schemaDefinitionProvider.GetSchemaLocation(namespaceName));
            }

            schemaTypes.Add(Tuple.Create(namespaceName, schemaType));
        }
コード例 #2
0
        /// <summary>
        /// Initialize builder with contract details.
        /// <param name="protocol">X-Road protocol to use when generating service description.</param>
        /// <param name="schemaDefinitionProvider">Provides overrides for default presentation format.</param>
        /// <param name="version">Global version for service description (when versioning entire schema and operations using same version number).</param>
        /// </summary>
        public ProducerDefinition(IXRoadProtocol protocol, SchemaDefinitionProvider schemaDefinitionProvider, uint?version = null)
        {
            if (protocol == null)
            {
                throw new ArgumentNullException(nameof(protocol));
            }
            this.protocol = protocol;

            if (schemaDefinitionProvider == null)
            {
                throw new ArgumentNullException(nameof(schemaDefinitionProvider));
            }
            this.schemaDefinitionProvider = schemaDefinitionProvider;

            this.version     = version;
            contractAssembly = schemaDefinitionProvider.ProtocolDefinition.ContractAssembly;

            portType = new PortType {
                Name = "PortTypeName"
            };

            binding = new Binding
            {
                Name = "BindingName",
                Type = new XmlQualifiedName(portType.Name, protocol.ProducerNamespace)
            };

            servicePort = new Port
            {
                Name    = "PortName",
                Binding = new XmlQualifiedName(binding.Name, protocol.ProducerNamespace)
            };

            service = new Service
            {
                Name  = "ServiceName",
                Ports = { servicePort }
            };

            CollectTypes();

            var globalNamespaces = new Dictionary <string, string>();

            addGlobalNamespace = (namespaceName) =>
            {
                var prefix = NamespaceConstants.GetPreferredPrefix(namespaceName);
                if (string.IsNullOrEmpty(prefix))
                {
                    return(false);
                }

                globalNamespaces[prefix] = namespaceName;

                return(true);
            };

            getGlobalNamespaces = () => globalNamespaces.Select(x => Tuple.Create(x.Key, x.Value)).ToList();

            var requiredImports = new SortedSet <Tuple <string, string> >();

            addRequiredImport = (schemaNamespace, typeNamespace, schemaExporter) =>
            {
                if (typeNamespace == NamespaceConstants.XSD || typeNamespace == schemaNamespace)
                {
                    return;
                }

                if (!schemaLocations.ContainsKey(typeNamespace))
                {
                    schemaLocations.Add(typeNamespace, schemaDefinitionProvider.GetSchemaLocation(typeNamespace, schemaExporter));
                }

                requiredImports.Add(Tuple.Create(schemaNamespace, typeNamespace));
            };

            getRequiredImports = ns => requiredImports.Where(x => x.Item1 == ns).Select(x => x.Item2).ToList();

            xRoadPrefix      = schemaDefinitionProvider.GetXRoadPrefix();
            xRoadNamespace   = schemaDefinitionProvider.GetXRoadNamespace();
            headerDefinition = schemaDefinitionProvider.GetXRoadHeaderDefinition();

            addGlobalNamespace(NamespaceConstants.SOAP);
            addGlobalNamespace(NamespaceConstants.WSDL);
            addGlobalNamespace(NamespaceConstants.XSD);
        }