Example #1
0
        private LimitRule ParseLimitInformation()
        {
            var errorMessage = new Action <string, string>((title, msg) => MessageBox.Show(msg, title, MessageBoxButtons.OK, MessageBoxIcon.Error));
            var rule         = LimitRule.Free;

            if (tglUpload.Checked)
            {
                if (!double.TryParse(tbUploadRate.Text, out double rate))
                {
                    errorMessage("Value Error", "Invalid upload rate.");
                    return(null);
                }

                rule.UploadRate = NetworkUtilities.BrokenDownRateToBitRate(rate, (BitByteUnit)Enum.Parse(typeof(BitByteUnit), cmbUploadRate.SelectedItem.ToString()));

                if (cbUploadBurst.Checked)
                {
                    if (!double.TryParse(tbUploadBurst.Text, out double burst))
                    {
                        errorMessage("Value Error", "Invalid upload burst.");
                        return(null);
                    }

                    rule.UploadBurst = NetworkUtilities.BrokenDownRateToBitRate(burst, (BitByteUnit)Enum.Parse(typeof(BitByteUnit), cmbUploadBurst.SelectedItem.ToString()));
                }
            }

            if (tglDownload.Checked)
            {
                if (!double.TryParse(tbDownloadRate.Text, out double rate))
                {
                    errorMessage("Value Error", "Invalid download rate.");
                    return(null);
                }

                rule.DownloadRate = NetworkUtilities.BrokenDownRateToBitRate(rate, (BitByteUnit)Enum.Parse(typeof(BitByteUnit), cmbDownloadRate.SelectedItem.ToString()));

                if (cbDownloadBurst.Checked)
                {
                    if (!double.TryParse(tbDownloadBurst.Text, out double burst))
                    {
                        errorMessage("Value Error", "Invalid download burst.");
                        return(null);
                    }

                    rule.DownloadBurst = NetworkUtilities.BrokenDownRateToBitRate(burst, (BitByteUnit)Enum.Parse(typeof(BitByteUnit), cmbDownloadBurst.SelectedItem.ToString()));
                }
            }

            return(rule);
        }