Exemple #1
0
 public static PropValue PackNullableUnlimitedByteQuantifiedSizeIntoKilobytes(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(Unlimited <ByteQuantifiedSize>) == value.GetType())
     {
         long num = -1L;
         if (value != null)
         {
             Unlimited <ByteQuantifiedSize> unlimited = (Unlimited <ByteQuantifiedSize>)value;
             if (unlimited.IsUnlimited)
             {
                 num = -1L;
             }
             else
             {
                 num = checked ((long)unlimited.Value.ToKB());
             }
         }
         object value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack(num, propertyDefinition.PropertyTag.ValueType(), out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #2
0
 public static PropValue PackNullableEnhancedTimeSpanIntoSeconds(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value != null && typeof(EnhancedTimeSpan) == value.GetType())
     {
         object value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack(((EnhancedTimeSpan)value).TotalSeconds, propertyDefinition.PropertyTag.ValueType(), out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #3
0
 public static object ExtractNullableEnhancedTimeSpanFromSeconds(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(EnhancedTimeSpan?) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(double), out obj))
         {
             return(new EnhancedTimeSpan?(EnhancedTimeSpan.FromSeconds((double)obj)));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #4
0
 public static PropValue PackNullableEnhancedTimeSpanIntoDays(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(EnhancedTimeSpan) == value.GetType())
     {
         PropType type   = propertyDefinition.PropertyTag.ValueType();
         object   value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack((value == null) ? 0.0 : ((EnhancedTimeSpan)value).TotalDays, type, out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #5
0
 public static PropValue PackNullableValueToBool(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (value == null || typeof(bool) == value.GetType())
     {
         PropType type   = propertyDefinition.PropertyTag.ValueType();
         object   value2 = null;
         if (MapiPropValueConvertor.TryCastValueToPack((value == null) ? false : value, type, out value2))
         {
             return(new PropValue(propertyDefinition.PropertyTag, value2));
         }
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
        public static PropValue Pack(object value, MapiPropertyDefinition propertyDefinition)
        {
            PropTag  propertyTag = propertyDefinition.PropertyTag;
            PropType propType    = propertyTag.ValueType();
            Type     type        = MapiPropValueConvertor.TypeFromPropType(propType, false);

            if (value != null)
            {
                if (typeof(byte[]) == type)
                {
                    if (typeof(Guid) == value.GetType())
                    {
                        return(new PropValue(propertyTag, ((Guid)value).ToByteArray()));
                    }
                    if (typeof(Schedule) == value.GetType())
                    {
                        return(new PropValue(propertyTag, ((Schedule)value).ToByteArray()));
                    }
                }
                if (typeof(DateTime) == type && typeof(DateTime) == value.GetType())
                {
                    return(new PropValue(propertyTag, ((DateTime)value).ToUniversalTime()));
                }
                if (typeof(DateTime[]) == type)
                {
                    Type type2 = value.GetType();
                    if (typeof(MultiValuedProperty <DateTime>) == type2 || typeof(DateTime[]) == type2)
                    {
                        List <DateTime> list = new List <DateTime>(((ICollection)value).Count);
                        foreach (object obj in ((ICollection)value))
                        {
                            list.Add(((DateTime)obj).ToUniversalTime());
                        }
                        return(new PropValue(propertyTag, list.ToArray()));
                    }
                }
                if (type.IsAssignableFrom(value.GetType()))
                {
                    return(new PropValue(propertyTag, value));
                }
            }
            object value2 = null;

            if (MapiPropValueConvertor.TryCastValueToPack(value, propType, out value2))
            {
                return(new PropValue(propertyTag, value2));
            }
            throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
        }
Exemple #7
0
 public static object ExtractUnlimitedByteQuantifiedSizeFromPages(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(Unlimited <ByteQuantifiedSize>) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(int), out obj))
         {
             long num = (long)((int)obj);
             if (0L > num)
             {
                 return(Unlimited <ByteQuantifiedSize> .UnlimitedValue);
             }
             return(new Unlimited <ByteQuantifiedSize>(ByteQuantifiedSize.FromBytes(checked ((ulong)num * 32UL * 1024UL))));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #8
0
 public static object ExtractNullableUnlimitedByteQuantifiedSizeFromKilobytes(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(Unlimited <ByteQuantifiedSize>?) == propertyDefinition.Type)
     {
         object obj = null;
         if (MapiPropValueConvertor.TryCastValueToExtract(value, typeof(long), out obj))
         {
             long num = (long)obj;
             if (0L > num)
             {
                 return(new Unlimited <ByteQuantifiedSize>?(Unlimited <ByteQuantifiedSize> .UnlimitedValue));
             }
             return(new Unlimited <ByteQuantifiedSize>?(new Unlimited <ByteQuantifiedSize>(ByteQuantifiedSize.FromKB(checked ((ulong)num)))));
         }
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #9
0
 public static PropValue PackMultiAnsiStringsIntoBytes(object value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(MultiValuedProperty <string>) == value.GetType())
     {
         MultiValuedProperty <string> multiValuedProperty = (MultiValuedProperty <string>)value;
         List <byte> list = new List <byte>();
         foreach (string s in multiValuedProperty)
         {
             byte[] bytes = Encoding.ASCII.GetBytes(s);
             list.AddRange(bytes);
             if (bytes[bytes.Length - 1] != 0)
             {
                 list.Add(0);
             }
         }
         return(new PropValue(propertyDefinition.PropertyTag, list.ToArray()));
     }
     throw MapiPropValueConvertor.ConstructPackingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #10
0
 public static object ExtractIpV4StringFromIpV6Bytes(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (!(typeof(string) == propertyDefinition.Type))
     {
         throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
     }
     byte[] bytes = value.GetBytes();
     if (16 == bytes.Length)
     {
         return(string.Format("{0}.{1}.{2}.{3}", new object[]
         {
             bytes[4],
             bytes[5],
             bytes[6],
             bytes[7]
         }));
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ErrorByteArrayLength(16.ToString(), bytes.Length.ToString()));
 }
 internal static bool TryCastValueToPack(object value, PropType type, out object valueToPack)
 {
     valueToPack = null;
     try
     {
         valueToPack = Convert.ChangeType(value, MapiPropValueConvertor.TypeFromPropType(type, false));
     }
     catch (ArgumentNullException)
     {
         return(false);
     }
     catch (InvalidCastException)
     {
         return(false);
     }
     catch (OverflowException)
     {
         return(false);
     }
     return(true);
 }
Exemple #12
0
 public static object ExtractMultiAnsiStringsFromBytes(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (typeof(string) == propertyDefinition.Type && propertyDefinition.IsMultivalued)
     {
         byte[]        bytes = value.GetBytes();
         List <string> list  = new List <string>();
         int           num   = 0;
         int           num2  = 0;
         while (bytes.Length > num2)
         {
             if (bytes[num2] == 0)
             {
                 list.Add(Encoding.ASCII.GetString(bytes, num, num2 - num));
                 num = 1 + num2;
             }
             num2++;
         }
         return(new MultiValuedProperty <string>(propertyDefinition.IsReadOnly, propertyDefinition, list));
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
 }
Exemple #13
0
 public static object ExtractMacAddressStringFromBytes(PropValue value, MapiPropertyDefinition propertyDefinition)
 {
     if (!(typeof(string) == propertyDefinition.Type))
     {
         throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
     }
     byte[] bytes = value.GetBytes();
     if (6 == bytes.Length)
     {
         return(string.Format("{0:X2}-{1:X2}-{2:X2}-{3:X2}-{4:X2}-{5:X2}", new object[]
         {
             bytes[0],
             bytes[1],
             bytes[2],
             bytes[3],
             bytes[4],
             bytes[5]
         }));
     }
     throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ErrorByteArrayLength(6.ToString(), bytes.Length.ToString()));
 }
        public static object Extract(PropValue value, MapiPropertyDefinition propertyDefinition)
        {
            bool isReadOnly     = propertyDefinition.IsReadOnly;
            Type type           = propertyDefinition.Type;
            Type underlyingType = Nullable.GetUnderlyingType(type);

            if (null != underlyingType)
            {
                type = underlyingType;
            }
            if (propertyDefinition.PropertyTag.Id() != value.PropTag.Id())
            {
                throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ExceptionUnmatchedPropTag(propertyDefinition.PropertyTag.ToString(), value.PropTag.ToString()));
            }
            if (PropType.Binary == value.PropType)
            {
                if (typeof(Guid) == type)
                {
                    return(new Guid(value.GetBytes()));
                }
                if (typeof(Schedule) == type)
                {
                    return(Schedule.FromByteArray(value.GetBytes()));
                }
                if (typeof(MapiEntryId) == type)
                {
                    return(new MapiEntryId(value.GetBytes()));
                }
            }
            if (typeof(short) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <short>(isReadOnly, propertyDefinition, value.GetShortArray()));
                }
                return(value.GetShort());
            }
            else if (typeof(int) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <int>(isReadOnly, propertyDefinition, value.GetIntArray()));
                }
                return(value.GetInt());
            }
            else if (typeof(long) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <long>(isReadOnly, propertyDefinition, value.GetLongArray()));
                }
                return(value.GetLong());
            }
            else if (typeof(float) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <float>(isReadOnly, propertyDefinition, value.GetFloatArray()));
                }
                return(value.GetFloat());
            }
            else if (typeof(double) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <double>(isReadOnly, propertyDefinition, value.GetDoubleArray()));
                }
                return(value.GetDouble());
            }
            else if (typeof(DateTime) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    DateTime[]      dateTimeArray = value.GetDateTimeArray();
                    List <DateTime> list          = new List <DateTime>(dateTimeArray.Length);
                    foreach (DateTime dateTime in dateTimeArray)
                    {
                        list.Add(dateTime.ToLocalTime());
                    }
                    return(new MultiValuedProperty <DateTime>(isReadOnly, propertyDefinition, list.ToArray()));
                }
                return(value.GetDateTime().ToLocalTime());
            }
            else if (typeof(bool) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <bool>(isReadOnly, propertyDefinition, value.GetBoolArray()));
                }
                return(value.GetBoolean());
            }
            else if (typeof(string) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <string>(isReadOnly, propertyDefinition, value.GetStringArray()));
                }
                return(value.GetString());
            }
            else if (typeof(Guid) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <Guid>(isReadOnly, propertyDefinition, value.GetGuidArray()));
                }
                return(value.GetGuid());
            }
            else if (typeof(byte[]) == type)
            {
                if (propertyDefinition.IsMultivalued)
                {
                    return(new MultiValuedProperty <byte[]>(isReadOnly, propertyDefinition, value.GetBytesArray()));
                }
                return(value.GetBytes());
            }
            else
            {
                if (typeof(short[]) == type)
                {
                    return(value.GetShortArray());
                }
                if (typeof(int[]) == type)
                {
                    return(value.GetIntArray());
                }
                if (typeof(long[]) == type)
                {
                    return(value.GetLongArray());
                }
                if (typeof(float[]) == type)
                {
                    return(value.GetFloatArray());
                }
                if (typeof(double[]) == type)
                {
                    return(value.GetDoubleArray());
                }
                if (typeof(DateTime[]) == type)
                {
                    DateTime[]      dateTimeArray2 = value.GetDateTimeArray();
                    List <DateTime> list2          = new List <DateTime>(dateTimeArray2.Length);
                    foreach (DateTime dateTime2 in dateTimeArray2)
                    {
                        list2.Add(dateTime2.ToLocalTime());
                    }
                    return(list2.ToArray());
                }
                if (typeof(bool[]) == type)
                {
                    return(value.GetBoolArray());
                }
                if (typeof(string[]) == type)
                {
                    return(value.GetStringArray());
                }
                if (typeof(Guid[]) == type)
                {
                    return(value.GetGuidArray());
                }
                if (typeof(byte[][]) == type)
                {
                    return(value.GetBytesArray());
                }
                if (type.IsAssignableFrom(MapiPropValueConvertor.TypeFromPropType(value.PropType, false)))
                {
                    return(value.RawValue);
                }
                object result = null;
                if (MapiPropValueConvertor.TryCastValueToExtract(value, type, out result))
                {
                    return(result);
                }
                throw MapiPropValueConvertor.ConstructExtractingException(value, propertyDefinition, Strings.ConstantNa);
            }
        }
