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 is 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; } } }
/// <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 is null)) { return(Result); } } return(null); }
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(); }
/// <summary> /// Starts the retrieval of a Service Description Document. /// </summary> /// <param name="Service">Service object.</param> /// <param name="Callback">Callback method. Will be called when the document has been downloaded, or an error has occurred.</param> /// <param name="State">State object propagated to the callback method.</param> public void StartGetService(UPnPService Service, ServiceDescriptionEventHandler Callback, object State) { WebClient Client = new WebClient(); Client.DownloadDataCompleted += new DownloadDataCompletedEventHandler(DownloadServiceCompleted); Client.DownloadDataAsync(Service.SCPDURI, new object[] { Service, Callback, State }); }
/// <summary> /// Gets the service description document from a service in the network. /// This method is the synchronous version of <see cref="StartGetService"/>. /// </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) { ManualResetEvent Done = new ManualResetEvent(false); ServiceDescriptionEventArgs e = null; this.StartGetService(Service, (sender, e2) => { e = e2; Done.Set(); }, null); if (!Done.WaitOne(Timeout)) throw new TimeoutException("Timeout."); if (e.Exception != null) throw e.Exception; return e.ServiceDescriptionDocument; }
/// <summary> /// Gets the service description document from a service in the network. /// This method is the synchronous version of <see cref="StartGetService"/>. /// </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); }