/// <summary> /// Extension to get the device model name by sending a request to the UPNP service address /// </summary> /// <param name="UPNPServiceAddress">Usually Ex: "http://<ip>:49157/rootdesc1.xml", this is contained in the UPNP probe response message</param> /// <returns></returns> public static async Task get_device_infoAsync(this deviceNetworkInfo DeviceInfo) { if (!string.IsNullOrEmpty(DeviceInfo.UPNPServiceAddress)) { string model = string.Empty; using (HttpClient request = new HttpClient()) { try { XDocument doc = XDocument.Parse(await request.GetStringAsync(DeviceInfo.UPNPServiceAddress)); model = doc.Root.Element("{urn:schemas-upnp-org:device-1-0}device").Element("{urn:schemas-upnp-org:device-1-0}modelName").Value; } catch (Exception ex) { Console.WriteLine("UPNP_GET_DEVICE_INFO " + ex.Message + (ex.InnerException != null ? ex.InnerException.Message : "")); } } DeviceInfo.Model = model; } }
public void add_DeviceInfo(deviceNetworkInfo NewInfo) { this._lock.EnterWriteLock(); var existingInfo = DiscoveredDevices.Where(x => x.IPaddress.ToString() == NewInfo.IPaddress.ToString()).FirstOrDefault(); if (existingInfo == null) { //Resolve the mac address try { NewInfo.MACAddress = ExtensionMethods.getMACAddress(NewInfo.IPaddress); }catch (Exception ex) { NewInfo.MACAddress = "Could not resolve address"; } if (!string.IsNullOrEmpty(VendorMACfilter) && Regex.IsMatch(NewInfo.MACAddress.ToUpper(), VendorMACfilter)) { DiscoveredDevices.Add(NewInfo); } } else { //Check if other info could be added if (string.IsNullOrEmpty(existingInfo.ONVIFXAddress) && !string.IsNullOrEmpty(NewInfo.ONVIFXAddress)) { existingInfo.ONVIFXAddress = NewInfo.ONVIFXAddress; } if (string.IsNullOrEmpty(existingInfo.UPNPServiceAddress) && !string.IsNullOrEmpty(NewInfo.UPNPServiceAddress)) { existingInfo.UPNPServiceAddress = NewInfo.UPNPServiceAddress; } } this._lock.ExitWriteLock(); }