public virtual void Save(IConfigurable instance) { if (instance.ObjectState == ObjectState.Unchanged) { return; } if (instance.ObjectState == ObjectState.Deleted) { throw new NotSupportedException("Can't save deleted object."); } EwsStoreObject ewsStoreObject = (EwsStoreObject)instance; if (ewsStoreObject.IsReadOnly) { throw new InvalidOperationException("Can't save read-only object."); } ValidationError[] array = ewsStoreObject.Validate(); if (array.Length > 0) { throw new DataValidationException(array[0]); } if (ewsStoreObject.MaximumSupportedExchangeObjectVersion.IsOlderThan(ewsStoreObject.ExchangeVersion)) { throw new DataValidationException(new PropertyValidationError(DataStrings.ErrorCannotSaveBecauseTooNew(ewsStoreObject.ExchangeVersion, ewsStoreObject.MaximumSupportedExchangeObjectVersion), ADObjectSchema.ExchangeVersion, ewsStoreObject.ExchangeVersion)); } if (ewsStoreObject.ObjectState == ObjectState.New) { Item item = this.CreateItemObjectForNew(); ewsStoreObject.CopyChangeToItemObject(item, this.RequestedServerVersion); this.InvokeServiceCall(delegate() { item.Save(this.DefaultFolder); }); ewsStoreObject.CopyFromItemObject(item, this.RequestedServerVersion); } else { bool flag; Item item = this.BindItem(ewsStoreObject.Identity.EwsObjectId, this.CreatePropertySet(ewsStoreObject.GetChangedPropertyDefinitions(), out flag)); if (item != null) { ewsStoreObject.CopyChangeToItemObject(item, this.RequestedServerVersion); this.InvokeServiceCall(delegate() { item.Update(2); }); } } ewsStoreObject.ResetChangeTracking(true); }
private T ObjectFromItem <T>(Item item) where T : IConfigurable, new() { EwsStoreObject ewsStoreObject = (EwsStoreObject)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T))); object originalValue = null; ExchangeObjectVersion exchangeVersion = (ExchangeObjectVersion)EwsStoreObjectSchema.ExchangeVersion.DefaultValue; if (item.TryGetProperty(EwsStoreObjectSchema.ExchangeVersion.StorePropertyDefinition, ref originalValue)) { exchangeVersion = (ExchangeObjectVersion)ValueConvertor.ConvertValue(originalValue, typeof(ExchangeObjectVersion), null); ewsStoreObject.SetExchangeVersion(exchangeVersion); if (ewsStoreObject.ExchangeVersion.Major > ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major) { ExTraceGlobals.StorageTracer.TraceWarning <ItemId, byte, byte>(0L, "{0} has major version {1} which is greater than current one ({2}) and will be ignored", item.Id, ewsStoreObject.ExchangeVersion.Major, ewsStoreObject.MaximumSupportedExchangeObjectVersion.Major); return(default(T)); } } if (!string.IsNullOrEmpty(ewsStoreObject.ItemClass) && !ewsStoreObject.ItemClass.Equals(item.ItemClass, StringComparison.OrdinalIgnoreCase)) { return(default(T)); } ewsStoreObject.CopyFromItemObject(item, this.RequestedServerVersion); if (ewsStoreObject.MaximumSupportedExchangeObjectVersion.IsOlderThan(ewsStoreObject.ExchangeVersion)) { ExTraceGlobals.StorageTracer.TraceWarning <ItemId, ExchangeObjectVersion, ExchangeObjectVersion>(0L, "{0} has version {1} which is greater than current one ({2}) and will be read-only", item.Id, ewsStoreObject.ExchangeVersion, ewsStoreObject.MaximumSupportedExchangeObjectVersion); ewsStoreObject.SetIsReadOnly(true); } ValidationError[] array = ewsStoreObject.ValidateRead(); ewsStoreObject.ResetChangeTracking(true); if (array.Length > 0) { foreach (ValidationError validationError in array) { PropertyValidationError propertyValidationError = validationError as PropertyValidationError; ExTraceGlobals.StorageTracer.TraceDebug((long)this.GetHashCode(), "Object '{0}' read from '{1}' failed validation. Attribute: '{2}'. Invalid data: '{3}'. Error message: '{4}'.", new object[] { ewsStoreObject.Identity, this.Mailbox.ToString() + "\\" + this.DefaultFolder.ToString(), (propertyValidationError != null) ? propertyValidationError.PropertyDefinition.Name : "<null>", (propertyValidationError != null) ? (propertyValidationError.InvalidData ?? "<null>") : "<null>", validationError.Description }); } } return((T)((object)this.FilterObject(ewsStoreObject))); }