Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
UPnPDevice.cs
1using System;
2using System.Collections.Generic;
3using System.Text;
4using System.Xml;
5
7{
11 public class UPnPDevice
12 {
13 private readonly XmlElement xml;
14 private readonly string deviceType;
15 private readonly string friendlyName;
16 private readonly string manufacturer;
17 private readonly string manufacturerURL;
18 private readonly string modelDescription;
19 private readonly string modelName;
20 private readonly string modelNumber;
21 private readonly string modelURL;
22 private readonly string serialNumber;
23 private readonly string udn;
24 private readonly string upc;
25 private readonly UPnPIcon[] icons;
26 private readonly UPnPService[] services;
27 private readonly UPnPDevice[] devices;
28 private readonly string presentationURL;
29 private readonly Uri manufacturerURI;
30 private readonly Uri modelURI;
31 private readonly Uri presentationURI;
32
33 internal UPnPDevice(XmlElement Xml, Uri BaseUri, UPnPClient Client)
34 {
35 List<UPnPIcon> Icons = new List<UPnPIcon>();
36 List<UPnPService> Services = new List<UPnPService>();
37 List<UPnPDevice> Devices = new List<UPnPDevice>();
38
39 this.xml = Xml;
40
41 foreach (XmlNode N in Xml.ChildNodes)
42 {
43 switch (N.LocalName)
44 {
45 case "deviceType":
46 this.deviceType = N.InnerText;
47 break;
48
49 case "friendlyName":
50 this.friendlyName = N.InnerText;
51 break;
52
53 case "manufacturer":
54 this.manufacturer = N.InnerText;
55 break;
56
57 case "manufacturerURL":
58 this.manufacturerURL = N.InnerText;
59 this.manufacturerURI = new Uri(BaseUri, this.manufacturerURL);
60 break;
61
62 case "modelDescription":
63 this.modelDescription = N.InnerText;
64 break;
65
66 case "modelName":
67 this.modelName = N.InnerText;
68 break;
69
70 case "modelNumber":
71 this.modelNumber = N.InnerText;
72 break;
73
74 case "modelURL":
75 this.modelURL = N.InnerText;
76 this.modelURI = new Uri(BaseUri, this.modelURL);
77 break;
78
79 case "serialNumber":
80 this.serialNumber = N.InnerText;
81 break;
82
83 case "UDN":
84 this.udn = N.InnerText;
85 break;
86
87 case "UPC":
88 this.upc = N.InnerText;
89 break;
90
91 case "iconList":
92 foreach (XmlNode N2 in N.ChildNodes)
93 {
94 if (N2.LocalName == "icon")
95 Icons.Add(new UPnPIcon((XmlElement)N2, BaseUri));
96 }
97 break;
98
99 case "serviceList":
100 foreach (XmlNode N2 in N.ChildNodes)
101 {
102 if (N2.LocalName == "service")
103 Services.Add(new UPnPService((XmlElement)N2, BaseUri, Client));
104 }
105 break;
106
107 case "deviceList":
108 foreach (XmlNode N2 in N.ChildNodes)
109 {
110 if (N2.LocalName == "device")
111 Devices.Add(new UPnPDevice((XmlElement)N2, BaseUri, Client));
112 }
113 break;
114
115 case "presentationURL":
116 this.presentationURL = N.InnerText;
117 this.presentationURI = new Uri(BaseUri, this.presentationURL);
118 break;
119 }
120 }
121
122 this.icons = Icons.ToArray();
123 this.services = Services.ToArray();
124 this.devices = Devices.ToArray();
125 }
126
130 public XmlElement Xml => this.xml;
131
135 public string DeviceType => this.deviceType;
136
140 public string FriendlyName => this.friendlyName;
141
145 public string Manufacturer => this.manufacturer;
146
150 public string ManufacturerURL => this.manufacturerURL;
151
155 public string ModelDescription => this.modelDescription;
156
160 public string ModelName => this.modelName;
161
165 public string ModelNumber => this.modelNumber;
166
170 public string ModelURL => this.modelURL;
171
175 public string SerialNumber => this.serialNumber;
176
180 public string UDN => this.udn;
181
185 public string UPC => this.upc;
186
190 public UPnPIcon[] Icons => this.icons;
191
195 public UPnPService[] Services => this.services;
196
200 public UPnPDevice[] Devices => this.devices;
201
205 public string PresentationURL => this.presentationURL;
206
210 public Uri ManufacturerURI => this.manufacturerURI;
211
215 public Uri ModelURI => this.modelURI;
216
220 public Uri PresentationURI => this.presentationURI;
221
223 public override string ToString()
224 {
225 return this.friendlyName;
226 }
227
234 {
235 UPnPDevice Result = null;
236
237 if (this.deviceType == DeviceType)
238 Result = this;
239 else
240 {
241 foreach (UPnPDevice Device in this.devices)
242 {
243 Result = Device.GetDevice(DeviceType);
244 if (!(Result is null))
245 break;
246 }
247 }
248
249 return Result;
250 }
251
257 public UPnPService GetService(string ServiceType)
258 {
259 UPnPService Result;
260
261 foreach (UPnPService Service in this.services)
262 {
263 if (Service.ServiceType == ServiceType)
264 return Service;
265 }
266
267 foreach (UPnPDevice Device in this.devices)
268 {
269 Result = Device.GetService(ServiceType);
270 if (!(Result is null))
271 return Result;
272 }
273
274 return null;
275 }
276
281 {
282 get
283 {
284 List<UPnPDevice> Result = new List<UPnPDevice>()
285 {
286 this
287 };
288
289 foreach (UPnPDevice Device in this.devices)
290 Result.AddRange(Device.DevicesRecursive);
291
292 return Result.ToArray();
293 }
294 }
295
300 {
301 get
302 {
303 List<UPnPService> Result = new List<UPnPService>();
304
305 Result.AddRange(this.services);
306 foreach (UPnPDevice Device in this.devices)
307 Result.AddRange(Device.ServicesRecursive);
308
309 return Result.ToArray();
310 }
311 }
312
313 }
314}
Implements support for the UPnP protocol, as described in: http://upnp.org/specs/arch/UPnP-arch-Devic...
Definition: UPnPClient.cs:21
Contains information about a device.
Definition: UPnPDevice.cs:12
string ModelDescription
Long user-friendly title
Definition: UPnPDevice.cs:155
UPnPService GetService(string ServiceType)
Gets a service, given its service type.
Definition: UPnPDevice.cs:257
UPnPService[] Services
Services published by the device.
Definition: UPnPDevice.cs:195
UPnPDevice GetDevice(string DeviceType)
Gets a device or embedded device, given its device type.
Definition: UPnPDevice.cs:233
UPnPDevice[] DevicesRecursive
Returns all devices, including the device itself and its embedded devices, and their embedded devices...
Definition: UPnPDevice.cs:281
string DeviceType
Device type
Definition: UPnPDevice.cs:135
string UDN
Unique Device Name (uuid:UUID)
Definition: UPnPDevice.cs:180
string FriendlyName
Short user-friendly title
Definition: UPnPDevice.cs:140
Uri ManufacturerURI
URI to manufacturer site
Definition: UPnPDevice.cs:210
string ManufacturerURL
URL to manufacturer site
Definition: UPnPDevice.cs:150
string SerialNumber
Manufacturer's serial number
Definition: UPnPDevice.cs:175
string PresentationURL
URL for presentation
Definition: UPnPDevice.cs:205
UPnPIcon[] Icons
Icons for the device.
Definition: UPnPDevice.cs:190
string ModelURL
URL to model site
Definition: UPnPDevice.cs:170
Uri ModelURI
URI to model site
Definition: UPnPDevice.cs:215
Uri PresentationURI
URI for presentation
Definition: UPnPDevice.cs:220
UPnPDevice[] Devices
Embedded devices.
Definition: UPnPDevice.cs:200
UPnPService[] ServicesRecursive
Returns all services, including the service of itself and services of its embedded devices,...
Definition: UPnPDevice.cs:300
string ModelNumber
Model number
Definition: UPnPDevice.cs:165
string UPC
Universal Product Code
Definition: UPnPDevice.cs:185
string Manufacturer
Manufacturer name
Definition: UPnPDevice.cs:145
XmlElement Xml
Underlying XML definition.
Definition: UPnPDevice.cs:130
Contains information about an icon.
Definition: UPnPIcon.cs:12
Contains information about a service.
Definition: UPnPService.cs:12
string ServiceType
Service Type
Definition: UPnPService.cs:94