internal static StoreObjectPropertyBag CreatePropertyBag(StoreSession storeSession, StoreObjectId id, ICollection <PropertyDefinition> prefetchPropertyArray) { MapiProp mapiProp = null; StoreObjectPropertyBag storeObjectPropertyBag = null; bool flag = false; StoreObjectPropertyBag result; try { mapiProp = storeSession.GetMapiProp(id); storeObjectPropertyBag = new StoreObjectPropertyBag(storeSession, mapiProp, prefetchPropertyArray); flag = true; result = storeObjectPropertyBag; } finally { if (!flag) { if (storeObjectPropertyBag != null) { storeObjectPropertyBag.Dispose(); storeObjectPropertyBag = null; } if (mapiProp != null) { mapiProp.Dispose(); mapiProp = null; } } } return(result); }
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; } } }