Пример #1
0
        private void Initialize()
        {
            new List <ComboBox>()
            {
                cmbUploadRate, cmbUploadBurst, cmbDownloadRate, cmbDownloadBurst
            }.ForEach(x => x.DataSource = Enum.GetValues(typeof(BitByteUnit)));
            cmbUploadRate.SelectedItem = cmbUploadBurst.SelectedItem = cmbDownloadRate.SelectedItem = cmbDownloadBurst.SelectedItem = BitByteUnit.KBit;

            if (Hosts.All(x => x.Status != Host.HostStatus.Free))
            {
                if (Hosts.All(x => x.LimitRule.IsUploadLimited))
                {
                    tglUpload.Checked = true;

                    if (Hosts.All(x => Hosts.First().LimitRule.UploadRate == x.LimitRule.UploadRate))
                    {
                        var rate = NetworkUtilities.BreakDownBitRate(Hosts.First().LimitRule.UploadRate.Value, out BitByteUnit unit);

                        tbUploadRate.Text          = rate.ToString();
                        cmbUploadRate.SelectedItem = unit;
                    }

                    if (Hosts.First().LimitRule.UploadBurst != null && Hosts.All(x => Hosts.First().LimitRule.UploadBurst == x.LimitRule.UploadBurst))
                    {
                        var burst = NetworkUtilities.BreakDownBitRate(Hosts.First().LimitRule.UploadBurst.Value, out BitByteUnit unit);

                        tbUploadBurst.Text          = burst.ToString();
                        cmbUploadBurst.SelectedItem = unit;
                        cbUploadBurst.Checked       = true;
                    }
                }

                if (Hosts.All(x => x.LimitRule.IsDownloadLimited))
                {
                    tglDownload.Checked = true;

                    if (Hosts.All(x => Hosts.First().LimitRule.DownloadRate == x.LimitRule.DownloadRate))
                    {
                        var rate = NetworkUtilities.BreakDownBitRate(Hosts.First().LimitRule.DownloadRate.Value, out BitByteUnit unit);

                        tbDownloadRate.Text          = rate.ToString();
                        cmbDownloadRate.SelectedItem = unit;
                    }

                    if (Hosts.First().LimitRule.DownloadBurst != null && Hosts.All(x => Hosts.First().LimitRule.DownloadBurst == x.LimitRule.DownloadBurst))
                    {
                        var burst = NetworkUtilities.BreakDownBitRate(Hosts.First().LimitRule.DownloadBurst.Value, out BitByteUnit unit);

                        tbDownloadBurst.Text          = burst.ToString();
                        cmbDownloadBurst.SelectedItem = unit;
                        cbDownloadBurst.Checked       = true;
                    }
                }
            }
        }