예제 #1
0
        internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type)
        {
            reader.ReadStartElement(); // ProbeMatch / ResolveMatch / Hello / Bye

            // Endpoint Reference
            if (
                (reader.IsStartElement("EndpointReference", WsWellKnownUri.WsaNamespaceUri_2004_08) == false) &&
                (reader.IsStartElement("EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08) == false)
                )
            {
                throw new XmlException();
            }

            this.Endpoint = new WsWsaEndpointRef(reader);

            // Types
            if (reader.IsStartElement("Types", WsWellKnownUri.WsdNamespaceUri))
            {
                this.ServiceTypes = new DpwsServiceTypes(reader);
            }

            // Optional Scopes??
            if (reader.IsStartElement("Scopes", WsWellKnownUri.WsdNamespaceUri))
            {
                reader.Skip();
            }

            // XAddrs
            if (reader.IsStartElement("XAddrs", WsWellKnownUri.WsdNamespaceUri))
            {
                this.XAddrs = reader.ReadElementString().Split(' ');
                int count = XAddrs.Length;

                for (int i = 0; i < count; i++)
                {
                    // validate all XAddrs for fully qualified paths
                    if (Uri.IsWellFormedUriString(XAddrs[i], UriKind.Absolute) == false)
                    {
                        throw new XmlException();
                    }
                }
            }
            else if (type == ServiceDescriptionType.ResolveMatch) // for ResolveMatch, XAddrs is required
            {
                throw new XmlException();
            }

            // MetadataVersion
            if (reader.IsStartElement("MetadataVersion", WsWellKnownUri.WsdNamespaceUri))
            {
                this.MetadataVersion = reader.ReadElementString();
            }
            else if (type != ServiceDescriptionType.Bye) // for Hello, ProbeMatch and ResolveMatch, MetadataVersion is required
            {
                throw new XmlException();
            }

            XmlReaderHelper.SkipAllSiblings(reader); // xs:any
            reader.ReadEndElement();                 // ProbeMatch / ResolveMatch / Hello / Bye
        }
예제 #2
0
        internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type, ProtocolVersion v, IPEndPoint remoteEP)
        {
            m_version = v;

            reader.ReadStartElement(); // ProbeMatch / ResolveMatch / Hello / Bye

            // Endpoint Reference
            if (reader.IsStartElement("EndpointReference", m_version.AddressingNamespace) == false)
            {
                throw new XmlException();
            }
            this.Endpoint = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);

            // Types
            if (reader.IsStartElement("Types", m_version.DiscoveryNamespace))
            {
                this.ServiceTypes = new DpwsServiceTypes(reader);
            }

            // Optional Scopes??
            if (reader.IsStartElement("Scopes", m_version.DiscoveryNamespace))
            {
                reader.Skip();
            }

            // XAddrs
            if (reader.IsStartElement("XAddrs", m_version.DiscoveryNamespace))
            {
                this.XAddrs = reader.ReadElementString().Trim().Split(' ');
                int count = XAddrs.Length;

                for (int i = 0; i < count; i++)
                {
                    // validate all XAddrs for fully qualified paths
                    if (Uri.IsWellFormedUriString(XAddrs[i], UriKind.Absolute) == false)
                    {
                        throw new XmlException();
                    }

                    if (remoteEP != null)
                    {
                        int idx = XAddrs[i].ToLower().IndexOf("localhost");

                        if (idx != -1)
                        {
                            XAddrs[i] = XAddrs[i].Substring(0, idx) + remoteEP.Address.ToString() + XAddrs[i].Substring(idx + 9 /*localhost*/);
                        }
                    }
                }
            }
            else if (type == ServiceDescriptionType.ResolveMatch) // for ResolveMatch, XAddrs is required
            {
                throw new XmlException();
            }

            // MetadataVersion
            if (reader.IsStartElement("MetadataVersion", m_version.DiscoveryNamespace))
            {
                this.MetadataVersion = reader.ReadElementString();
            }
            else if (type != ServiceDescriptionType.Bye) // for Hello, ProbeMatch and ResolveMatch, MetadataVersion is required
            {
                throw new XmlException();
            }

            XmlReaderHelper.SkipAllSiblings(reader); // xs:any
            reader.ReadEndElement();                 // ProbeMatch / ResolveMatch / Hello / Bye
        }
