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);
            }
        }
Ejemplo n.º 2
0
            // Token: 0x0600135F RID: 4959 RVA: 0x00070F58 File Offset: 0x0006F158
            protected object SortValues(PropValue propValue)
            {
                object value;

                try
                {
                    PropType propType = propValue.PropType;
                    if (propType <= PropType.LongArray)
                    {
                        switch (propType)
                        {
                        case PropType.ShortArray:
                        {
                            short[] shortArray = propValue.GetShortArray();
                            if (shortArray != null)
                            {
                                Array.Sort <short>(shortArray);
                                return(shortArray);
                            }
                            return(propValue.Value);
                        }

                        case PropType.IntArray:
                        {
                            int[] intArray = propValue.GetIntArray();
                            if (intArray != null)
                            {
                                Array.Sort <int>(intArray);
                                return(intArray);
                            }
                            return(propValue.Value);
                        }

                        case PropType.FloatArray:
                        {
                            float[] floatArray = propValue.GetFloatArray();
                            if (floatArray != null)
                            {
                                Array.Sort <float>(floatArray);
                                return(floatArray);
                            }
                            return(propValue.Value);
                        }

                        case PropType.DoubleArray:
                        {
                            double[] doubleArray = propValue.GetDoubleArray();
                            if (doubleArray != null)
                            {
                                Array.Sort <double>(doubleArray);
                                return(doubleArray);
                            }
                            return(propValue.Value);
                        }

                        default:
                            if (propType == PropType.LongArray)
                            {
                                long[] longArray = propValue.GetLongArray();
                                if (longArray != null)
                                {
                                    Array.Sort <long>(longArray);
                                    return(longArray);
                                }
                                return(propValue.Value);
                            }
                            break;
                        }
                    }
                    else
                    {
                        switch (propType)
                        {
                        case PropType.AnsiStringArray:
                        case PropType.StringArray:
                        {
                            string[] stringArray = propValue.GetStringArray();
                            if (stringArray != null)
                            {
                                Array.Sort <string>(stringArray);
                                return(stringArray);
                            }
                            return(propValue.Value);
                        }

                        default:
                            if (propType != PropType.GuidArray)
                            {
                                if (propType == PropType.BinaryArray)
                                {
                                    byte[][] bytesArray = propValue.GetBytesArray();
                                    if (bytesArray != null)
                                    {
                                        Array.Sort <byte[]>(bytesArray, ArrayComparer <byte> .Comparer);
                                        return(bytesArray);
                                    }
                                    return(propValue.Value);
                                }
                            }
                            else
                            {
                                Guid[] guidArray = propValue.GetGuidArray();
                                if (guidArray != null)
                                {
                                    Array.Sort <Guid>(guidArray);
                                    return(guidArray);
                                }
                                return(propValue.Value);
                            }
                            break;
                        }
                    }
                    OABLogger.LogRecord(TraceType.ErrorTrace, "MultivaluedProperty.SortValues: don't know how to deal with type {0}", new object[]
                    {
                        propValue.PropType
                    });
                    value = propValue.Value;
                }
                catch (InvalidCastException)
                {
                    OABLogger.LogRecord(TraceType.ErrorTrace, "MultivaluedProperty.SortValues: InvalidCastException while handling property {0} of stated type {1}", new object[]
                    {
                        this.propertyDefinition.Name,
                        propValue.PropType
                    });
                    value = propValue.Value;
                }
                return(value);
            }
Ejemplo n.º 3
0
        private object ConvertValue(ADPropertyDefinition propertyDefinition, PropValue propValue)
        {
            if (propValue.IsError() || propValue.IsNull())
            {
                return(null);
            }
            PropType propType = propValue.PropType;

            object[] values;
            if (propType <= PropType.SysTime)
            {
                if (propType <= PropType.Boolean)
                {
                    if (propType != PropType.Int && propType != PropType.Boolean)
                    {
                        goto IL_174;
                    }
                }
                else
                {
                    switch (propType)
                    {
                    case PropType.AnsiString:
                        values = new object[]
                        {
                            this.encoding.GetString(propValue.GetBytes())
                        };
                        goto IL_18F;

                    case PropType.String:
                        break;

                    default:
                        if (propType != PropType.SysTime)
                        {
                            goto IL_174;
                        }
                        break;
                    }
                }
            }
            else if (propType <= PropType.Binary)
            {
                if (propType != PropType.Guid)
                {
                    if (propType != PropType.Binary)
                    {
                        goto IL_174;
                    }
                    values = new object[]
                    {
                        propValue.RawValue
                    };
                    goto IL_18F;
                }
            }
            else
            {
                switch (propType)
                {
                case PropType.AnsiStringArray:
                    values = Array.ConvertAll <byte[], object>(propValue.GetBytesArray(), (byte[] bytesValue) => this.encoding.GetString(bytesValue));
                    goto IL_18F;

                case PropType.StringArray:
                    values = Array.ConvertAll <string, object>(propValue.GetStringArray(), (string stringValue) => stringValue);
                    goto IL_18F;

                default:
                    if (propType != PropType.BinaryArray)
                    {
                        goto IL_174;
                    }
                    values = Array.ConvertAll <byte[], object>(propValue.GetBytesArray(), (byte[] bytesValue) => bytesValue);
                    goto IL_18F;
                }
            }
            values = new object[]
            {
                propValue.RawValue.ToString()
            };
            goto IL_18F;
IL_174:
            throw new InvalidOperationException(string.Format("Property type {0} is not supported", propValue.GetType()));
            object result;

            try
            {
IL_18F:
                result = ADValueConvertor.GetValueFromDirectoryAttributeValues(propertyDefinition, values);
            }
            catch (DataValidationException arg)
            {
                NspiPropertyMap.Tracer.TraceWarning <string, DataValidationException>((long)this.GetHashCode(), "Unable to handle property {0} because it has invalid value, exception: {1}", propertyDefinition.Name, arg);
                result = null;
            }
            return(result);
        }
Ejemplo n.º 4
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);
        }