Example #1
0
        private void RequestAnswerer_UpdateList()
        {
            RequestAnswerer_ListBox.Enabled = RequestAnswerer_Listener.IsActive;

            PeerConnection[] l1, l2;

            l1 = RequestAnswerer_Listener.GetPendingRequests();
            List<PeerConnection> l1l = new List<PeerConnection>(l1);
            ListBox.ObjectCollection l2r = RequestAnswerer_ListBox.Items;
            l2 = new PeerConnection[l2r.Count];

            // Copy l2r to l2.
            for (int i = 0; i < l2r.Count; i++)
                l2[i] = (PeerConnection)l2r[i];

            // Remove
            foreach (PeerConnection item in l2)
                if (!l1l.Contains(item))
                    l2r.Remove(item);

            // Add
            for (int i = 0; i < l1l.Count; i++)
            {
                PeerConnection l1o = l1[i];
                PeerConnection l2o = i <= l2.GetUpperBound(0) ? l2[i] : null;
                if (l1o.GreetingReceived && (l2o == null || l1o != l2o))
                {
                    l2r.Add(l1o);
                    if (i == l1l.Count - 1)
                        RequestAnswerer_ListBox.SelectedItem = l1o;
                }
            }
        }