Beispiel #1
0
 public void HandleEvent(object sender, AnnounceEventArgs args)
 {
     if (args != null)
     {
         Announce announce = args.Announce;
         this.ArmTimer(announce);
     }
 }
Beispiel #2
0
        public bool Equals(Announce other)
        {
            if (object.ReferenceEquals(other, null))
            {
                return(false);
            }

            return(string.Compare(this.JsonString, other.JsonString, StringComparison.Ordinal) == 0);
        }
Beispiel #3
0
        internal void Add(string announceString, Announce announce)
        {
            string path = announce.Path;
            string lastAnnounceString;

            if (this.lastDeviceAnnounceString.TryGetValue(path, out lastAnnounceString))
            {
                this.parsedMessages.Remove(lastAnnounceString);
                this.lastDeviceAnnounceString.Remove(path);
            }

            this.parsedMessages.Add(announceString, announce);
            this.lastDeviceAnnounceString.Add(path, announceString);
        }
Beispiel #4
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);
                        }
                    }
                }
            }
        }
        public void HandleEvent(object sender, MulticastMessageEventArgs args)
        {
            if ((this.HandleMessage != null) && (args != null))
            {
                string           jsonString = args.JsonString;
                NetworkInterface incomingIF = args.IncomingInterface;

                if (!string.IsNullOrEmpty(jsonString))
                {
                    Announce announce = this.cache.Get(jsonString);
                    if (announce == null)
                    {
                        using (MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)))
                        {
                            try
                            {
                                announce = (Announce)this.deserializer.ReadObject(ms);
                                if (MandatoryKeysPresent(announce))
                                {
                                    announce.JsonString = jsonString;
                                    announce.IdentifyCommunicationPath(incomingIF);
                                    this.cache.Add(jsonString, announce);
                                    this.eventArgs.Announce = announce;
                                    this.HandleMessage(this, this.eventArgs);
                                }
                            }
                            catch (SerializationException)
                            {
                                return;
                            }
                        }
                    }
                    else
                    {
                        this.eventArgs.Announce = announce;
                        this.HandleMessage(this, this.eventArgs);
                    }
                }
            }
        }
Beispiel #6
0
 internal AnnounceTimer(double expire, Announce announce)
     : base(expire)
 {
     this.Announce = announce;
 }
Beispiel #7
0
 private int GetExpirationMilliSeconds(Announce announce)
 {
     return(announce.Parameters.Expiration * 1000);
 }
 private static bool MandatoryKeysPresent(Announce announce)
 {
     return(KeysInAnnounceParamsPresent(announce.Parameters));
 }