internal static PropValue ConvertToMapiPropValue(PropertyValue propertyValue) { PropValue result; try { PropertyTag propertyTag = propertyValue.PropertyTag; object value = null; if (!propertyValue.IsNullValue) { PropertyType propertyType = propertyTag.PropertyType; if (propertyType <= PropertyType.Guid) { if (propertyType <= PropertyType.Object) { switch (propertyType) { case PropertyType.Null: goto IL_244; case PropertyType.Int16: value = propertyValue.GetValue <short>(); goto IL_244; case PropertyType.Int32: value = propertyValue.GetValue <int>(); goto IL_244; default: switch (propertyType) { case PropertyType.Error: value = (uint)propertyValue.Value; goto IL_244; case PropertyType.Bool: value = propertyValue.GetValue <bool>(); goto IL_244; case PropertyType.Object: goto IL_244; } break; } } else { switch (propertyType) { case PropertyType.String8: value = MarshalHelper.GetString8PropertyValue(propertyValue); goto IL_244; case PropertyType.Unicode: value = propertyValue.GetValue <string>(); goto IL_244; default: if (propertyType == PropertyType.SysTime) { value = (DateTime)propertyValue.GetValue <ExDateTime>(); goto IL_244; } if (propertyType == PropertyType.Guid) { value = propertyValue.GetValue <Guid>(); goto IL_244; } break; } } } else if (propertyType <= PropertyType.MultiValueUnicode) { if (propertyType == PropertyType.Binary) { value = propertyValue.GetValue <byte[]>(); goto IL_244; } switch (propertyType) { case PropertyType.MultiValueInt16: value = propertyValue.GetValue <short[]>(); goto IL_244; case PropertyType.MultiValueInt32: value = propertyValue.GetValue <int[]>(); goto IL_244; default: switch (propertyType) { case PropertyType.MultiValueString8: value = MarshalHelper.GetMultiValuedString8PropertyValue(propertyValue); goto IL_244; case PropertyType.MultiValueUnicode: value = propertyValue.GetValue <string[]>(); goto IL_244; } break; } } else { if (propertyType == PropertyType.MultiValueSysTime) { ExDateTime[] value2 = propertyValue.GetValue <ExDateTime[]>(); DateTime[] array = null; if (value2 != null) { array = new DateTime[value2.Length]; for (int i = 0; i < value2.Length; i++) { array[i] = (DateTime)value2[i]; } } value = array; goto IL_244; } if (propertyType == PropertyType.MultiValueGuid) { value = propertyValue.GetValue <Guid[]>(); goto IL_244; } if (propertyType == PropertyType.MultiValueBinary) { value = propertyValue.GetValue <byte[][]>(); goto IL_244; } } throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert unsupported property type {0} on property {1}.", propertyTag.PropertyType, propertyTag)); } IL_244: result = new PropValue(ConvertHelper.ConvertToMapiPropTag(propertyTag), value); } catch (UnexpectedPropertyTypeException inner) { throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert invalid PropValue as it contains unsupported PropType on property {0}.", propertyValue), inner); } return(result); }
internal static Restriction ConvertToMapiRestriction(Restriction restriction) { if (restriction == null) { return(null); } switch (restriction.RestrictionType) { case RestrictionType.And: return(Restriction.And(ConvertHelper.ConvertToMapiRestrictions(((CompositeRestriction)restriction).ChildRestrictions))); case RestrictionType.Or: return(Restriction.Or(ConvertHelper.ConvertToMapiRestrictions(((CompositeRestriction)restriction).ChildRestrictions))); case RestrictionType.Not: return(Restriction.Not(ConvertHelper.ConvertToMapiRestriction(((NotRestriction)restriction).ChildRestriction))); case RestrictionType.Content: { ContentRestriction contentRestriction = restriction as ContentRestriction; if (contentRestriction.PropertyValue == null) { throw new NspiException(NspiStatus.InvalidParameter, "Null PropertyValue is not valid for ContentRestriction."); } return(Restriction.Content(ConvertHelper.ConvertToMapiPropTag(contentRestriction.PropertyTag), contentRestriction.PropertyTag.IsMultiValuedProperty, ConvertHelper.ConvertToMapiPropValue(contentRestriction.PropertyValue.Value), (ContentFlags)contentRestriction.FuzzyLevel)); } case RestrictionType.Property: { PropertyRestriction propertyRestriction = restriction as PropertyRestriction; if (propertyRestriction.PropertyValue == null) { throw new NspiException(NspiStatus.InvalidParameter, "Null PropertyValue is not valid for PropertyRestriction."); } return(Restriction.Property(ConvertHelper.ConvertToMapiRelOp(propertyRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(propertyRestriction.PropertyTag), propertyRestriction.PropertyTag.IsMultiValuedProperty, ConvertHelper.ConvertToMapiPropValue(propertyRestriction.PropertyValue.Value))); } case RestrictionType.CompareProps: { ComparePropsRestriction comparePropsRestriction = restriction as ComparePropsRestriction; return(Restriction.CompareProps(ConvertHelper.ConvertToMapiRelOp(comparePropsRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(comparePropsRestriction.Property1), ConvertHelper.ConvertToMapiPropTag(comparePropsRestriction.Property2))); } case RestrictionType.BitMask: { BitMaskRestriction bitMaskRestriction = restriction as BitMaskRestriction; return(Restriction.BitMask(ConvertHelper.ConvertToMapiRelBmr(bitMaskRestriction.BitMaskOperator), ConvertHelper.ConvertToMapiPropTag(bitMaskRestriction.PropertyTag), (int)bitMaskRestriction.BitMask)); } case RestrictionType.Size: { SizeRestriction sizeRestriction = restriction as SizeRestriction; return(Restriction.PropertySize(ConvertHelper.ConvertToMapiRelOp(sizeRestriction.RelationOperator), ConvertHelper.ConvertToMapiPropTag(sizeRestriction.PropertyTag), (int)sizeRestriction.Size)); } case RestrictionType.Exists: { ExistsRestriction existsRestriction = restriction as ExistsRestriction; return(Restriction.Exist(ConvertHelper.ConvertToMapiPropTag(existsRestriction.PropertyTag))); } case RestrictionType.SubRestriction: { SubRestriction subRestriction = restriction as SubRestriction; return(Restriction.Sub(ConvertHelper.ConvertToMapiPropTag(subRestriction.SubRestrictionType), ConvertHelper.ConvertToMapiRestriction(subRestriction.ChildRestriction))); } default: throw new NspiException(NspiStatus.InvalidParameter, string.Format("Invalid restriction type: {0}", restriction)); } }
internal static PropRow ConvertToMapiPropRow(PropertyValue[] propertyValues) { PropValue[] properties = ConvertHelper.ConvertToMapiPropValues(propertyValues); return(new PropRow(properties)); }
internal static Restriction ConvertFromMapiRestriction(Restriction restriction, int codePage) { if (restriction == null) { return(null); } switch (restriction.Type) { case Restriction.ResType.And: return(new AndRestriction((from r in ((Restriction.AndRestriction)restriction).Restrictions select ConvertHelper.ConvertFromMapiRestriction(r, codePage)).ToArray <Restriction>())); case Restriction.ResType.Or: return(new OrRestriction((from r in ((Restriction.OrRestriction)restriction).Restrictions select ConvertHelper.ConvertFromMapiRestriction(r, codePage)).ToArray <Restriction>())); case Restriction.ResType.Not: return(new NotRestriction(ConvertHelper.ConvertFromMapiRestriction((Restriction.NotRestriction)restriction, codePage))); case Restriction.ResType.Content: { Restriction.ContentRestriction contentRestriction = (Restriction.ContentRestriction)restriction; return(new ContentRestriction((FuzzyLevel)contentRestriction.Flags, ConvertHelper.ConvertFromMapiPropTag(contentRestriction.PropTag), new PropertyValue?(ConvertHelper.ConvertFromMapiPropValue(contentRestriction.PropValue, codePage)))); } case Restriction.ResType.Property: { Restriction.PropertyRestriction propertyRestriction = (Restriction.PropertyRestriction)restriction; RelationOperator relop = ConvertHelper.ConvertFromMapiRelOp(propertyRestriction.Op); PropertyTag propertyTag = ConvertHelper.ConvertFromMapiPropTag(propertyRestriction.PropTag); PropertyValue value = ConvertHelper.ConvertFromMapiPropValue(propertyRestriction.PropValue, codePage); return(new PropertyRestriction(relop, propertyTag, new PropertyValue?(value))); } case Restriction.ResType.CompareProps: { Restriction.ComparePropertyRestriction comparePropertyRestriction = (Restriction.ComparePropertyRestriction)restriction; return(new ComparePropsRestriction(ConvertHelper.ConvertFromMapiRelOp(comparePropertyRestriction.Op), ConvertHelper.ConvertFromMapiPropTag(comparePropertyRestriction.TagLeft), ConvertHelper.ConvertFromMapiPropTag(comparePropertyRestriction.TagRight))); } case Restriction.ResType.BitMask: { Restriction.BitMaskRestriction bitMaskRestriction = (Restriction.BitMaskRestriction)restriction; return(new BitMaskRestriction(ConvertHelper.ConvertFromMapiRelBmr(bitMaskRestriction.Bmr), ConvertHelper.ConvertFromMapiPropTag(bitMaskRestriction.Tag), (uint)bitMaskRestriction.Mask)); } case Restriction.ResType.Size: { Restriction.SizeRestriction sizeRestriction = (Restriction.SizeRestriction)restriction; return(new SizeRestriction(ConvertHelper.ConvertFromMapiRelOp(sizeRestriction.Op), ConvertHelper.ConvertFromMapiPropTag(sizeRestriction.Tag), (uint)sizeRestriction.Size)); } case Restriction.ResType.Exist: { Restriction.ExistRestriction existRestriction = (Restriction.ExistRestriction)restriction; return(new ExistsRestriction(ConvertHelper.ConvertFromMapiPropTag(existRestriction.Tag))); } case Restriction.ResType.SubRestriction: { Restriction.SubRestriction subRestriction = (Restriction.SubRestriction)restriction; return(new SubRestriction((SubRestrictionType)subRestriction.Type, ConvertHelper.ConvertFromMapiRestriction(subRestriction.Restriction, codePage))); } default: throw new NspiException(NspiStatus.InvalidParameter, string.Format("Invalid MAPI restriction type: {0}", restriction)); } }
internal static PropertyValue ConvertFromMapiPropValue(PropValue mapiPropValue, int codePage) { PropertyValue result; try { PropertyTag propertyTag = new PropertyTag((uint)mapiPropValue.PropTag); object obj = null; PropertyType propertyType = propertyTag.PropertyType; if (propertyType <= PropertyType.Guid) { if (propertyType <= PropertyType.Object) { switch (propertyType) { case PropertyType.Null: goto IL_2E7; case PropertyType.Int16: obj = mapiPropValue.GetShort(); goto IL_2E7; case PropertyType.Int32: obj = mapiPropValue.GetInt(); goto IL_2E7; default: switch (propertyType) { case PropertyType.Error: obj = (ErrorCode)mapiPropValue.GetErrorValue(); goto IL_2E7; case PropertyType.Bool: obj = mapiPropValue.GetBoolean(); goto IL_2E7; case PropertyType.Object: goto IL_2E7; } break; } } else { switch (propertyType) { case PropertyType.String8: obj = ConvertHelper.ConvertMapiPtString8ToString8(mapiPropValue.Value, codePage); goto IL_2E7; case PropertyType.Unicode: obj = mapiPropValue.GetString(); goto IL_2E7; default: if (propertyType == PropertyType.SysTime) { DateTime dateTime = mapiPropValue.GetDateTime(); obj = (ExDateTime)dateTime; goto IL_2E7; } if (propertyType == PropertyType.Guid) { obj = mapiPropValue.GetGuid(); goto IL_2E7; } break; } } } else if (propertyType <= PropertyType.MultiValueUnicode) { if (propertyType == PropertyType.Binary) { obj = mapiPropValue.GetBytes(); goto IL_2E7; } switch (propertyType) { case PropertyType.MultiValueInt16: obj = mapiPropValue.GetShortArray(); goto IL_2E7; case PropertyType.MultiValueInt32: obj = mapiPropValue.GetIntArray(); goto IL_2E7; default: switch (propertyType) { case PropertyType.MultiValueString8: if (mapiPropValue.Value is string[]) { string[] array = (string[])mapiPropValue.Value; String8[] array2 = new String8[array.Length]; for (int i = 0; i < array.Length; i++) { array2[i] = ConvertHelper.ConvertMapiPtString8ToString8(array[i], codePage); } obj = array2; goto IL_2E7; } if (mapiPropValue.Value is byte[][]) { byte[][] array3 = (byte[][])mapiPropValue.Value; String8[] array4 = new String8[array3.Length]; for (int j = 0; j < array3.Length; j++) { array4[j] = ConvertHelper.ConvertMapiPtString8ToString8(array3[j], codePage); } obj = array4; goto IL_2E7; } goto IL_2E7; case PropertyType.MultiValueUnicode: obj = mapiPropValue.GetStringArray(); goto IL_2E7; } break; } } else if (propertyType != PropertyType.MultiValueSysTime) { if (propertyType == PropertyType.MultiValueGuid) { obj = mapiPropValue.GetGuidArray(); goto IL_2E7; } if (propertyType == PropertyType.MultiValueBinary) { obj = mapiPropValue.GetBytesArray(); goto IL_2E7; } } else { DateTime[] dateTimeArray = mapiPropValue.GetDateTimeArray(); if (dateTimeArray != null) { ExDateTime[] array5 = new ExDateTime[dateTimeArray.Length]; for (int k = 0; k < dateTimeArray.Length; k++) { array5[k] = (ExDateTime)dateTimeArray[k]; } obj = array5; goto IL_2E7; } goto IL_2E7; } throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert unsupported property type {0} on property {1}.", propertyTag.PropertyType, propertyTag)); IL_2E7: if (obj == null) { result = PropertyValue.NullValue(propertyTag); } else { result = new PropertyValue(propertyTag, obj); } } catch (InvalidPropertyValueTypeException inner) { throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert invalid PropValue on property {0}.", mapiPropValue), inner); } catch (NotSupportedException inner2) { throw new NspiException(NspiStatus.InvalidParameter, string.Format("Unable to convert invalid PropValue as it contains unsupported PropType on property {0}.", mapiPropValue), inner2); } return(result); }