/// <summary>
        ///
        /// </summary>
        private void UpdateAvailability()
        {
            // Add new states.
            foreach (ManifestBlockListState State in Peer.BlockState.States)
            {
                if (State.BlockState.AreAllSet(false))
                {
                    continue;
                }

                if (!Panels.ContainsKey(State.Id.ToString()))
                {
                    ManifestAvailabilityPanel Panel = new ManifestAvailabilityPanel();
                    Panel.Dock           = DockStyle.Top;
                    Panel.BlockListState = State;
                    Controls.Add(Panel);

                    Panels.Add(State.Id.ToString(), Panel);
                }
            }

            // Removed states.
            string[] Keys = Panels.Keys.ToArray <string>();
            for (int i = 0; i < Keys.Length; i++)
            {
                ManifestAvailabilityPanel Panel = Panels[Keys[i]];

                bool Exists = false;
                foreach (ManifestBlockListState State in Peer.BlockState.States)
                {
                    if (State.BlockState.AreAllSet(false))
                    {
                        continue;
                    }

                    if (Panel.BlockListState.Id == State.Id)
                    {
                        Exists = true;
                        break;
                    }
                }

                if (!Exists)
                {
                    Controls.Remove(Panel);
                    Panels.Remove(Keys[i]);
                    i--;
                }
            }

            // Update the availability state.
            foreach (var Val in Panels)
            {
                Val.Value.UpdateState();
            }
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        private void UpdateAvailability()
        {
            // Get all current peers with blocks.
            Peer[] AllPeers = Program.NetClient.AllPeers;

            List <Peer> RelevantPeers = new List <Peer>();

            foreach (Peer Peer in AllPeers)
            {
                if (Peer.Connection.IsReadyForData && Peer.Connection.Address != null)
                {
                    ManifestBlockListState State = Peer.BlockState.GetStateById(Download.ActiveManifestId);
                    if (State != null && !State.BlockState.AreAllSet(false))
                    {
                        RelevantPeers.Add(Peer);
                    }
                }
            }

            // Add new states.
            foreach (Peer Peer in RelevantPeers)
            {
                string Key = Peer.Connection.Address.Address.ToString();
                if (!Panels.ContainsKey(Key))
                {
                    ManifestAvailabilityPanel Panel = new ManifestAvailabilityPanel();
                    Panel.Dock           = DockStyle.Top;
                    Panel.BlockListState = Peer.BlockState.GetStateById(Download.ActiveManifestId);
                    Panel.NameOverride   = Peer.Connection.Handshake.Username;
                    Controls.Add(Panel);

                    Panels.Add(Key, Panel);
                }
            }

            // Removed states.
            string[] Keys = Panels.Keys.ToArray <string>();
            for (int i = 0; i < Keys.Length; i++)
            {
                ManifestAvailabilityPanel Panel = Panels[Keys[i]];

                bool Exists = false;
                foreach (Peer Peer in RelevantPeers)
                {
                    string Key = Peer.Connection.Address.Address.ToString();
                    if (Key == Keys[i])
                    {
                        Exists = true;
                        break;
                    }
                }

                if (!Exists)
                {
                    Controls.Remove(Panel);
                    Panels.Remove(Keys[i]);
                    Keys = Panels.Keys.ToArray <string>();
                    i--;
                }
            }

            // Update the availability state.
            foreach (var Val in Panels)
            {
                Val.Value.UpdateState();
            }
        }