Exemple #1
0
        private void MediaServerAdded(object sender, Library.EventArgsMediaServer e)
        {
            ModelMediaServer server = null;

            Trace.WriteLine(Trace.kMediaServer, ">ModelLibrary.MediaServerAdded: " + e.MediaServer);
            try
            {
                server = new ModelMediaServer(e.MediaServer, iEventServer);
            }
            catch (Linn.ControlPoint.ServiceException ex)
            {
                // Need to show media server icon with error symbol
                UserLog.WriteLine(e.MediaServer + ": (" + ex.Message + ")");

                return;
            }

            try
            {
                iMutex.WaitOne();

                UserLog.WriteLine(DateTime.Now + ": Library+                " + server);

                iMediaServerByUdn.Add(server.Udn, server);
                iMediaServerList.Add(server.Name + server.Udn, e.MediaServer);

                iHomeContainer.ChildCount = iMediaServerList.Count;

                iUpdateId++;

                iMutex.ReleaseMutex();
            }
            catch (Exception ex)
            {
                Trace.WriteLine(Trace.kMediaServer, "ModelLibrary.MediaServerAdded: " + ex.Message);

                iMutex.ReleaseMutex();

                throw ex;
            }

            server.EventContentDirectoryInitialised += EventContentDirectoryInitialisedResponse;
            server.EventContainerUpdated            += EventContainerUpdatedResponse;

            server.Open();

            iMutex.WaitOne();
            uint updateId = iUpdateId;

            iMutex.ReleaseMutex();

            EventContainerUpdatedResponse(null, new ModelMediaServer.EventArgsContainerUpdate(iHomeContainer.Id, updateId.ToString()));

            Trace.WriteLine(Trace.kMediaServer, "<ModelLibrary.MediaServerAdded");
        }
Exemple #2
0
        private void MediaServerRemoved(object sender, Library.EventArgsMediaServer e)
        {
            Trace.WriteLine(Trace.kMediaServer, ">ModelLibrary.MediaServerRemoved: " + e.MediaServer.Name);

            string           udn = e.MediaServer.Device.Udn;
            ModelMediaServer server;

            iMutex.WaitOne();

            if (iMediaServerByUdn.TryGetValue(udn, out server))
            {
                try
                {
                    iMediaServerByUdn.Remove(server.Udn);
                    iMediaServerList.Remove(server.Name + server.Udn);

                    iHomeContainer.ChildCount = iMediaServerList.Count;

                    iUpdateId++;

                    iMutex.ReleaseMutex();
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(Trace.kMediaServer, "ModelLibrary.MediaServerRemoved: " + ex.Message);

                    iMutex.ReleaseMutex();

                    throw ex;
                }

                server.Close();

                server.EventContentDirectoryInitialised -= EventContentDirectoryInitialisedResponse;
                server.EventContainerUpdated            -= EventContainerUpdatedResponse;

                UserLog.WriteLine(DateTime.Now + ": Library-                " + server);

                iMutex.WaitOne();
                uint updateId = iUpdateId;
                iMutex.ReleaseMutex();

                EventContainerUpdatedResponse(null, new ModelMediaServer.EventArgsContainerUpdate(iHomeContainer.Id, updateId.ToString()));
            }
            else
            {
                iMutex.ReleaseMutex();
            }

            Trace.WriteLine(Trace.kMediaServer, "<ModelLibrary.MediaServerRemoved");
        }