Beispiel #1
0
        private static bool InternalTryParseCIDR(string expression, int sep, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            int length = expression.Length;

            if (sep == 0 || expression[sep] != '/')
            {
                return(false);
            }
            IPvxAddress baseAddress;

            if (!IPvxAddress.TryParse(expression.Substring(0, sep), out baseAddress))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(0, sep));
                return(false);
            }
            short cidrLength = 0;

            if (!short.TryParse(expression.Substring(sep + 1, length - sep - 1), out cidrLength))
            {
                range.exceptionMessage = DataStrings.InvalidCIDRLength(expression.Substring(sep + 1, length - sep - 1));
                return(false);
            }
            if (!range.IsValidCIDRLength(cidrLength, baseAddress.AddressFamily))
            {
                return(false);
            }
            if (!range.SetAddressesFromCIDR(baseAddress, cidrLength))
            {
                return(false);
            }
            range.format = IPRange.Format.CIDR;
            return(true);
        }
Beispiel #2
0
        private static bool InternalTryParseLoHi(string expression, int sep, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            int length = expression.Length;

            if (sep == 0 || expression[sep] != '-')
            {
                return(false);
            }
            IPvxAddress start;

            if (!IPvxAddress.TryParse(expression.Substring(0, sep), out start))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(0, sep));
                return(false);
            }
            IPvxAddress end;

            if (!IPvxAddress.TryParse(expression.Substring(sep + 1, length - sep - 1), out end))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(sep + 1, length - sep - 1));
                return(false);
            }
            range.SetAddresses(start, end);
            if (!range.ValidateAddressFamily())
            {
                return(false);
            }
            range.format = IPRange.Format.LoHi;
            return(true);
        }
Beispiel #3
0
        protected IPRange(IPAddress networkAddress, short cidrLength)
        {
            short num = cidrLength;

            if (!this.IsValidCIDRLength(cidrLength, networkAddress.AddressFamily))
            {
                throw new ArgumentException(this.exceptionMessage);
            }
            if (networkAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                num += 96;
            }
            IPvxAddress pvxAddress = new IPvxAddress(networkAddress);

            if (num == 128)
            {
                this.SetAddresses(pvxAddress, pvxAddress);
                this.format = IPRange.Format.SingleAddress;
            }
            else
            {
                if (!this.SetAddressesFromCIDR(pvxAddress, cidrLength))
                {
                    throw new ArgumentException(this.exceptionMessage);
                }
                this.format = IPRange.Format.CIDR;
            }
            if (!this.ValidateRange())
            {
                throw new ArgumentOutOfRangeException(this.exceptionMessage);
            }
        }
        public override PropertyConstraintViolationError Validate(object value, PropertyDefinition propertyDefinition, IPropertyBag propertyBag)
        {
            IPvxAddress pvxAddress = new IPvxAddress(0UL, this.maxIPRange);
            IPRange     iprange    = value as IPRange;

            if (iprange != null && pvxAddress.CompareTo(iprange.Size) < 0)
            {
                return(new PropertyConstraintViolationError(DataStrings.ConstraintViolationIpRangeNotAllowed(iprange.ToString(), this.maxIPRange), propertyDefinition, value, this));
            }
            return(null);
        }
Beispiel #5
0
        private static bool InternalTryParseSingleIPAddress(string expression, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            IPvxAddress pvxAddress;

            if (!IPvxAddress.TryParse(expression, out pvxAddress))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression);
                return(false);
            }
            range.SetAddresses(pvxAddress, pvxAddress);
            range.format = IPRange.Format.SingleAddress;
            return(true);
        }
Beispiel #6
0
 public IPRange(IPvxAddress startAddress, IPvxAddress endAddress, IPRange.Format format)
 {
     this.SetAddresses(startAddress, endAddress);
     if (!this.ValidateAddressFamily())
     {
         throw new FormatException(this.exceptionMessage);
     }
     if (!this.ValidateRange())
     {
         throw new ArgumentOutOfRangeException(this.exceptionMessage);
     }
     if (!this.IsValidFormat(format))
     {
         throw new FormatException(this.exceptionMessage);
     }
     this.format = format;
 }
