internal void DoMediaServerAdded(Device aDevice) { MediaServer server = new MediaServer(this, aDevice); iMediaServers.Add(aDevice, server); if (EventMediaServerAdded != null) { EventMediaServerAdded(this, new EventArgsMediaServer(new MediaServer(this, aDevice))); } }
internal void DoMediaServerRemoved(Device aDevice) { if (iMediaServers.ContainsKey(aDevice)) { MediaServer server = iMediaServers[aDevice]; if (EventMediaServerRemoved != null) { EventMediaServerRemoved(this, new EventArgsMediaServer(server)); } iMediaServers.Remove(aDevice); } }
internal void DoCloudServerRemoved(string aLocation) { Device device; if (iCloudServers.TryGetValue(aLocation, out device)) { MediaServer server = iMediaServers[device]; iMediaServers.Remove(device); Trace.WriteLine(Trace.kTopology, "Cloud- " + device); iCloudServers.Remove(aLocation); if (EventMediaServerRemoved != null) { EventMediaServerRemoved(this, new EventArgsMediaServer(server)); } } }
internal void DoCloudServerAdded(string aLocation) { try { if (!iCloudServers.ContainsKey(aLocation)) { Device device = new DeviceUpnp(aLocation); MediaServer server = new MediaServer(this, device); iMediaServers.Add(device, server); iCloudServers.Add(aLocation, device); Trace.WriteLine(Trace.kTopology, "Cloud+ " + device); if (EventMediaServerAdded != null) { EventMediaServerAdded(this, new EventArgsMediaServer(server)); } } } catch (Exception) { } }
public DidlLite Items(string aMediaServerId, string aId, uint aStartIndex, uint aCount, out uint aUpdateId) { if (aMediaServerId == string.Empty) { DidlLite result = new DidlLite(); iMutex.WaitOne(); aUpdateId = iUpdateId; uint endIndex = aStartIndex + aCount; for (uint i = 0; i < endIndex && i < iMediaServerList.Values.Count; ++i) { MediaServer server = iMediaServerList.Values[(int)i]; ModelMediaServer s; if (iMediaServerByUdn.TryGetValue(server.Device.Udn, out s)) { result.Add(s.Metadata); } } iMutex.ReleaseMutex(); return(result); } else { ModelMediaServer server = ModelMediaServer(aMediaServerId); if (server != null) { DidlLite result; uint numberReturned, totalMatches; server.Browse(aId, aStartIndex, aCount, out result, out numberReturned, out totalMatches, out aUpdateId); return(result); } } // we get here if the media server we are querying is not in our media server list throw new LibraryNotFoundException(aMediaServerId); }
public ModelMediaServer(MediaServer aMediaServer, IEventUpnpProvider aEventServer) { iMediaServer = aMediaServer; iServiceContentDirectory = new ServiceContentDirectory(iMediaServer.Device, aEventServer); iMetadata = new container(); iMetadata.ParentId = "Library"; string title = iMediaServer.Name; if (title != null) { iMetadata.Title = title; } iMetadata.Id = Udn; iMetadata.Restricted = true; if (title != null) { XmlDocument doc = new XmlDocument(); doc.LoadXml(aMediaServer.Device.DeviceXml); XmlNamespaceManager nsm = new XmlNamespaceManager(doc.NameTable); nsm.AddNamespace("ns", "urn:schemas-upnp-org:device-1-0"); XmlNodeList icons = doc.SelectNodes("/ns:root/ns:device/ns:iconList/ns:icon", nsm); string url = string.Empty; int width = 0; int height = 0; int depth = 0; foreach (XmlNode i in icons) { // some servers do not implement this part of the XML correctly i.e. some of these // elements are missing - given that this code is just to identify an icon to show // for the server, it is a bit harsh to enforce the standard and forego the use of the // server, so this incorrect XML is just accounted for here XmlNode widthNode = i.SelectSingleNode("ns:width", nsm); XmlNode heightNode = i.SelectSingleNode("ns:height", nsm); XmlNode depthNode = i.SelectSingleNode("ns:depth", nsm); XmlNode urlNode = i.SelectSingleNode("ns:url", nsm); try { int w = (widthNode != null) ? int.Parse(widthNode.InnerText, System.Globalization.CultureInfo.InvariantCulture) : 0; int h = (heightNode != null) ? int.Parse(heightNode.InnerText, System.Globalization.CultureInfo.InvariantCulture) : 0; int d = (depthNode != null) ? int.Parse(depthNode.InnerText, System.Globalization.CultureInfo.InvariantCulture) : 0; if (urlNode != null && (w > width || h > height || d > depth)) { width = w; height = h; depth = d; url = urlNode.InnerText; if (url.StartsWith("/")) { url = url.Substring(1); } } } catch (FormatException) { } } if (url != string.Empty) { Uri uri = new Uri(aMediaServer.Device.Location); iMetadata.AlbumArtUri.Add(string.Format("http://{0}:{1}/{2}", aMediaServer.Device.IpAddress, uri.Port, url)); } } }
internal EventArgsMediaServer(MediaServer aMediaServer) { MediaServer = aMediaServer; }