예제 #1
0
 internal static PropTag[] ConvertToMapiPropTags(PropertyTag[] propertyTags)
 {
     if (propertyTags == null)
     {
         return(null);
     }
     PropTag[] array = new PropTag[propertyTags.Length];
     for (int i = 0; i < propertyTags.Length; i++)
     {
         array[i] = ConvertHelper.ConvertToMapiPropTag(propertyTags[i]);
     }
     return(array);
 }
예제 #2
0
        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);
        }
예제 #3
0
        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));
            }
        }