Exemple #15
0
 private MapiPropertyDefinition(string name, Type type, PropTag propertyTag, MapiPropertyDefinitionFlags propertyDefinitionFlags, object defaultValue, object initialValue, MapiPropValueExtractorDelegate propertyValueExtractor, MapiPropValuePackerDelegate propertyValuePacker, PropertyDefinitionConstraint[] readConstraints, PropertyDefinitionConstraint[] writeConstraints, ProviderPropertyDefinition[] supportingProperties, CustomFilterBuilderDelegate customFilterBuilderDelegate, GetterDelegate getterDelegate, SetterDelegate setterDelegate) : base(name ?? propertyTag.ToString(), ExchangeObjectVersion.Exchange2003, type ?? MapiPropValueConvertor.TypeFromPropType(propertyTag.ValueType(), true), defaultValue, readConstraints ?? PropertyDefinitionConstraint.None, writeConstraints ?? PropertyDefinitionConstraint.None, supportingProperties ?? ProviderPropertyDefinition.None, customFilterBuilderDelegate, getterDelegate, setterDelegate)
 {
     this.propertyTag = propertyTag;
     if (((PropTag)12288U & propertyTag) != PropTag.Null)
     {
         propertyDefinitionFlags |= MapiPropertyDefinitionFlags.MultiValued;
     }
     this.propertyDefinitionFlags = propertyDefinitionFlags;
     this.initialValue            = initialValue;
     this.propertyValueExtractor  = (propertyValueExtractor ?? new MapiPropValueExtractorDelegate(MapiPropValueConvertor.Extract));
     this.propertyValuePacker     = (propertyValuePacker ?? new MapiPropValuePackerDelegate(MapiPropValueConvertor.Pack));
 }