Exemplo n.º 1
0
        private void Callback_FleetStateUpdate(FleetStateDto fleetState)
        {
            FleetState = fleetState;

            lock (kingpinStateMailboxes)
            {
                foreach (IKingpinState kingpinState in fleetState.KingpinStates)
                {
                    KingpinStateMailbox mailbox = kingpinStateMailboxes.FirstOrDefault(e => e.Key.Equals(kingpinState.IPAddress));

                    if (mailbox != null)
                    {
                        mailbox.Update(kingpinState);
                    }
                    else
                    {
                        KingpinStateMailbox mailBox = new KingpinStateMailbox(kingpinState.IPAddress, kingpinState);

                        kingpinStateMailboxes.Add(mailBox);
                        OnAdded(mailBox);
                    }
                }

                IEnumerable <IPAddress> activeIP = fleetState.KingpinStates.Select(e => e.IPAddress);
                IEnumerable <IPAddress> deadIP   = kingpinStateMailboxes.Select(e => e.Key).Except(activeIP).ToList();

                foreach (IPAddress ipAddress in deadIP)
                {
                    KingpinStateMailbox deadMailBox = kingpinStateMailboxes.First(e => e.Key == ipAddress);
                    kingpinStateMailboxes.Remove(deadMailBox);

                    OnRemoved(deadMailBox);
                }
            }
        }
Exemplo n.º 2
0
        private void OnRemoved(KingpinStateMailbox kingpinStateMailbox)
        {
            Action <KingpinStateMailbox> handlers = Removed;

            handlers?
            .GetInvocationList()
            .Cast <Action <KingpinStateMailbox> >()
            .ForEach(e => e.BeginInvoke(kingpinStateMailbox, null, null));
        }