Beispiel #1
0
        /// <summary>
        /// Gets a Service Description Document from a device.
        /// </summary>
        /// <param name="Service">Service object.</param>
        /// <param name="Timeout">Timeout, in milliseconds.</param>
        /// <returns>Service description document, if found, or null otherwise.</returns>
        public async Task <ServiceDescriptionDocument> GetServiceAsync(UPnPService Service, int Timeout)
        {
            using (HttpClient Client = new HttpClient())
            {
                try
                {
                    Client.Timeout = TimeSpan.FromMilliseconds(Timeout);
                    Stream Stream = await Client.GetStreamAsync(Service.SCPDURI);

                    XmlDocument Xml = new XmlDocument();
                    Xml.Load(Stream);

                    return(new ServiceDescriptionDocument(Xml, this, Service));
                }
                catch (Exception ex)
                {
                    this.RaiseOnError(ex);
                    return(null);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Gets a service, given its service type.
        /// </summary>
        /// <param name="ServiceType">Service type.</param>
        /// <returns>Service object, if found, null otherwise.</returns>
        public UPnPService GetService(string ServiceType)
        {
            UPnPService Result = null;

            foreach (UPnPService Service in this.services)
            {
                if (Service.ServiceType == ServiceType)
                {
                    return(Service);
                }
            }

            foreach (UPnPDevice Device in this.devices)
            {
                Result = Device.GetService(ServiceType);
                if (Result != null)
                {
                    return(Result);
                }
            }

            return(null);
        }
Beispiel #3
0
 /// <summary>
 /// Gets a Service Description Document from a device.
 /// </summary>
 /// <param name="Service">Service object.</param>
 /// <returns>Service description document, if found, or null otherwise.</returns>
 public Task <ServiceDescriptionDocument> GetServiceAsync(UPnPService Service)
 {
     return(this.GetServiceAsync(Service, 10000));
 }
Beispiel #4
0
 /// <summary>
 /// Gets the service description document from a service in the network.
 /// This method is the synchronous version of <see cref="GetServiceAsync(UPnPService, int)"/>.
 /// </summary>
 /// <param name="Service">Service to get.</param>
 /// <param name="Timeout">Timeout, in milliseconds.</param>
 /// <returns>Service Description Document.</returns>
 /// <exception cref="TimeoutException">If the document could not be retrieved within the timeout time.</exception>
 /// <exception cref="Exception">If the document could not be retrieved, or could not be parsed.</exception>
 public ServiceDescriptionDocument GetService(UPnPService Service, int Timeout)
 {
     return(this.GetServiceAsync(Service, Timeout).Result);
 }
Beispiel #5
0
 /// <summary>
 /// Gets the service description document from a service in the network.
 /// This method is the synchronous version of <see cref="GetServiceAsync(UPnPService)"/>.
 /// </summary>
 /// <param name="Service">Service to get.</param>
 /// <returns>Service Description Document.</returns>
 /// <exception cref="TimeoutException">If the document could not be retrieved within the timeout time.</exception>
 /// <exception cref="Exception">If the document could not be retrieved, or could not be parsed.</exception>
 public ServiceDescriptionDocument GetService(UPnPService Service)
 {
     return(this.GetService(Service, 10000));
 }
        internal ServiceDescriptionDocument(XmlDocument Xml, UPnPClient Client, UPnPService Service)
        {
            List <UPnPStateVariable> Variables = new List <UPnPStateVariable>();
            List <UPnPAction>        Actions   = new List <UPnPAction>();

            this.xml     = Xml;
            this.service = Service;

            if (Xml.DocumentElement != null && Xml.DocumentElement.LocalName == "scpd" &&
                Xml.DocumentElement.NamespaceURI == "urn:schemas-upnp-org:service-1-0")
            {
                foreach (XmlNode N in Xml.DocumentElement.ChildNodes)
                {
                    switch (N.LocalName)
                    {
                    case "specVersion":
                        foreach (XmlNode N2 in N.ChildNodes)
                        {
                            switch (N2.LocalName)
                            {
                            case "major":
                                this.majorVersion = int.Parse(N2.InnerText);
                                break;

                            case "minor":
                                this.minorVersion = int.Parse(N2.InnerText);
                                break;
                            }
                        }
                        break;

                    case "actionList":
                        foreach (XmlNode N2 in N.ChildNodes)
                        {
                            if (N2.LocalName == "action")
                            {
                                UPnPAction Action = new UPnPAction((XmlElement)N2, this);
                                Actions.Add(Action);
                                this.actionsByName[Action.Name] = Action;
                            }
                        }
                        break;

                    case "serviceStateTable":
                        foreach (XmlNode N2 in N.ChildNodes)
                        {
                            if (N2.LocalName == "stateVariable")
                            {
                                UPnPStateVariable Variable = new UPnPStateVariable((XmlElement)N2);
                                Variables.Add(Variable);
                                this.variablesByName[Variable.Name] = Variable;
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                throw new Exception("Unrecognized file format.");
            }

            this.actions   = Actions.ToArray();
            this.variables = Variables.ToArray();
        }