예제 #1
0
        private void SenderAdded(object sender, Senders.EventArgsSender e)
        {
            lock (iLock)
            {
                if (iOpen)
                {
                    try
                    {
                        ModelSender model = new ModelSender(e.Sender, iEventServer);
                        model.EventAudioChanged      += SenderChanged;
                        model.EventMetadataChanged   += SenderChanged;
                        model.EventStatusChanged     += SenderChanged;
                        model.EventSenderInitialised += SenderInitialised;
                        model.EventSubscriptionError += SubscriptionError;

                        iPendingSenderList.Add(e.Sender.Device.Udn, model);

                        model.Open();
                    }
                    catch (ServiceException ex)
                    {
                        UserLog.WriteLine("Failed to create ModelSender: " + ex);
                        iSenders.RemoveDevice(e.Sender.Device);
                    }
                }
            }
        }
예제 #2
0
        private void SenderRemoved(object sender, Senders.EventArgsSender e)
        {
            ModelSender model;
            bool        changed = false;

            lock (iLock)
            {
                if (iPendingSenderList.TryGetValue(e.Sender.Device.Udn, out model))
                {
                    iPendingSenderList.Remove(e.Sender.Device.Udn);
                }
                else
                {
                    if (iSenderList.TryGetValue(e.Sender.Device.Udn, out model))
                    {
                        iSenderList.Remove(e.Sender.Device.Udn);
                        iEnabledSenderList.Remove(model);
                    }
                    else
                    {
                        model = null;
                    }
                }

                if (model != null)
                {
                    model.EventSenderInitialised -= SenderInitialised;
                    model.EventAudioChanged      -= SenderChanged;
                    model.EventMetadataChanged   -= SenderChanged;
                    model.EventStatusChanged     -= SenderChanged;
                    model.EventSubscriptionError -= SubscriptionError;

                    model.Close();

                    changed = true;
                }
            }

            if (changed && EventSenderRemoved != null)
            {
                EventSenderRemoved(this, new EventArgsSender(model));
            }
        }