コード例 #1
0
        public static bool AddressInRange(string address, string firstRangeAddress, uint lastOctet)
        {
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (firstRangeAddress == null)
            {
                throw new ArgumentNullException(nameof(firstRangeAddress));
            }

            var addressIsValid    = AddressValidationRule.Validate(address);
            var rangeStartIsValid = AddressValidationRule.Validate(firstRangeAddress);
            var lastOctetValid    = lastOctet > 0 && lastOctet < 255;

            if (!addressIsValid || !rangeStartIsValid || !lastOctetValid)
            {
                return(false);
            }

            var addressOctets = address.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var startOctets   = firstRangeAddress.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var firstOctetMatch      = addressOctets[0] == startOctets[0];
            var secondOctetMatch     = addressOctets[1] == startOctets[1];
            var thirdOctetMatch      = addressOctets[2] == startOctets[2];
            var finalOctet           = uint.Parse(addressOctets[3], CultureInfo.CurrentCulture);
            var finalStartRangeOcted = uint.Parse(startOctets[3], CultureInfo.CurrentCulture);
            var lastOctedInRange     = finalOctet >= finalStartRangeOcted && finalOctet <= lastOctet;

            return(firstOctetMatch && secondOctetMatch && thirdOctetMatch && lastOctedInRange);
        }
コード例 #2
0
        public static bool AddressInRange(string address, string firstRangeAddress, uint lastOctet)
        {
            var validationRule = new AddressValidationRule();

            var addressIsValid    = validationRule.Validate(address);
            var rangeStartIsValid = validationRule.Validate(firstRangeAddress);
            var lastOctetValid    = lastOctet > 0 && lastOctet < 255;

            if (!addressIsValid || !rangeStartIsValid || !lastOctetValid)
            {
                return(false);
            }

            var addressOctets = address.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            var startOctets   = firstRangeAddress.Split(".".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

            var firstOctetMatch      = addressOctets[0] == startOctets[0];
            var secondOctetMatch     = addressOctets[1] == startOctets[1];
            var thirdOctetMatch      = addressOctets[2] == startOctets[2];
            var finalOctet           = uint.Parse(addressOctets[3]);
            var finalStartRangeOcted = uint.Parse(startOctets[3]);
            var lastOctedInRange     = finalOctet >= finalStartRangeOcted && finalOctet <= lastOctet;

            return(firstOctetMatch & secondOctetMatch && thirdOctetMatch && lastOctedInRange);
        }
コード例 #3
0
        public void IsInvalidRegex(string pattern)
        {
            //Arrange & Act
            bool result = AddressValidationRule.IsCorrectRegex(pattern);

            //Assert
            result.Should().BeFalse();
        }
コード例 #4
0
        public void IsInvalidAddress(string address)
        {
            //Arrange & Act
            bool result = AddressValidationRule.IsCorrectAddress(address);

            //Assert
            result.Should().BeFalse();
        }
コード例 #5
0
 public WhitelistManagementControl(IWhitelistManagementPresenter presenter)
 {
     _validationRule = new AddressValidationRule();
     _presenter      = presenter;
     InitializeComponent();
     _presenter.Attach(this);
     _presenter.Load();
     addressAddButton.Enabled = false;
 }
コード例 #6
0
        public RangeManagementControl(RangeManagementViewModel viewModel)
        {
            _addressValidationRule = new AddressValidationRule();
            _lastOctetValidator    = new LastOctetValidator();
            _viewModel             = viewModel;
            InitializeComponent();
            baseIpTextBox.Text = _viewModel.BaseIp;

            if (_viewModel.LastOctetMax > 0)
            {
                lastOctetTextBox.Text = _viewModel.LastOctetMax.ToString();
            }
        }
コード例 #7
0
        private void BaseIpTextBoxTextChanged(object sender, EventArgs e)
        {
            var address = baseIpTextBox.Text;

            if (AddressValidationRule.Validate(address))
            {
                _viewModel.BaseIp       = address;
                baseIpTextBox.BackColor = DefaultBackColor;
            }
            else
            {
                baseIpTextBox.BackColor = Color.Red;
            }
        }
コード例 #8
0
        private void NewAddressTextBoxTextChanged(object sender, EventArgs e)
        {
            var input = newAddressTextBox.Text;

            if (string.IsNullOrWhiteSpace(input))
            {
                addressAddButton.Enabled    = false;
                newAddressTextBox.BackColor = DefaultBackColor;
                return;
            }

            if (AddressValidationRule.Validate(input))
            {
                addressAddButton.Enabled    = true;
                newAddressTextBox.BackColor = Color.LawnGreen;
            }
            else
            {
                newAddressTextBox.BackColor = Color.Red;
                addressAddButton.Enabled    = false;
            }
        }