Esempio n. 1
0
        private void ArmTimer(Announce announce)
        {
            string path         = announce.Path;
            int    expriationMs = this.GetExpirationMilliSeconds(announce);

            lock (this.deviceMap)
            {
                if (!this.stopped)
                {
                    if (this.deviceMap.ContainsKey(path))
                    {
                        AnnounceTimer timer = this.deviceMap[path];
                        timer.Stop();
                        Announce oldAnnounce = timer.Announce;
                        if (!oldAnnounce.Equals(announce))
                        {
                            timer.Announce = announce;
                            if (this.HandleUpdateDevice != null)
                            {
                                UpdateDeviceEventArgs updateDeviceEvent = new UpdateDeviceEventArgs();
                                updateDeviceEvent.NewAnnounce = announce;
                                updateDeviceEvent.OldAnnounce = oldAnnounce;
                                this.HandleUpdateDevice(this, updateDeviceEvent);
                            }
                        }

                        timer.Interval = expriationMs;
                        timer.Start();
                    }
                    else
                    {
                        AnnounceTimer timer = new AnnounceTimer(expriationMs, announce);
                        timer.AutoReset = false;
                        timer.Elapsed  += new ElapsedEventHandler(this.OnTimedEvent);
                        this.deviceMap.Add(path, timer);
                        timer.Start();
                        if (this.HandleNewDevice != null)
                        {
                            NewDeviceEventArgs newDeviceEvent = new NewDeviceEventArgs();
                            newDeviceEvent.Announce = announce;
                            this.HandleNewDevice(this, newDeviceEvent);
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            AnnounceTimer timer = (AnnounceTimer)source;

            timer.Stop();
            string path = timer.Announce.Path;

            lock (this.deviceMap)
            {
                this.deviceMap.Remove(path);
            }

            if (this.HandleRemoveDevice != null)
            {
                RemoveDeviceEventArgs removeDeviceEvent = new RemoveDeviceEventArgs();
                removeDeviceEvent.Announce = timer.Announce;
                this.HandleRemoveDevice(this, removeDeviceEvent);
            }
        }
Esempio n. 3
0
        public void Close()
        {
            lock (this.deviceMap)
            {
                this.stopped = true;
                var keysToRemove = new List <string>();
                foreach (KeyValuePair <string, AnnounceTimer> entry in this.deviceMap)
                {
                    AnnounceTimer timer = this.deviceMap[entry.Key];
                    timer.Stop();
                    timer.Close();
                    keysToRemove.Add(entry.Key);
                }

                foreach (var key in keysToRemove)
                {
                    this.deviceMap.Remove(key);
                }
            }
        }