Ejemplo n.º 1
0
        public void Delete(IConfigurable instance)
        {
            EwsStoreObject ewsStoreObject = (EwsStoreObject)instance;

            if (ewsStoreObject.IsReadOnly)
            {
                throw new InvalidOperationException("Can't delete read-only object.");
            }
            if (instance.ObjectState == ObjectState.Deleted)
            {
                throw new InvalidOperationException(ServerStrings.ExceptionObjectHasBeenDeleted);
            }
            Item item = this.BindItem(ewsStoreObject.Identity.EwsObjectId, PropertySet.IdOnly);

            if (item != null)
            {
                this.InvokeServiceCall(delegate()
                {
                    item.Delete(0);
                });
            }
            this.Cache.ClearItemCache(ewsStoreObject);
            ewsStoreObject.ResetChangeTracking();
            ewsStoreObject.MarkAsDeleted();
        }
 public virtual void ClearItemCache(EwsStoreObject ewsStoreObject)
 {
     if (this.AlternativeIdCacheEnabled && !string.IsNullOrEmpty(ewsStoreObject.AlternativeId))
     {
         this.alternativeId2Id.Remove(ewsStoreObject.AlternativeId);
     }
 }
 protected override EwsStoreObject FilterObject(EwsStoreObject ewsStoreObject)
 {
     ewsStoreObject = base.FilterObject(ewsStoreObject);
     if (ewsStoreObject != null && ((AsyncOperationNotification)ewsStoreObject).Type == AsyncOperationType.Unknown)
     {
         return(null);
     }
     return(ewsStoreObject);
 }
        public void DeleteAuditLogSearch(AuditLogSearchBase search)
        {
            EwsStoreObject ewsStoreObject = new EwsStoreObject();

            ewsStoreObject.propertyBag.SetField(EwsStoreObjectSchema.Identity, search[AuditLogSearchBaseEwsSchema.EwsItemId]);
            base.Delete(ewsStoreObject);
            search.ResetChangeTracking();
            search.MarkAsDeleted();
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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)));
        }
Ejemplo n.º 7
0
 protected virtual EwsStoreObject FilterObject(EwsStoreObject ewsStoreObject)
 {
     return(ewsStoreObject);
 }
Ejemplo n.º 8
0
        protected virtual IEnumerable <T> InternalFindPaged <T>(SearchFilter filter, FolderId rootId, bool deepSearch, SortBy[] sortBy, int pageSize, params ProviderPropertyDefinition[] properties) where T : IConfigurable, new()
        {
            Func <GetItemResponse, bool> func  = null;
            Func <GetItemResponse, Item> func2 = null;

            EwsStoreDataProvider.< > c__DisplayClass1b <T> CS$ < > 8__locals1 = new EwsStoreDataProvider.< > c__DisplayClass1b <T>();
            CS$ < > 8__locals1.filter      = filter;
            CS$ < > 8__locals1.rootId      = rootId;
            CS$ < > 8__locals1.< > 4__this = this;
            if (pageSize < 0 || pageSize > 1000)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, string.Format("pageSize should be between 1 and {0} or 0 to use the default page size: {1}", 1000, this.DefaultPageSize));
            }
            EwsStoreObject      dummyObject = (EwsStoreObject)((object)((default(T) == null) ? Activator.CreateInstance <T>() : default(T)));
            List <SearchFilter> filters     = new List <SearchFilter>();

            if (CS$ < > 8__locals1.filter != null)
            {
                filters.Add(CS$ < > 8__locals1.filter);
            }
            SearchFilter versioningFilter = dummyObject.VersioningFilter;

            if (versioningFilter != null)
            {
                filters.Add(versioningFilter);
            }
            SearchFilter itemClassFilter = dummyObject.ItemClassFilter;

            if (itemClassFilter != null)
            {
                filters.Add(itemClassFilter);
            }
            if (filters.Count == 1)
            {
                CS$ < > 8__locals1.filter = filters[0];
            }
            else if (filters.Count > 1)
            {
                CS$ < > 8__locals1.filter = new SearchFilter.SearchFilterCollection(0, filters.ToArray());
            }
            CS$ < > 8__locals1.itemView = new ItemView((pageSize == 0) ? this.DefaultPageSize : pageSize);
            if (sortBy != null && sortBy.Length > 0)
            {
                foreach (SortBy sortBy2 in sortBy)
                {
                    CS$ < > 8__locals1.itemView.OrderBy.Add(((EwsStoreObjectPropertyDefinition)sortBy2.ColumnDefinition).StorePropertyDefinition, (sortBy2.SortOrder == SortOrder.Ascending) ? 0 : 1);
                }
            }
            bool useBindItem = false;

            CS$ < > 8__locals1.propertySet = null;
            if (properties != null && properties.Length > 0)
            {
                CS$ < > 8__locals1.propertySet = this.CreatePropertySet(properties, out useBindItem);
            }
            else
            {
                CS$ < > 8__locals1.propertySet = this.CreatePropertySet <T>(out useBindItem);
            }
            if (useBindItem)
            {
                CS$ < > 8__locals1.itemView.PropertySet = new PropertySet(0);
            }
            else
            {
                CS$ < > 8__locals1.itemView.PropertySet = CS$ < > 8__locals1.propertySet;
            }
            for (;;)
            {
                EwsStoreDataProvider.< > c__DisplayClass1e <T> CS$ < > 8__locals2 = new EwsStoreDataProvider.< > c__DisplayClass1e <T>();
                CS$ < > 8__locals2.CS$ < > 8__locals1c = CS$ < > 8__locals1;
                FindItemsResults <Item> results = this.InvokeServiceCall <FindItemsResults <Item> >(() => CS$ < > 8__locals1.< > 4__this.Service.FindItems(CS$ < > 8__locals1.rootId ?? CS$ < > 8__locals1.< > 4__this.DefaultFolder, CS$ < > 8__locals1.filter, CS$ < > 8__locals1.itemView));
                CS$ < > 8__locals2.items = results.Items;
                if (useBindItem && results.Items.Count > 0)
                {
                    ServiceResponseCollection <GetItemResponse> serviceResponseCollection = this.InvokeServiceCall <ServiceResponseCollection <GetItemResponse> >(() => CS$ < > 8__locals2.CS$ < > 8__locals1c.< > 4__this.Service.BindToItems(from x in CS$ < > 8__locals2.items
                                                                                                                                                                                                                                               select x.Id, CS$ < > 8__locals2.CS$ < > 8__locals1c.propertySet));
                    EwsStoreDataProvider.< >      c__DisplayClass1e <T> CS$ < > 8__locals3 = CS$ < > 8__locals2;
                    IEnumerable <GetItemResponse> source = serviceResponseCollection;
                    if (func == null)
                    {
                        func = ((GetItemResponse x) => x.Item != null);
                    }
                    IEnumerable <GetItemResponse> source2 = source.Where(func);
                    if (func2 == null)
                    {
                        func2 = ((GetItemResponse x) => x.Item);
                    }
                    CS$ < > 8__locals3.items = source2.Select(func2);
                }
                foreach (Item item in CS$ < > 8__locals2.items)
                {
                    T instance = this.ObjectFromItem <T>(item);
                    if (instance != null)
                    {
                        yield return(instance);
                    }
                }
                if (!results.MoreAvailable)
                {
                    break;
                }
                CS$ < > 8__locals1.itemView.Offset = results.NextPageOffset.Value;
            }
            yield break;
        }