예제 #3
0
 internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type, ProtocolVersion v) :
     this(reader, type, v, null)
 {
 }
        internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type, ProtocolVersion v, IPEndPoint remoteEP)
        {
            m_version = v;

            reader.ReadStartElement(); // ProbeMatch / ResolveMatch / Hello / Bye

            // Endpoint Reference
            if (reader.IsStartElement("EndpointReference", m_version.AddressingNamespace) == false)
            {
                throw new XmlException();                
            }
            this.Endpoint = new WsWsaEndpointRef(reader, m_version.AddressingNamespace);

            // Types
            if (reader.IsStartElement("Types", m_version.DiscoveryNamespace))
            {
                this.ServiceTypes = new DpwsServiceTypes(reader);
            }

            // Optional Scopes??
            if (reader.IsStartElement("Scopes", m_version.DiscoveryNamespace))
            {
                reader.Skip();
            }

            // XAddrs
            if (reader.IsStartElement("XAddrs", m_version.DiscoveryNamespace))
            {
                this.XAddrs = reader.ReadElementString().Trim().Split(' ');
                int count = XAddrs.Length;

                for (int i = 0; i < count; i++)
                {
                    // validate all XAddrs for fully qualified paths
                    if (Uri.IsWellFormedUriString(XAddrs[i], UriKind.Absolute) == false)
                    {
                        throw new XmlException();
                    }

                    if(remoteEP != null)
                    {
                        int idx = XAddrs[i].ToLower().IndexOf("localhost");

                        if(idx != -1)
                        {
                            XAddrs[i] = XAddrs[i].Substring(0, idx) + remoteEP.Address.ToString() + XAddrs[i].Substring(idx + 9 /*localhost*/);
                        }
                    }
                }
            }
            else if (type == ServiceDescriptionType.ResolveMatch) // for ResolveMatch, XAddrs is required
            {
                throw new XmlException();
            }

            // MetadataVersion
            if (reader.IsStartElement("MetadataVersion", m_version.DiscoveryNamespace))
            {
                this.MetadataVersion = reader.ReadElementString();
            }
            else if (type != ServiceDescriptionType.Bye) // for Hello, ProbeMatch and ResolveMatch, MetadataVersion is required
            {
                throw new XmlException();
            }

            XmlReaderHelper.SkipAllSiblings(reader); // xs:any
            reader.ReadEndElement(); // ProbeMatch / ResolveMatch / Hello / Bye
        }
 internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type, ProtocolVersion v) :
     this(reader, type, v, null)
 {
 }