Beispiel #7
0
        private bool SetAddressesFromCIDR(IPvxAddress baseAddress, short cidrLength)
        {
            if (!this.IsValidCIDRLength(cidrLength, baseAddress.AddressFamily))
            {
                return(false);
            }
            if (baseAddress.AddressFamily == AddressFamily.InterNetwork)
            {
                cidrLength += 96;
            }
            IPvxAddress pvxAddress  = ~IPvxAddress.Zero >> (int)cidrLength;
            IPvxAddress pvxAddress2 = baseAddress;

            pvxAddress2 |= pvxAddress;
            baseAddress &= ~pvxAddress;
            this.SetAddresses(baseAddress, pvxAddress2);
            return(true);
        }
Beispiel #8
0
        protected virtual object ReadRawValue(StreamPropertyType propId)
        {
            if (propId <= (StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List))
            {
                switch (propId)
                {
                case StreamPropertyType.Null:
                    return(null);

                case StreamPropertyType.Bool:
                    this.Read(this.buffer, 1);
                    return(this.buffer[0] == 1);

                case StreamPropertyType.Byte:
                    this.Read(this.buffer, 1);
                    return(this.buffer[0]);

                case StreamPropertyType.SByte:
                    this.Read(this.buffer, 1);
                    return((sbyte)this.buffer[0]);

                case StreamPropertyType.Int16:
                    this.Read(this.buffer, 2);
                    return(BitConverter.ToInt16(this.buffer, 0));

                case StreamPropertyType.UInt16:
                    this.Read(this.buffer, 2);
                    return(BitConverter.ToUInt16(this.buffer, 0));

                case StreamPropertyType.Int32:
                    this.Read(this.buffer, 4);
                    return(BitConverter.ToInt32(this.buffer, 0));

                case StreamPropertyType.UInt32:
                    this.Read(this.buffer, 4);
                    return(BitConverter.ToUInt32(this.buffer, 0));

                case StreamPropertyType.Int64:
                    this.Read(this.buffer, 8);
                    return(BitConverter.ToInt64(this.buffer, 0));

                case StreamPropertyType.UInt64:
                    this.Read(this.buffer, 8);
                    return(BitConverter.ToUInt64(this.buffer, 0));

                case StreamPropertyType.Single:
                    this.Read(this.buffer, 4);
                    return(BitConverter.ToSingle(this.buffer, 0));

                case StreamPropertyType.Double:
                    this.Read(this.buffer, 8);
                    return(BitConverter.ToDouble(this.buffer, 0));

                case StreamPropertyType.Decimal:
                {
                    this.Read(this.buffer, 16);
                    int[] array = new int[4];
                    for (int i = 0; i < 4; i++)
                    {
                        array[i] = BitConverter.ToInt32(this.buffer, i * 4);
                    }
                    return(new decimal(array));
                }

                case StreamPropertyType.Char:
                {
                    char[] array2 = (char[])this.ReadRawValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array);
                    if (array2 == null || array2.Length != 1)
                    {
                        throw new FormatException("Extended property stream. Invalid character content.");
                    }
                    return(array2[0]);
                }

                case StreamPropertyType.String:
                {
                    this.Read(this.buffer, 4);
                    int num = BitConverter.ToInt32(this.buffer, 0);
                    if (num == 0)
                    {
                        return(string.Empty);
                    }
                    if (num > this.buffer.Length)
                    {
                        byte[] bytes = new byte[num];
                        this.Read(bytes, num);
                        return(Encoding.UTF8.GetString(bytes, 0, num));
                    }
                    this.Read(this.buffer, num);
                    return(Encoding.UTF8.GetString(this.buffer, 0, num));
                }

                case StreamPropertyType.DateTime:
                {
                    this.Read(this.buffer, 8);
                    long fileTime = BitConverter.ToInt64(this.buffer, 0);
                    return(DateTime.FromFileTimeUtc(fileTime));
                }

                case StreamPropertyType.Guid:
                    this.Read(this.buffer, 16);
                    return(ExBitConverter.ReadGuid(this.buffer, 0));

                case StreamPropertyType.IPAddress:
                {
                    this.Read(this.buffer, 16);
                    IPvxAddress address = new IPvxAddress(BitConverter.ToUInt64(this.buffer, 8), BitConverter.ToUInt64(this.buffer, 0));
                    return(address);
                }

                case StreamPropertyType.IPEndPoint:
                {
                    IPAddress ipaddress = (IPAddress)this.ReadRawValue(StreamPropertyType.IPAddress);
                    ushort    num2      = (ushort)this.ReadRawValue(StreamPropertyType.UInt16);
                    if (ipaddress != IPAddress.None || num2 != 0)
                    {
                        return(new IPEndPoint(ipaddress, (int)num2));
                    }
                    return(null);
                }

                case StreamPropertyType.RoutingAddress:
                case StreamPropertyType.ADObjectId:
                case StreamPropertyType.RecipientType:
                case StreamPropertyType.ADObjectIdUTF8:
                case StreamPropertyType.ADObjectIdWithString:
                case StreamPropertyType.ProxyAddress:
                    break;

                default:
                    switch (propId)
                    {
                    case StreamPropertyType.Bool | StreamPropertyType.Array:
                    {
                        bool[] result;
                        this.ReadArray <bool>(propId, out result);
                        return(result);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array:
                    {
                        byte[] result2;
                        this.ReadArray <byte>(propId, out result2);
                        return(result2);
                    }

                    case StreamPropertyType.SByte | StreamPropertyType.Array:
                    {
                        sbyte[] result3;
                        this.ReadArray <sbyte>(propId, out result3);
                        return(result3);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.Array:
                    {
                        short[] result4;
                        this.ReadArray <short>(propId, out result4);
                        return(result4);
                    }

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array:
                    {
                        ushort[] result5;
                        this.ReadArray <ushort>(propId, out result5);
                        return(result5);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array:
                    {
                        int[] result6;
                        this.ReadArray <int>(propId, out result6);
                        return(result6);
                    }

                    case StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        uint[] result7;
                        this.ReadArray <uint>(propId, out result7);
                        return(result7);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        long[] result8;
                        this.ReadArray <long>(propId, out result8);
                        return(result8);
                    }

                    case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        ulong[] result9;
                        this.ReadArray <ulong>(propId, out result9);
                        return(result9);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        float[] result10;
                        this.ReadArray <float>(propId, out result10);
                        return(result10);
                    }

                    case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        double[] result11;
                        this.ReadArray <double>(propId, out result11);
                        return(result11);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        decimal[] result12;
                        this.ReadArray <decimal>(propId, out result12);
                        return(result12);
                    }

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        this.Read(this.buffer, 4);
                        int num3 = BitConverter.ToInt32(this.buffer, 0);
                        if (num3 == 0)
                        {
                            return(new char[0]);
                        }
                        if (num3 > this.buffer.Length)
                        {
                            byte[] bytes2 = new byte[num3];
                            this.Read(bytes2, num3);
                            return(Encoding.UTF8.GetChars(bytes2));
                        }
                        this.Read(this.buffer, num3);
                        return(Encoding.UTF8.GetChars(this.buffer, 0, num3));
                    }

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                    {
                        string[] result13;
                        this.ReadArray <string>(propId, out result13);
                        return(result13);
                    }

                    case StreamPropertyType.DateTime | StreamPropertyType.Array:
                    {
                        DateTime[] result14;
                        this.ReadArray <DateTime>(propId, out result14);
                        return(result14);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    {
                        Guid[] result15;
                        this.ReadArray <Guid>(propId, out result15);
                        return(result15);
                    }

                    case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    {
                        IPAddress[] result16;
                        this.ReadArray <IPAddress>(propId, out result16);
                        return(result16);
                    }

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    {
                        IPEndPoint[] result17;
                        this.ReadArray <IPEndPoint>(propId, out result17);
                        return(result17);
                    }

                    case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        break;

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        goto IL_8D3;

                    default:
                        switch (propId)
                        {
                        case StreamPropertyType.Bool | StreamPropertyType.List:
                        {
                            List <bool> result18;
                            this.ReadList <bool>(propId, out result18);
                            return(result18);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.List:
                        {
                            List <byte> result19;
                            this.ReadList <byte>(propId, out result19);
                            return(result19);
                        }

                        case StreamPropertyType.SByte | StreamPropertyType.List:
                        {
                            List <sbyte> result20;
                            this.ReadList <sbyte>(propId, out result20);
                            return(result20);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.List:
                        {
                            List <short> result21;
                            this.ReadList <short>(propId, out result21);
                            return(result21);
                        }

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List:
                        {
                            List <ushort> result22;
                            this.ReadList <ushort>(propId, out result22);
                            return(result22);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List:
                        {
                            List <int> result23;
                            this.ReadList <int>(propId, out result23);
                            return(result23);
                        }

                        case StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <uint> result24;
                            this.ReadList <uint>(propId, out result24);
                            return(result24);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <long> result25;
                            this.ReadList <long>(propId, out result25);
                            return(result25);
                        }

                        case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <ulong> result26;
                            this.ReadList <ulong>(propId, out result26);
                            return(result26);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <float> result27;
                            this.ReadList <float>(propId, out result27);
                            return(result27);
                        }

                        case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <double> result28;
                            this.ReadList <double>(propId, out result28);
                            return(result28);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <decimal> result29;
                            this.ReadList <decimal>(propId, out result29);
                            return(result29);
                        }

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            this.Read(this.buffer, 4);
                            int num4 = BitConverter.ToInt32(this.buffer, 0);
                            if (num4 == 0)
                            {
                                return(new char[0]);
                            }
                            if (num4 > this.buffer.Length)
                            {
                                byte[] bytes3 = new byte[num4];
                                this.Read(bytes3, num4);
                                return(new List <char>(Encoding.UTF8.GetChars(bytes3)));
                            }
                            this.Read(this.buffer, num4);
                            return(new List <char>(Encoding.UTF8.GetChars(this.buffer, 0, num4)));
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            List <string> result30;
                            this.ReadList <string>(propId, out result30);
                            return(result30);
                        }

                        case StreamPropertyType.DateTime | StreamPropertyType.List:
                        {
                            List <DateTime> result31;
                            this.ReadList <DateTime>(propId, out result31);
                            return(result31);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.List:
                        {
                            List <Guid> result32;
                            this.ReadList <Guid>(propId, out result32);
                            return(result32);
                        }

                        case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List:
                        {
                            List <IPAddress> result33;
                            this.ReadList <IPAddress>(propId, out result33);
                            return(result33);
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List:
                        {
                            List <IPEndPoint> result34;
                            this.ReadList <IPEndPoint>(propId, out result34);
                            return(result34);
                        }

                        case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List:
                            break;

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                            goto IL_8D3;

                        default:
                            goto IL_8D3;
                        }
                        break;
                    }
                    break;
                }
            }
            else
            {
                if (propId == (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.List))
                {
                    List <byte[]> result35;
                    this.ReadList <byte[]>(propId, out result35);
                    return(result35);
                }
                switch (propId)
                {
                case StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty:
                {
                    List <bool> result36;
                    this.ReadMultiValuedProperty <bool>(propId, out result36);
                    return(result36);
                }

                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty:
                {
                    List <byte> result37;
                    this.ReadMultiValuedProperty <byte>(propId, out result37);
                    return(result37);
                }

                case StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                {
                    List <sbyte> result38;
                    this.ReadMultiValuedProperty <sbyte>(propId, out result38);
                    return(result38);
                }

                case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                {
                    List <short> result39;
                    this.ReadMultiValuedProperty <short>(propId, out result39);
                    return(result39);
                }

                case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                {
                    List <ushort> result40;
                    this.ReadMultiValuedProperty <ushort>(propId, out result40);
                    return(result40);
                }

                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                {
                    List <int> result41;
                    this.ReadMultiValuedProperty <int>(propId, out result41);
                    return(result41);
                }

                case StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <uint> result42;
                    this.ReadMultiValuedProperty <uint>(propId, out result42);
                    return(result42);
                }

                case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <long> result43;
                    this.ReadMultiValuedProperty <long>(propId, out result43);
                    return(result43);
                }

                case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <ulong> result44;
                    this.ReadMultiValuedProperty <ulong>(propId, out result44);
                    return(result44);
                }

                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <float> result45;
                    this.ReadMultiValuedProperty <float>(propId, out result45);
                    return(result45);
                }

                case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <double> result46;
                    this.ReadMultiValuedProperty <double>(propId, out result46);
                    return(result46);
                }

                case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <decimal> result47;
                    this.ReadMultiValuedProperty <decimal>(propId, out result47);
                    return(result47);
                }

                case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    this.Read(this.buffer, 4);
                    int num5 = BitConverter.ToInt32(this.buffer, 0);
                    if (num5 == 0)
                    {
                        return(new char[0]);
                    }
                    if (num5 > this.buffer.Length)
                    {
                        byte[] bytes4 = new byte[num5];
                        this.Read(bytes4, num5);
                        return(new List <char>(Encoding.UTF8.GetChars(bytes4)));
                    }
                    this.Read(this.buffer, num5);
                    return(new List <char>(Encoding.UTF8.GetChars(this.buffer, 0, num5)));
                }

                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                {
                    List <string> result48;
                    this.ReadMultiValuedProperty <string>(propId, out result48);
                    return(result48);
                }

                case StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                {
                    List <DateTime> result49;
                    this.ReadMultiValuedProperty <DateTime>(propId, out result49);
                    return(result49);
                }

                case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                {
                    List <Guid> result50;
                    this.ReadMultiValuedProperty <Guid>(propId, out result50);
                    return(result50);
                }

                case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                {
                    List <IPAddress> result51;
                    this.ReadMultiValuedProperty <IPAddress>(propId, out result51);
                    return(result51);
                }

                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                {
                    List <IPEndPoint> result52;
                    this.ReadMultiValuedProperty <IPEndPoint>(propId, out result52);
                    return(result52);
                }

                case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                    break;

                case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                    goto IL_8D3;

                default:
                {
                    if (propId != (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.MultiValuedProperty))
                    {
                        goto IL_8D3;
                    }
                    List <byte[]> result53;
                    this.ReadMultiValuedProperty <byte[]>(propId, out result53);
                    return(result53);
                }
                }
            }
            throw new InvalidOperationException(string.Format("The property type {0} is not supported by PropertyStreamReader, but may be supported by a subclass", propId));
