protected virtual void OnDLNADeviceUpdated(DLNADeviceConnectionManager m, DLNADevice d) { if (DLNADeviceUpdated != null) { DLNADeviceUpdated(m, d); } }
// Summary: // Check if the device is connected (a ping have been successful) public virtual bool IsDLNADeviceConnected(DLNADevice cd) { if (listDLNADevices.ContainsKey(cd.Id)) { return(listDLNADevices[cd.Id].Status == DLNADeviceStatus.Connected); } return(false); }
protected DLNADevice GetUniqueDeviceByID(string id) { DLNADevice device = null; foreach (var d in listDLNADevices) { if (string.Equals(d.Value.Id, id)) { if (device == null) { device = d.Value; } else { // not unique return(null); } } } return(device); }
protected DLNADevice GetUniqueDeviceByName(string Name) { DLNADevice device = null; foreach (var d in listDLNADevices) { if (string.Equals(d.Value.FriendlyName, Name)) { if (device == null) { device = d.Value; } else { // not unique return(null); } } } return(device); }
public async System.Threading.Tasks.Task <bool> ParseMessage(string message) { if (!string.IsNullOrEmpty(message)) { string[] sep = { "\r\n" }; string[] array = message.Split(sep, StringSplitOptions.RemoveEmptyEntries); if (array != null) { string Id = string.Empty; string Location = string.Empty; string Version = string.Empty; string IpCache = string.Empty; string Server = string.Empty; string St = string.Empty; string Usn = string.Empty; string Ip = string.Empty; string friendlyName = string.Empty; string manufacturer = string.Empty; string modelName = string.Empty; string modelNumber = string.Empty; for (int i = 0; i < array.Length; i++) { if (array[i].StartsWith("LOCATION: ")) { Location = array[i].Substring(10); if (!string.IsNullOrEmpty(Location)) { if (Location.StartsWith("http://")) { int pos = Location.IndexOf(':', 7); if (pos > 0) { Ip = Location.Substring(7, pos - 7); } string HEOSXmlContent = await GetDeviceInformation(Location); if (!string.IsNullOrEmpty(HEOSXmlContent)) { friendlyName = GetParameter(HEOSXmlContent, "friendlyName"); manufacturer = GetParameter(HEOSXmlContent, "manufacturer"); modelName = GetParameter(HEOSXmlContent, "modelName"); modelNumber = GetParameter(HEOSXmlContent, "modelNumber"); } } } } else if (array[i].StartsWith("VERSIONS.UPNP.HEOS.COM: ")) { Version = array[i].Substring(24); } else if (array[i].StartsWith("IPCACHE.URL.UPNP.HEOS.COM: ")) { IpCache = array[i].Substring(27); } else if (array[i].StartsWith("SERVER: ")) { Server = array[i].Substring(8); } else if (array[i].StartsWith("ST: ")) { St = array[i].Substring(4); } else if (array[i].StartsWith("USN: ")) { Usn = array[i].Substring(5); if (!string.IsNullOrEmpty(Usn)) { if (Usn.StartsWith("uuid:")) { int pos = Usn.IndexOf(':', 5); if (pos > 0) { Id = Usn.Substring(6, pos - 6); } } } } } if ((!string.IsNullOrEmpty(Id)) && (!string.IsNullOrEmpty(friendlyName))) { DLNADevice hs = new DLNADevice(Id, Location, Version, IpCache, Server, St, Usn, Ip, friendlyName, manufacturer, modelName, modelNumber, DLNADevicePlayMode.Normal, false); if (hs != null) { await hs.GetDNLAServices(); if (GetUniqueDeviceByID(Id) != null) { listDLNADevices[Id] = hs; OnDLNADeviceUpdated(this, hs); } else { listDLNADevices.Add(Id, hs); OnDLNADeviceAdded(this, hs); } return(true); } } } } return(false); }