Пример #1
0
        /// <summary>
        /// <see cref="ExchangeSyncProvider.FillItemsFilterCollection"/>
        /// </summary>
        protected override void FillItemsFilterCollection()
        {
            _itemsFilterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And);
            var draftFilter = new Exchange.SearchFilter.IsNotEqualTo(Exchange.ItemSchema.IsDraft, true);

            _itemsFilterCollection.Add(draftFilter);
            if (_userConnection.GetIsFeatureEnabled("SetEmailSynchronizedInExchange"))
            {
                var customPropSetFilter    = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty);
                var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter);
                _itemsFilterCollection.Add(notCustomPropSetFilter);
            }
            DateTime loadEmailsFromDate = LoadEmailsFromDate != DateTime.MinValue
                                ? LoadEmailsFromDate
                                : UserSettings.LastSyncDate;

            LogError($"LoadEmailsFromDate = '{LoadEmailsFromDate}', LastSyncDate = '{UserSettings.LastSyncDate}', result = '{loadEmailsFromDate}'");
            if (loadEmailsFromDate != DateTime.MinValue)
            {
                var localLastSyncDate = GetLastSyncDate(loadEmailsFromDate);
                var itemsFilter       = new Exchange.SearchFilter.IsGreaterThan(Exchange.ItemSchema.LastModifiedTime,
                                                                                localLastSyncDate);
                _itemsFilterCollection.Add(itemsFilter);
                LogError($"LoadEmailsFromDate filter adedd, filter date '{localLastSyncDate}'");
            }
        }
Пример #2
0
        public IEnumerable <IRemoteItem> EnumerateChangesOld(SyncContext context)
        {
            base.EnumerateChanges(context);
            var result  = new List <IRemoteItem>();
            var folders = new List <Exchange.Folder>();

            if (UserSettings.LoadAll)
            {
                Exchange.Folder rootFolder = Exchange.Folder.Bind(Service, Exchange.WellKnownFolderName.MsgFolderRoot);
                var             filter     = new Exchange.SearchFilter.IsEqualTo(
                    Exchange.FolderSchema.FolderClass, ExchangeConsts.NoteFolderClassName);
                folders.GetAllFoldersByFilter(rootFolder, filter);
            }
            else
            {
                folders = SafeBindFolders(Service, UserSettings.RemoteFolderUIds.Keys, context);
            }
            var itemsFilterCollection = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And);
            var draftFilter           = new Exchange.SearchFilter.IsNotEqualTo(Exchange.ItemSchema.IsDraft, true);

            itemsFilterCollection.Add(draftFilter);
            DateTime loadEmailsFromDate = LoadEmailsFromDate != DateTime.MinValue
                                ? LoadEmailsFromDate
                                : UserSettings.LastSyncDate;

            if (loadEmailsFromDate != DateTime.MinValue)
            {
                var localLastSyncDate = GetLastSyncDate(loadEmailsFromDate);
                var itemsFilter       = new Exchange.SearchFilter.IsGreaterThan(Exchange.ItemSchema.LastModifiedTime,
                                                                                localLastSyncDate);
                _itemsFilterCollection.Add(itemsFilter);
            }
            FilterDeprecatedFolders(ref folders);
            foreach (var noteFolder in folders)
            {
                var activityFolderIds = new List <Guid>();
                if (UserSettings.RootFolderId != Guid.Empty)
                {
                    activityFolderIds.Add(UserSettings.RootFolderId);
                }
                var folderId = GetFolderId(noteFolder);
                if (UserSettings.RemoteFolderUIds.ContainsKey(folderId))
                {
                    activityFolderIds.Add(UserSettings.RemoteFolderUIds[folderId]);
                }
                Exchange.PropertySet idOnlyPropertySet = new Exchange.PropertySet(Exchange.BasePropertySet.IdOnly);
                var itemView = new Exchange.ItemView(PageItemCount)
                {
                    PropertySet = idOnlyPropertySet
                };
                Exchange.FindItemsResults <Exchange.Item> itemCollection;
                do
                {
                    itemCollection = GetFolderItemsByFilter(noteFolder, itemsFilterCollection, itemView);
                    if (itemCollection == null)
                    {
                        break;
                    }
                    result.AddRange(GetEmailsFromCollection(itemCollection, activityFolderIds));
                } while (itemCollection.MoreAvailable);
            }
            return(result);
        }