예제 #1
0
        internal void Instantiate(PropValue[] propertyValues)
        {
            if (propertyValues == null)
            {
                throw new ArgumentNullException("propertyValues");
            }
            if (propertyValues.Length == 0)
            {
                return;
            }
            if (!(this.ObjectSchema is MapiObjectSchema))
            {
                throw new MapiInvalidOperationException(Strings.ExceptionSchemaInvalidCast(this.ObjectSchema.GetType().ToString()));
            }
            base.InstantiationErrors.Clear();
            MapiStore mapiStore = null;
            MapiProp  mapiProp  = null;

            try
            {
                foreach (PropertyDefinition propertyDefinition in this.ObjectSchema.AllProperties)
                {
                    MapiPropertyDefinition mapiPropertyDefinition = (MapiPropertyDefinition)propertyDefinition;
                    if (!mapiPropertyDefinition.IsCalculated && mapiPropertyDefinition.PropertyTag != PropTag.Null)
                    {
                        bool      flag      = false;
                        PropValue propValue = new PropValue(PropTag.Null, null);
                        foreach (PropValue propValue in propertyValues)
                        {
                            if (propValue.PropTag.Id() == mapiPropertyDefinition.PropertyTag.Id())
                            {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag)
                        {
                            if (mapiPropertyDefinition.IsMandatory)
                            {
                                base.InstantiationErrors.Add(new PropertyValidationError(Strings.ErrorMandatoryPropertyMissing(mapiPropertyDefinition.Name), mapiPropertyDefinition, null));
                            }
                        }
                        else
                        {
                            if (PropType.Error == propValue.PropType && propValue.GetErrorValue() == -2147024882)
                            {
                                if (mapiProp == null)
                                {
                                    mapiProp = this.GetRawMapiEntry(out mapiStore);
                                }
                                propValue = mapiProp.GetProp(mapiPropertyDefinition.PropertyTag);
                            }
                            if (PropType.Error == propValue.PropType)
                            {
                                ExTraceGlobals.MapiObjectTracer.TraceError <PropTag>((long)this.GetHashCode(), "Retrieving PropTag '{0}' failed.", mapiPropertyDefinition.PropertyTag);
                            }
                            else
                            {
                                try
                                {
                                    object value = mapiPropertyDefinition.Extractor(propValue, mapiPropertyDefinition);
                                    IList <ValidationError> list = mapiPropertyDefinition.ValidateProperty(value, this.propertyBag, false);
                                    if (list != null)
                                    {
                                        base.InstantiationErrors.AddRange(list);
                                    }
                                    this.propertyBag.SetField(mapiPropertyDefinition, value);
                                }
                                catch (MapiConvertingException ex)
                                {
                                    base.InstantiationErrors.Add(new PropertyConversionError(ex.LocalizedString, mapiPropertyDefinition, propValue, ex));
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (mapiProp != null)
                {
                    mapiProp.Dispose();
                    mapiProp = null;
                }
                if (mapiStore != null)
                {
                    mapiStore.Dispose();
                    mapiStore = null;
                }
            }
        }
예제 #2
0
        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);
        }