Пример #1
0
        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();
            }
        }
Пример #2
0
        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();
                });
            }
        }
Пример #3
0
        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);
                }
            }
        }