internal ServiceDescriptionEventArgs(Exception Ex, UPnPClient Client, object State) { this.client = Client; this.doc = null; this.ex = Ex; this.state = State; }
/// <summary> /// Contains information about the location of a device on the network. /// </summary> /// <param name="Client">UPnP Client</param> /// <param name="Headers">All headers in notification.</param> /// <param name="LocalEndPoint">Local End Point.</param> /// <param name="RemoteEndPoint">Remote End Point.</param> internal NotificationEventArgs(UPnPClient Client, UPnPHeaders Headers, IPEndPoint LocalEndPoint, IPEndPoint RemoteEndPoint) { this.client = Client; this.headers = Headers; this.localEndPoint = LocalEndPoint; this.remoteEndPoint = RemoteEndPoint; }
public UPnPService(XmlElement Xml, Uri BaseUri, UPnPClient Client) { this.client = Client; this.xml = Xml; foreach (XmlNode N in Xml.ChildNodes) { switch (N.LocalName) { case "serviceType": this.serviceType = N.InnerText; break; case "serviceId": this.serviceId = N.InnerText; break; case "SCPDURL": this.scpdURL = N.InnerText; this.scpdURI = new Uri(BaseUri, this.scpdURL); break; case "controlURL": this.controlURL = N.InnerText; this.controlURI = new Uri(BaseUri, this.controlURL); break; case "eventSubURL": this.eventSubURL = N.InnerText; this.eventSubURI = new Uri(BaseUri, this.eventSubURL); break; } } }
internal ServiceDescriptionEventArgs(ServiceDescriptionDocument Doc, UPnPClient Client, object State) { this.client = Client; this.doc = Doc; this.ex = null; this.state = State; }
/// <summary> /// Contains information about the location of a device on the network. /// </summary> /// <param name="SearchTarget">SSDP Search Target</param> /// <param name="Server">Server</param> /// <param name="Location">Location of device information</param> /// <param name="UniqueServiceName">Unique Service Name (USN)</param> /// <param name="Headers">All headers in response.</param> internal DeviceLocation(UPnPClient Client, string SearchTarget, string Server, string Location, string UniqueServiceName, UPnPHeaders Headers) { this.client = Client; this.searchTarget = SearchTarget; this.server = Server; this.location = Location; this.uniqueServiceName = UniqueServiceName; this.headers = Headers; }
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; } } }
public UPnPService(UPnPClient Client, string ServiceType, string ServiceId, string ScpdUrl) { this.client = Client; this.xml = null; this.serviceType = ServiceType; this.serviceId = ServiceId; this.scpdURL = ScpdUrl; this.scpdURI = new Uri(ScpdUrl); this.controlURL = null; this.controlURI = null; this.eventSubURL = null; this.eventSubURI = null; }
internal DeviceDescriptionDocument(XmlDocument Xml, UPnPClient Client, string BaseUrl) { this.xml = Xml; if (Xml.DocumentElement != null && Xml.DocumentElement.LocalName == "root" && Xml.DocumentElement.NamespaceURI == "urn:schemas-upnp-org:device-1-0") { if (!string.IsNullOrEmpty(BaseUrl)) { this.baseUrl = BaseUrl; this.baseUri = new Uri(this.baseUrl); } 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 "URLBase": this.baseUrl = N.InnerText; this.baseUri = new Uri(this.baseUrl); break; case "device": this.device = new UPnPDevice((XmlElement)N, this.baseUri, Client); break; } } } else throw new Exception("Unrecognized file format."); }
internal DeviceDescriptionDocument(XmlDocument Xml, UPnPClient Client, string BaseUrl) { this.xml = Xml; if (!(Xml.DocumentElement is null) && Xml.DocumentElement.LocalName == "root" && Xml.DocumentElement.NamespaceURI == "urn:schemas-upnp-org:device-1-0") { if (!string.IsNullOrEmpty(BaseUrl)) { this.baseUrl = BaseUrl; this.baseUri = new Uri(this.baseUrl); } 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 "URLBase": this.baseUrl = N.InnerText; this.baseUri = new Uri(this.baseUrl); break; case "device": this.device = new UPnPDevice((XmlElement)N, this.baseUri, Client); break; } } }
internal UPnPDevice(XmlElement Xml, Uri BaseUri, UPnPClient Client) { List <UPnPIcon> Icons = new List <UPnPIcon>(); List <UPnPService> Services = new List <UPnPService>(); List <UPnPDevice> Devices = new List <UPnPDevice>(); this.xml = Xml; foreach (XmlNode N in Xml.ChildNodes) { switch (N.LocalName) { case "deviceType": this.deviceType = N.InnerText; break; case "friendlyName": this.friendlyName = N.InnerText; break; case "manufacturer": this.manufacturer = N.InnerText; break; case "manufacturerURL": this.manufacturerURL = N.InnerText; this.manufacturerURI = new Uri(BaseUri, this.manufacturerURL); break; case "modelDescription": this.modelDescription = N.InnerText; break; case "modelName": this.modelName = N.InnerText; break; case "modelNumber": this.modelNumber = N.InnerText; break; case "modelURL": this.modelURL = N.InnerText; this.modelURI = new Uri(BaseUri, this.modelURL); break; case "serialNumber": this.serialNumber = N.InnerText; break; case "UDN": this.udn = N.InnerText; break; case "UPC": this.upc = N.InnerText; break; case "iconList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "icon") { Icons.Add(new UPnPIcon((XmlElement)N2, BaseUri)); } } break; case "serviceList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "service") { Services.Add(new UPnPService((XmlElement)N2, BaseUri, Client)); } } break; case "deviceList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "device") { Devices.Add(new UPnPDevice((XmlElement)N2, BaseUri, Client)); } } break; case "presentationURL": this.presentationURL = N.InnerText; this.presentationURI = new Uri(BaseUri, this.presentationURL); break; } } this.icons = Icons.ToArray(); this.services = Services.ToArray(); this.devices = Devices.ToArray(); }
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(); }
internal UPnPDevice(XmlElement Xml, Uri BaseUri, UPnPClient Client) { List<UPnPIcon> Icons = new List<UPnPIcon>(); List<UPnPService> Services = new List<UPnPService>(); List<UPnPDevice> Devices = new List<UPnPDevice>(); this.xml = Xml; foreach (XmlNode N in Xml.ChildNodes) { switch (N.LocalName) { case "deviceType": this.deviceType = N.InnerText; break; case "friendlyName": this.friendlyName = N.InnerText; break; case "manufacturer": this.manufacturer = N.InnerText; break; case "manufacturerURL": this.manufacturerURL = N.InnerText; this.manufacturerURI = new Uri(BaseUri, this.manufacturerURL); break; case "modelDescription": this.modelDescription = N.InnerText; break; case "modelName": this.modelName = N.InnerText; break; case "modelNumber": this.modelNumber = N.InnerText; break; case "modelURL": this.modelURL = N.InnerText; this.modelURI = new Uri(BaseUri, this.modelURL); break; case "serialNumber": this.serialNumber = N.InnerText; break; case "UDN": this.udn = N.InnerText; break; case "UPC": this.upc = N.InnerText; break; case "iconList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "icon") Icons.Add(new UPnPIcon((XmlElement)N2, BaseUri)); } break; case "serviceList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "service") Services.Add(new UPnPService((XmlElement)N2, BaseUri, Client)); } break; case "deviceList": foreach (XmlNode N2 in N.ChildNodes) { if (N2.LocalName == "device") Devices.Add(new UPnPDevice((XmlElement)N2, BaseUri, Client)); } break; case "presentationURL": this.presentationURL = N.InnerText; this.presentationURI = new Uri(BaseUri, this.presentationURL); break; } } this.icons = Icons.ToArray(); this.services = Services.ToArray(); this.devices = Devices.ToArray(); }
private void StartSearch() { try { this.upnpClient = new UPnPClient(); this.upnpClient.OnDeviceFound += new UPnPDeviceLocationEventHandler(upnpClient_OnDeviceFound); this.State = PeerToPeerNetworkState.SearchingForGateway; this.upnpClient.StartSearch("urn:schemas-upnp-org:service:WANIPConnection:1", 1); this.upnpClient.StartSearch("urn:schemas-upnp-org:service:WANIPConnection:2", 1); } catch (Exception ex) { this.exception = ex; this.State = PeerToPeerNetworkState.Error; } }
private void upnpClient_OnDeviceFound(UPnPClient Sender, DeviceLocationEventArgs e) { try { lock (this.ipAddressesFound) { if (this.ipAddressesFound.ContainsKey(e.RemoteEndPoint.Address)) return; this.ipAddressesFound[e.RemoteEndPoint.Address] = true; } e.Location.StartGetDevice(this.DeviceRetrieved, e); } catch (Exception ex) { this.exception = ex; this.State = PeerToPeerNetworkState.Error; } }
/// <summary> /// <see cref="IDisposable.Dispose"/> /// </summary> public void Dispose() { this.State = PeerToPeerNetworkState.Closed; if (this.tcpListener != null) { this.tcpListener.Stop(); this.tcpListener = null; } if (this.tcpMappingAdded) { this.tcpMappingAdded = false; try { this.serviceWANIPConnectionV1.DeletePortMapping(string.Empty, (ushort)this.localEndpoint.Port, "TCP"); } catch (Exception) { // Ignore } } if (this.udpMappingAdded) { this.udpMappingAdded = false; try { this.serviceWANIPConnectionV1.DeletePortMapping(string.Empty, (ushort)this.localEndpoint.Port, "UDP"); } catch (Exception) { // Ignore } } this.serviceWANIPConnectionV1 = null; if (this.upnpClient != null) { this.upnpClient.Dispose(); this.upnpClient = null; } if (this.ipAddressesFound != null) { this.ipAddressesFound.Clear(); this.ipAddressesFound = null; } if (this.ready != null) { this.ready.Close(); this.ready = null; } if (this.error != null) { this.error.Close(); this.error = null; } }