示例#1
0
        internal static MapiEntryId GetEntryIdentity(MapiProp mapiObject)
        {
            MapiEntryId result;

            try
            {
                if (mapiObject == null)
                {
                    throw new ArgumentNullException("mapiObject");
                }
                PropValue prop = mapiObject.GetProp(PropTag.EntryId);
                if (PropType.Error == prop.PropType)
                {
                    result = null;
                }
                else
                {
                    result = new MapiEntryId(prop.GetBytes());
                }
            }
            catch (MapiPermanentException)
            {
                result = null;
            }
            catch (MapiRetryableException)
            {
                result = null;
            }
            return(result);
        }
示例#2
0
        internal static string GetName(MapiProp mapiObject)
        {
            string result;

            try
            {
                if (mapiObject == null)
                {
                    throw new ArgumentNullException("mapiObject");
                }
                PropValue prop = mapiObject.GetProp(PropTag.DisplayName);
                if (PropType.Error == prop.PropType)
                {
                    result = null;
                }
                else
                {
                    result = prop.GetString();
                }
            }
            catch (MapiPermanentException)
            {
                result = null;
            }
            catch (MapiRetryableException)
            {
                result = null;
            }
            return(result);
        }
示例#3
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;
                }
            }
        }