private void EventModelMediaServerInitial(object sender, EventArgs args) { ModelMediaServer ms = sender as ModelMediaServer; ContainerMediaServer rootContainer = null; lock (iLock) { iMediaServerRootContainers.TryGetValue(ms.Metadata.Id, out rootContainer); } if (rootContainer != null) { rootContainer.OnEventInitial(); } }
private void EventContainerUpdatedHandler(object sender, EventArgs args) { ModelMediaServer ms = sender as ModelMediaServer; ContainerMediaServer rootContainer = null; lock (iLock) { iMediaServerRootContainers.TryGetValue(ms.Metadata.Id, out rootContainer); } if (rootContainer != null) { ThreadPool.QueueUserWorkItem(delegate { rootContainer.OnEventTreeChanged(); }); } }
private void MediaServerAdded(object sender, Library.EventArgsMediaServer e) { ModelMediaServer mediaServer = null; ContainerMediaServer rootContainer = null; try { mediaServer = new ModelMediaServer(e.MediaServer, iEventProvider); mediaServer.EventContainerUpdated += EventContainerUpdatedHandler; mediaServer.EventSystemUpdateIDStateChanged += EventContainerUpdatedHandler; mediaServer.EventContentDirectoryInitialised += EventModelMediaServerInitial; mediaServer.Open(); rootContainer = new ContainerMediaServer(mediaServer, mediaServer.Metadata); } catch (Exception) { // failed to create the media server - a dodgy media server shouldn't crash the application UserLog.WriteLine(string.Format("{0}: Failed to create media server ({1}, {2})", DateTime.Now, e.MediaServer.Name, e.MediaServer.Device.Model)); } if (mediaServer != null) { lock (iLock) { iMediaServers.Remove(e.MediaServer); iMediaServers.Add(e.MediaServer, mediaServer); iMetadata.ChildCount = iMediaServers.Count; iMediaServerRootContainers[mediaServer.Metadata.Id] = rootContainer; } if (EventContentAdded != null) { EventContentAdded(this, EventArgs.Empty); } } }