示例#1
0
        private void vectorEncodeButton_Click(object sender, EventArgs e)
        {
            if (!Regex.IsMatch(mVectorTextBox.Text, "^[0-9]{1,}$"))
            {
                mLengthVectorLabel.Text = $"m should be a numeric value";
                return;
            }

            _mVector = int.Parse(mVectorTextBox.Text);

            mLengthVectorLabel.Text = $"Expected vector length is {Vector.GetExpectedVectorLength(_mVector)}";

            this.Refresh();

            if (vectorTextBox.Text.Length != Vector.GetExpectedVectorLength(_mVector))
            {
                vectorLengthErrorLabel.Text = $"Length of vector to encode should be {Vector.GetExpectedVectorLength(_mVector)}." +
                                              $" Actual length is {vectorTextBox.Text.Length}";
                return;
            }

            if (!Regex.IsMatch(vectorTextBox.Text, "^[0-1]{1,}$"))
            {
                vectorLengthErrorLabel.Text = $"Vector should contain 0s and 1s";
                return;
            }

            vectorLengthErrorLabel.Text = "";

            _encodedVector = _vectorHelpers.EncodeVector(vectorTextBox.Text, _mVector);

            encodedVectorLabel.Visible   = true;
            encodedVectorText.Visible    = true;
            encodedVectorText.Text       = _encodedVector.ToString();
            vectorErrorRateLabel.Visible = true;
            vectorErrorRate.Visible      = true;
            vectorErrorRate.Text         = "0.0";
            vectorSendButton.Visible     = true;
        }