IL_8D3:
            throw new FormatException("Invalid value data " + propId);
        }
        public static void WriteValue(StreamPropertyType propId, object value, byte[] buffer, ref int offset)
        {
            if (buffer == null || offset > buffer.Length)
            {
                throw new ArgumentException("buffer");
            }
            if (propId <= (StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List))
            {
                switch (propId)
                {
                case StreamPropertyType.Null:
                    return;

                case StreamPropertyType.Bool:
                    buffer[offset++] = (((bool)value) ? 1 : 0);
                    return;

                case StreamPropertyType.Byte:
                    buffer[offset++] = (byte)value;
                    return;

                case StreamPropertyType.SByte:
                {
                    sbyte b = (sbyte)value;
                    buffer[offset++] = (byte)b;
                    return;
                }

                case StreamPropertyType.Int16:
                    offset += ExBitConverter.Write((short)value, buffer, offset);
                    return;

                case StreamPropertyType.UInt16:
                    offset += ExBitConverter.Write((ushort)value, buffer, offset);
                    return;

                case StreamPropertyType.Int32:
                    offset += ExBitConverter.Write((int)value, buffer, offset);
                    return;

                case StreamPropertyType.UInt32:
                    offset += ExBitConverter.Write((uint)value, buffer, offset);
                    return;

                case StreamPropertyType.Int64:
                    offset += ExBitConverter.Write((long)value, buffer, offset);
                    return;

                case StreamPropertyType.UInt64:
                    offset += ExBitConverter.Write((ulong)value, buffer, offset);
                    return;

                case StreamPropertyType.Single:
                    offset += ExBitConverter.Write((float)value, buffer, offset);
                    return;

                case StreamPropertyType.Double:
                    offset += ExBitConverter.Write((double)value, buffer, offset);
                    return;

                case StreamPropertyType.Decimal:
                {
                    decimal d    = (decimal)value;
                    int[]   bits = decimal.GetBits(d);
                    for (int i = 0; i < bits.Length; i++)
                    {
                        offset += ExBitConverter.Write(bits[i], buffer, offset);
                    }
                    return;
                }

                case StreamPropertyType.Char:
                    value = new char[]
                    {
                        (char)value
                    };
                    break;

                case StreamPropertyType.String:
                {
                    int    num  = 0;
                    string text = (string)value;
                    if (!string.IsNullOrEmpty(text))
                    {
                        num = Encoding.UTF8.GetBytes(text, 0, text.Length, buffer, offset + 4);
                    }
                    offset += ExBitConverter.Write(num, buffer, offset);
                    offset += num;
                    return;
                }

                case StreamPropertyType.DateTime:
                {
                    DateTime dateTime = (DateTime)value;
                    offset += ExBitConverter.Write(dateTime.ToFileTimeUtc(), buffer, offset);
                    return;
                }

                case StreamPropertyType.Guid:
                    offset += ExBitConverter.Write((Guid)value, buffer, offset);
                    return;

                case StreamPropertyType.IPAddress:
                {
                    IPvxAddress pvxAddress = new IPvxAddress((value == null) ? IPAddress.None : ((IPAddress)value));
                    long        value2     = (long)((ulong)((uint)pvxAddress));
                    offset += ExBitConverter.Write(value2, buffer, offset);
                    value2  = (long)((ulong)((uint)(pvxAddress >> 64)));
                    offset += ExBitConverter.Write(value2, buffer, offset);
                    return;
                }

                case StreamPropertyType.IPEndPoint:
                {
                    if (value == null)
                    {
                        PropertyStreamWriter.WriteValue(StreamPropertyType.IPAddress, IPAddress.None, buffer, ref offset);
                        PropertyStreamWriter.WriteValue(StreamPropertyType.UInt16, 0, buffer, ref offset);
                        return;
                    }
                    IPEndPoint ipendPoint = (IPEndPoint)value;
                    PropertyStreamWriter.WriteValue(StreamPropertyType.IPAddress, ipendPoint.Address, buffer, ref offset);
                    PropertyStreamWriter.WriteValue(StreamPropertyType.UInt16, (ushort)ipendPoint.Port, buffer, ref offset);
                    return;
                }

                case StreamPropertyType.RoutingAddress:
                case StreamPropertyType.ADObjectId:
                case StreamPropertyType.RecipientType:
                case StreamPropertyType.ADObjectIdUTF8:
                case StreamPropertyType.ADObjectIdWithString:
                case StreamPropertyType.ProxyAddress:
                    goto IL_808;

                default:
                    switch (propId)
                    {
                    case StreamPropertyType.Bool | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <bool>(propId, (bool[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array:
                    {
                        byte[] array = (byte[])value;
                        offset += ExBitConverter.Write(array.Length, buffer, offset);
                        if (array.Length != 0)
                        {
                            Array.Copy(array, 0, buffer, offset, array.Length);
                            offset += array.Length;
                            return;
                        }
                        return;
                    }

                    case StreamPropertyType.SByte | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <sbyte>(propId, (sbyte[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <short>(propId, (short[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <ushort>(propId, (ushort[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <int>(propId, (int[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <uint>(propId, (uint[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <long>(propId, (long[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <ulong>(propId, (ulong[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <float>(propId, (float[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <double>(propId, (double[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <decimal>(propId, (decimal[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        break;

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <string>(propId, (string[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.DateTime | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <DateTime>(propId, (DateTime[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <Guid>(propId, (Guid[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <IPAddress>(propId, (IPAddress[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        PropertyStreamWriter.WriteArray <IPEndPoint>(propId, (IPEndPoint[])value, buffer, ref offset);
                        return;

                    case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array:
                    case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        goto IL_808;

                    case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.Array:
                        return;

                    default:
                        switch (propId)
                        {
                        case StreamPropertyType.Bool | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <bool>(propId, (List <bool>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <byte>(propId, (List <byte>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.SByte | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <sbyte>(propId, (List <sbyte>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <short>(propId, (List <short>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <ushort>(propId, (List <ushort>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <int>(propId, (List <int>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <uint>(propId, (List <uint>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <long>(propId, (List <long>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <ulong>(propId, (List <ulong>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <float>(propId, (List <float>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <double>(propId, (List <double>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <decimal>(propId, (List <decimal>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                        {
                            char[] value3 = (value != null) ? ((List <char>)value).ToArray() : null;
                            PropertyStreamWriter.WriteValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array, value3, buffer, ref offset);
                            return;
                        }

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <string>(propId, (List <string>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.DateTime | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <DateTime>(propId, (List <DateTime>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <Guid>(propId, (List <Guid>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <IPAddress>(propId, (List <IPAddress>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.List:
                            PropertyStreamWriter.WriteList <IPEndPoint>(propId, (List <IPEndPoint>)value, buffer, ref offset);
                            return;

                        case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List:
                        case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.List:
                            goto IL_808;

                        case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.List:
                            return;

                        default:
                            return;
                        }
                        break;
                    }
                    break;
                }
                int num2 = 0;
                if (value != null)
                {
                    char[] array2 = (char[])value;
                    if (array2.Length != 0)
                    {
                        num2 = Encoding.UTF8.GetBytes(array2, 0, array2.Length, buffer, offset + 4);
                    }
                }
                offset += ExBitConverter.Write(num2, buffer, offset);
                offset += num2;
                return;
            }
            if (propId == (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.List))
            {
                PropertyStreamWriter.WriteList <byte[]>(propId, (List <byte[]>)value, buffer, ref offset);
                return;
            }
            switch (propId)
            {
            case StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <bool>(propId, (MultiValuedProperty <bool>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <byte>(propId, (MultiValuedProperty <byte>)value, buffer, ref offset);
                return;

            case StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <sbyte>(propId, (MultiValuedProperty <sbyte>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <short>(propId, (MultiValuedProperty <short>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <ushort>(propId, (MultiValuedProperty <ushort>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <int>(propId, (MultiValuedProperty <int>)value, buffer, ref offset);
                return;

            case StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <uint>(propId, (MultiValuedProperty <uint>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <long>(propId, (MultiValuedProperty <long>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <ulong>(propId, (MultiValuedProperty <ulong>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <float>(propId, (MultiValuedProperty <float>)value, buffer, ref offset);
                return;

            case StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <double>(propId, (MultiValuedProperty <double>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <decimal>(propId, (MultiValuedProperty <decimal>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
            {
                char[] value4 = (value != null) ? ((MultiValuedProperty <char>)value).ToArray() : null;
                PropertyStreamWriter.WriteValue(StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.Array, value4, buffer, ref offset);
                return;
            }

            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.UInt32 | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <string>(propId, (MultiValuedProperty <string>)value, buffer, ref offset);
                return;

            case StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <DateTime>(propId, (MultiValuedProperty <DateTime>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <Guid>(propId, (MultiValuedProperty <Guid>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <IPAddress>(propId, (MultiValuedProperty <IPAddress>)value, buffer, ref offset);
                return;

            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                PropertyStreamWriter.WriteMultiValuedProperty <IPEndPoint>(propId, (MultiValuedProperty <IPEndPoint>)value, buffer, ref offset);
                return;

            case StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
            case StreamPropertyType.Null | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
            case StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
            case StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
            case StreamPropertyType.Null | StreamPropertyType.UInt32 | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                break;

            case StreamPropertyType.Bool | StreamPropertyType.SByte | StreamPropertyType.DateTime | StreamPropertyType.MultiValuedProperty:
                return;

            default:
                if (propId != (StreamPropertyType.Null | StreamPropertyType.Bool | StreamPropertyType.Array | StreamPropertyType.MultiValuedProperty))
                {
                    return;
                }
                PropertyStreamWriter.WriteMultiValuedProperty <byte[]>(propId, (MultiValuedProperty <byte[]>)value, buffer, ref offset);
                return;
            }
IL_808:
            throw new InvalidOperationException(string.Format("Dont know how to handle type {0}", propId));
        }
Beispiel #10
0
 public static int Compare(IPRangeRemote v1, IPRangeRemote v2)
 {
     return(IPvxAddress.Compare(v1.size, v2.size));
 }
Beispiel #11
0
 protected void SetAddresses(IPvxAddress start, IPvxAddress end)
 {
     this.startAddress = start;
     this.endAddress   = end;
 }
Beispiel #12
0
        private static bool InternalTryParseNetmask(string expression, int sep, ref IPRange range)
        {
            range.format = IPRange.Format.Invalid;
            int length = expression.Length;

            if (sep == 0 || expression[sep] != '(' || expression[length - 1] != ')')
            {
                return(false);
            }
            IPAddress ipaddress;

            if (!IPAddress.TryParse(expression.Substring(0, sep), out ipaddress))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(0, sep));
                return(false);
            }
            IPAddress ipaddress2;

            if (!IPAddress.TryParse(expression.Substring(sep + 1, length - sep - 2), out ipaddress2))
            {
                range.exceptionMessage = DataStrings.InvalidIPAddressFormat(expression.Substring(sep + 1, length - sep - 2));
                return(false);
            }
            if (ipaddress.AddressFamily != ipaddress2.AddressFamily)
            {
                range.exceptionMessage = DataStrings.StartingAddressAndMaskAddressFamilyMismatch;
                return(false);
            }
            int         i          = (ipaddress.AddressFamily == AddressFamily.InterNetwork) ? 32 : 128;
            IPvxAddress pvxAddress = new IPvxAddress(ipaddress2);

            while (i > 0 && (byte)pvxAddress == 0)
            {
                i           -= 8;
                pvxAddress >>= 8;
            }
            if (i == 0)
            {
                if (ipaddress.AddressFamily == AddressFamily.InterNetwork)
                {
                    range.SetAddresses(IPvxAddress.IPv4MappedMask, IPvxAddress.IPv4Broadcast);
                }
                else
                {
                    range.SetAddresses(IPvxAddress.Zero, new IPvxAddress(ulong.MaxValue, ulong.MaxValue));
                }
                range.format = IPRange.Format.Netmask;
                return(true);
            }
            short num = 0;
            byte  b   = (byte)pvxAddress;

            if (b <= 224)
            {
                if (b == 128)
                {
                    num += 1;
                    goto IL_1EB;
                }
                if (b == 192)
                {
                    num += 2;
                    goto IL_1EB;
                }
                if (b == 224)
                {
                    num += 3;
                    goto IL_1EB;
                }
            }
            else
            {
                if (b == 240)
                {
                    num += 4;
                    goto IL_1EB;
                }
                if (b == 248)
                {
                    num += 5;
                    goto IL_1EB;
                }
                switch (b)
                {
                case 252:
                    num += 6;
                    goto IL_1EB;

                case 254:
                    num += 7;
                    goto IL_1EB;

                case 255:
                    num += 8;
                    goto IL_1EB;
                }
            }
            range.exceptionMessage = DataStrings.InvalidIPAddressMask(ipaddress2.ToString());
            return(false);

IL_1EB:
            i           -= 8;
            pvxAddress >>= 8;
            while (i > 0)
            {
                if ((byte)pvxAddress != 255)
                {
                    range.exceptionMessage = DataStrings.InvalidIPAddressMask(ipaddress2.ToString());
                    return(false);
                }
                i           -= 8;
                pvxAddress >>= 8;
                num         += 8;
            }
            if (!range.SetAddressesFromCIDR(new IPvxAddress(ipaddress), num))
            {
                return(false);
            }
            range.format = IPRange.Format.Netmask;
            return(true);
        }
Beispiel #13
0
 public bool Contains(IPvxAddress ipAddress)
 {
     return(ipAddress <= this.endAddress && ipAddress >= this.startAddress);
 }
Beispiel #14
0
        public bool Contains(IPAddress ipAddress)
        {
            IPvxAddress ipAddress2 = new IPvxAddress(ipAddress);

            return(this.Contains(ipAddress2));
        }