Ejemplo n.º 1
0
        private string ParseAndToString(string ipRange)
        {
            IpRange result;

            if (IpRange.TryParse(ipRange, out result))
            {
                return(result.ToString());
            }

            return("");
        }
Ejemplo n.º 2
0
        public ByteBlock this[ushort lid]
        {
            get { return(new IpRange(this.StartAddressColumn[lid], this.EndAddressColumn[lid]).ToString()); }
            set
            {
                IpRange result;
                IpRange.TryParse(value.ToString(), out result);

                this.StartAddressColumn[lid] = result.StartInclusive;
                this.EndAddressColumn[lid]   = result.EndInclusive;
            }
        }
Ejemplo n.º 3
0
        public void TryWhere(Operator op, ByteBlock value, ShortSet result, ExecutionDetails details)
        {
            // Convert the value to an IP Range. Error if not.
            IpRange valueRange;

            if (!IpRange.TryParse(value.ToString(), out valueRange))
            {
                details.AddError(ExecutionDetails.UnableToConvertType, value, this.Name, "IP Range");
                return;
            }

            if (op == Operator.Matches)
            {
                // Matches finds rows which overlap the passed range.

                // Get rows which *don't overlap* because the start address is after the range being searched for
                this.StartAddressColumn.TryWhere(Operator.GreaterThan, valueRange.EndInclusive, result, details);

                // Add rows which *don't overlap* because the end address is before the range being searched for
                this.EndAddressColumn.TryWhere(Operator.LessThan, valueRange.StartInclusive, result, details);

                // Negate to find the set which *do* overlap
                result.Not();
            }
            else if (op == Operator.Equals || op == Operator.MatchesExact || op == Operator.NotEquals)
            {
                // Equals and MatchExact find rows which exactly equal the range being searched for

                // Find rows with the wrong start
                this.StartAddressColumn.TryWhere(Operator.NotEquals, valueRange.StartInclusive, result, details);

                // Add rows the wrong end
                this.EndAddressColumn.TryWhere(Operator.NotEquals, valueRange.EndInclusive, result, details);

                // Negate to find the set which are equal (both start and end match)
                if (op != Operator.NotEquals)
                {
                    result.Not();
                }
            }
            else if (op == Operator.LessThan)
            {
                // Find rows which end before the start of the search range
                this.EndAddressColumn.TryWhere(Operator.LessThan, valueRange.StartInclusive, result, details);
            }
            else if (op == Operator.GreaterThan)
            {
                // Find rows start after the end of the search range
                this.StartAddressColumn.TryWhere(Operator.GreaterThan, valueRange.EndInclusive, result, details);
            }
            else if (op == Operator.LessThanOrEqual)
            {
                // Find rows which end before the end of the search range
                this.EndAddressColumn.TryWhere(Operator.LessThanOrEqual, valueRange.EndInclusive, result, details);
            }
            else if (op == Operator.GreaterThanOrEqual)
            {
                // Find rows which start after the start of the search range
                this.StartAddressColumn.TryWhere(Operator.GreaterThanOrEqual, valueRange.StartInclusive, result, details);
            }
            else
            {
                details.AddError(ExecutionDetails.ColumnDoesNotSupportOperator, op, this.Name);
            }
        }