예제 #6
0
        /// <summary>
        /// Generates a SPARQL Service Description Graph for the specified portion of the SPARQL Server Handler Configuration or uses the configuration supplied Description Graph
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="config">SPARQL Server Configuration</param>
        /// <param name="descripUri">Base URI of the Description</param>
        /// <param name="type">Portion of the SPARQL Server to describe</param>
        /// <returns></returns>
        public static IGraph GetServiceDescription(HttpContext context, BaseSparqlServerConfiguration config, Uri descripUri, ServiceDescriptionType type)
        {
            //Use user specified Service Description if present
            if (config.ServiceDescription != null)
            {
                return(config.ServiceDescription);
            }

            IGraph   g       = SparqlServiceDescriber.GetNewGraph();
            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            IUriNode service = g.CreateUriNode("sd:" + ClassService);

            INode queryNode, updateNode, protocolNode;

            //Query Service Description
            if (config.QueryProcessor != null && (type == ServiceDescriptionType.Query || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Query Service
                queryNode = g.CreateUriNode(new Uri(descripUri, "query"));
                g.Assert(queryNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(queryNode, url, queryNode);

                //Add the sd:supportedLanguage
                IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage);
                IUriNode lang;
                switch (config.QuerySyntax)
                {
                case SparqlQuerySyntax.Extended:
                case SparqlQuerySyntax.Sparql_1_1:
                    lang = g.CreateUriNode("sd:" + InstanceSparql11Query);
                    break;

                default:
                    lang = g.CreateUriNode("sd:" + InstanceSparql10Query);
                    break;
                }
                g.Assert(queryNode, supportedLang, lang);

                //Add the Result Formats
                IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanWriteRdf || definition.CanWriteSparqlResults)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(queryNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }

                //Add Features and Dataset Description
                //First add descriptions for Global Expression Factories
                IUriNode extensionFunction  = g.CreateUriNode("sd:" + PropertyExtensionFunction);
                IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate);
                foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories)
                {
                    foreach (Uri u in factory.AvailableExtensionFunctions)
                    {
                        g.Assert(queryNode, extensionFunction, g.CreateUriNode(u));
                    }
                    foreach (Uri u in factory.AvailableExtensionAggregates)
                    {
                        g.Assert(queryNode, extensionAggregate, g.CreateUriNode(u));
                    }
                }
            }
            else
            {
                queryNode = null;
            }

            //Update Service Description
            if (config.UpdateProcessor != null && (type == ServiceDescriptionType.Update || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Update Service
                updateNode = g.CreateUriNode(new Uri(descripUri, "update"));
                g.Assert(updateNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(updateNode, url, updateNode);

                //Add the sd:supportedLanguage
                IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage);
                g.Assert(updateNode, supportedLang, g.CreateUriNode("sd:" + InstanceSparql11Update));

                //Add Features and Dataset Description
                //First add descriptions for Global Expression Factories
                IUriNode extensionFunction  = g.CreateUriNode("sd:" + PropertyExtensionFunction);
                IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate);
                foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories)
                {
                    foreach (Uri u in factory.AvailableExtensionFunctions)
                    {
                        g.Assert(updateNode, extensionFunction, g.CreateUriNode(u));
                    }
                    foreach (Uri u in factory.AvailableExtensionAggregates)
                    {
                        g.Assert(updateNode, extensionAggregate, g.CreateUriNode(u));
                    }
                }
            }
            else
            {
                updateNode = null;
            }

            //Graph Store HTTP Protocol Description
            if (config.ProtocolProcessor != null && (type == ServiceDescriptionType.Protocol || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Service
                if (descripUri.ToString().EndsWith("/description"))
                {
                    String actualUri = descripUri.ToString();
                    actualUri    = actualUri.Substring(0, actualUri.LastIndexOf("/description") + 1);
                    protocolNode = g.CreateUriNode(new Uri(actualUri));
                }
                else
                {
                    protocolNode = g.CreateUriNode(descripUri);
                }
                g.Assert(protocolNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(protocolNode, url, protocolNode);

                //Add the Input Formats
                IUriNode inputFormat = g.CreateUriNode("sd:" + PropertyInputFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanParseRdf)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(protocolNode, inputFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }

                //Add the Result Formats
                IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanWriteRdf)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(protocolNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }
            }
            else
            {
                protocolNode = null;
            }

            //Finally get the Configuration Node to add additional feature and dataset descriptions
            config.AddFeatureDescription(g, queryNode, updateNode, protocolNode);

            return(g);
        }
        /// <summary>
        /// Generates a SPARQL Service Description Graph for the specified portion of the SPARQL Server Handler Configuration or uses the configuration supplied Description Graph
        /// </summary>
        /// <param name="context">HTTP Context</param>
        /// <param name="config">SPARQL Server Configuration</param>
        /// <param name="descripUri">Base URI of the Description</param>
        /// <param name="type">Portion of the SPARQL Server to describe</param>
        /// <returns></returns>
        public static IGraph GetServiceDescription(HttpContext context, BaseSparqlServerConfiguration config, Uri descripUri, ServiceDescriptionType type)
        {
            //Use user specified Service Description if present
            if (config.ServiceDescription != null) return config.ServiceDescription;

            IGraph g = SparqlServiceDescriber.GetNewGraph();
            IUriNode rdfType = g.CreateUriNode(new Uri(RdfSpecsHelper.RdfType));
            IUriNode service = g.CreateUriNode("sd:" + ClassService);

            INode queryNode, updateNode, protocolNode;

            //Query Service Description
            if (config.QueryProcessor != null && (type == ServiceDescriptionType.Query || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Query Service
                queryNode = g.CreateUriNode(new Uri(descripUri, "query"));
                g.Assert(queryNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(queryNode, url, queryNode);

                //Add the sd:supportedLanguage
                IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage);
                IUriNode lang;
                switch (config.QuerySyntax)
                {
                    case SparqlQuerySyntax.Extended:
                    case SparqlQuerySyntax.Sparql_1_1:
                        lang = g.CreateUriNode("sd:" + InstanceSparql11Query);
                        break;
                    default:
                        lang = g.CreateUriNode("sd:" + InstanceSparql10Query);
                        break;
                }
                g.Assert(queryNode, supportedLang, lang);

                //Add the Result Formats
                IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanWriteRdf || definition.CanWriteSparqlResults)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(queryNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }

                //Add Features and Dataset Description
                //First add descriptions for Global Expression Factories
                IUriNode extensionFunction = g.CreateUriNode("sd:" + PropertyExtensionFunction);
                IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate);
                foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories)
                {
                    foreach (Uri u in factory.AvailableExtensionFunctions)
                    {
                        g.Assert(queryNode, extensionFunction, g.CreateUriNode(u));
                    }
                    foreach (Uri u in factory.AvailableExtensionAggregates)
                    {
                        g.Assert(queryNode, extensionAggregate, g.CreateUriNode(u));
                    }
                }
            }
            else
            {
                queryNode = null;
            }

            //Update Service Description
            if (config.UpdateProcessor != null && (type == ServiceDescriptionType.Update || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Update Service
                updateNode = g.CreateUriNode(new Uri(descripUri, "update"));
                g.Assert(updateNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(updateNode, url, updateNode);

                //Add the sd:supportedLanguage
                IUriNode supportedLang = g.CreateUriNode("sd:" + PropertySupportedLanguage);
                g.Assert(updateNode, supportedLang, g.CreateUriNode("sd:" + InstanceSparql11Update));

                //Add Features and Dataset Description
                //First add descriptions for Global Expression Factories
                IUriNode extensionFunction = g.CreateUriNode("sd:" + PropertyExtensionFunction);
                IUriNode extensionAggregate = g.CreateUriNode("sd:" + PropertyExtensionAggregate);
                foreach (ISparqlCustomExpressionFactory factory in SparqlExpressionFactory.Factories)
                {
                    foreach (Uri u in factory.AvailableExtensionFunctions)
                    {
                        g.Assert(updateNode, extensionFunction, g.CreateUriNode(u));
                    }
                    foreach (Uri u in factory.AvailableExtensionAggregates)
                    {
                        g.Assert(updateNode, extensionAggregate, g.CreateUriNode(u));
                    }
                }
            }
            else
            {
                updateNode = null;
            }

            //Graph Store HTTP Protocol Description
            if (config.ProtocolProcessor != null && (type == ServiceDescriptionType.Protocol || type == ServiceDescriptionType.All))
            {
                //Add the Top Level Node representing the Service
                if (descripUri.ToString().EndsWith("/description"))
                {
                    String actualUri = descripUri.ToString();
                    actualUri = actualUri.Substring(0, actualUri.LastIndexOf("/description") + 1);
                    protocolNode = g.CreateUriNode(new Uri(actualUri));
                }
                else
                {
                    protocolNode = g.CreateUriNode(descripUri);
                }
                g.Assert(protocolNode, rdfType, service);

                //Add its sd:url
                IUriNode url = g.CreateUriNode("sd:" + PropertyUrl);
                g.Assert(protocolNode, url, protocolNode);

                //Add the Input Formats
                IUriNode inputFormat = g.CreateUriNode("sd:" + PropertyInputFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanParseRdf)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(protocolNode, inputFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }

                //Add the Result Formats
                IUriNode resultFormat = g.CreateUriNode("sd:" + PropertyResultFormat);
                foreach (MimeTypeDefinition definition in MimeTypesHelper.Definitions)
                {
                    if (definition.CanWriteRdf)
                    {
                        if (definition.FormatUri != null)
                        {
                            g.Assert(protocolNode, resultFormat, g.CreateUriNode(new Uri(definition.FormatUri)));
                        }
                    }
                }
            }
            else
            {
                protocolNode = null;
            }

            //Finally get the Configuration Node to add additional feature and dataset descriptions
            config.AddFeatureDescription(g, queryNode, updateNode, protocolNode);

            return g;
        }
예제 #8
0
        internal DpwsServiceDescription(XmlReader reader, ServiceDescriptionType type)
        {
            reader.ReadStartElement(); // ProbeMatch / ResolveMatch / Hello / Bye

            // Endpoint Reference
            if (
                (reader.IsStartElement("EndpointReference", WsWellKnownUri.WsaNamespaceUri_2004_08) == false) && 
                (reader.IsStartElement("EndpointReference", WsWellKnownUri.WsaNamespaceUri_2005_08) == false) 
               )
            {
                throw new XmlException();
            }

            this.Endpoint = new WsWsaEndpointRef(reader);

            // Types
            if (reader.IsStartElement("Types", WsWellKnownUri.WsdNamespaceUri))
            {
                this.ServiceTypes = new DpwsServiceTypes(reader);
            }

            // Optional Scopes??
            if (reader.IsStartElement("Scopes", WsWellKnownUri.WsdNamespaceUri))
            {
                reader.Skip();
            }

            // XAddrs
            if (reader.IsStartElement("XAddrs", WsWellKnownUri.WsdNamespaceUri))
            {
                this.XAddrs = reader.ReadElementString().Split(' ');
                int count = XAddrs.Length;

                for (int i = 0; i < count; i++)
                {
                    // validate all XAddrs for fully qualified paths
                    if (Uri.IsWellFormedUriString(XAddrs[i], UriKind.Absolute) == false)
                    {
                        throw new XmlException();
                    }
                }
            }
            else if (type == ServiceDescriptionType.ResolveMatch) // for ResolveMatch, XAddrs is required
            {
                throw new XmlException();
            }

            // MetadataVersion
            if (reader.IsStartElement("MetadataVersion", WsWellKnownUri.WsdNamespaceUri))
            {
                this.MetadataVersion = reader.ReadElementString();
            }
            else if (type != ServiceDescriptionType.Bye) // for Hello, ProbeMatch and ResolveMatch, MetadataVersion is required
            {
                throw new XmlException();
            }

            XmlReaderHelper.SkipAllSiblings(reader); // xs:any
            reader.ReadEndElement(); // ProbeMatch / ResolveMatch / Hello / Bye
        }