Example #1
0
        /// <summary>
        /// Gets filters for Exchange data query.
        /// </summary>
        /// <returns>Filter instance.</returns>
        private Exchange.SearchFilter.SearchFilterCollection GetItemsSearchFilters()
        {
            var itemsFilter = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And)
            {
                new Exchange.SearchFilter.IsEqualTo(Exchange.ItemSchema.ItemClass, ExchangeConsts.TaskItemClassName)
            };
            DateTime lastSyncDateUtc          = TimeZoneInfo.ConvertTimeToUtc(UserSettings.LastSyncDate, TimeZone);
            DateTime importActivitiesFromDate = UserSettings.ImportActivitiesFrom;

            if (UserSettings.ImportActivitiesFrom != DateTime.MinValue)
            {
                itemsFilter.Add(new Exchange.SearchFilter.IsGreaterThanOrEqualTo(
                                    Exchange.TaskSchema.LastModifiedTime, importActivitiesFromDate));
            }
            if (UserSettings.LastSyncDate != DateTime.MinValue)
            {
                var lastSyncDateUtcFilter = new Exchange.SearchFilter.IsGreaterThan(
                    Exchange.ItemSchema.LastModifiedTime, lastSyncDateUtc.ToLocalTime());
                var filterCollection       = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or);
                var customPropSetFilter    = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty);
                var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter);
                filterCollection.AddRange(new List <Exchange.SearchFilter> {
                    lastSyncDateUtcFilter,
                    notCustomPropSetFilter
                });
                itemsFilter.Add(filterCollection);
            }
            return(itemsFilter);
        }
Example #2
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}'");
            }
        }
Example #3
0
        /// <summary>
        /// Gets filters for Exchange data query.
        /// </summary>
        /// <returns>Filter instance.</returns>
        private Exchange.SearchFilter GetItemsSearchFilters(SyncContext context = null)
        {
            Exchange.SearchFilter filter      = null;
            DateTime lastSyncDateUtc          = TimeZoneInfo.ConvertTimeToUtc(UserSettings.LastSyncDate, TimeZone);
            DateTime importActivitiesFromDate = UserSettings.ImportActivitiesFrom;

            context?.LogInfo(SyncAction.None, SyncDirection.Download, "lastSyncDateUtc = {0}, importActivitiesFromDate = {1}",
                             lastSyncDateUtc, importActivitiesFromDate);
            if (lastSyncDateUtc != DateTime.MinValue && UserSettings.ImportActivitiesFrom != DateTime.MinValue)
            {
                var lastSyncDateUtcFilter = new Exchange.SearchFilter.IsGreaterThan(
                    Exchange.ItemSchema.LastModifiedTime, lastSyncDateUtc.ToLocalTime());
                var filterCollection       = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or);
                var customPropSetFilter    = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty);
                var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter);
                filterCollection.AddRange(new List <Exchange.SearchFilter> {
                    lastSyncDateUtcFilter,
                    notCustomPropSetFilter
                });
                if (context != null && GetExchangeRecurringAppointmentsSupported(context.UserConnection))
                {
                    return(filterCollection);
                }
                var allFilterCollection            = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.And);
                var importActivitiesFromDateFilter = new Exchange.SearchFilter.IsGreaterThanOrEqualTo(
                    Exchange.AppointmentSchema.Start, importActivitiesFromDate);
                allFilterCollection.AddRange(new List <Exchange.SearchFilter> {
                    importActivitiesFromDateFilter,
                    filterCollection
                });
                filter = allFilterCollection;
            }
            else if (lastSyncDateUtc != DateTime.MinValue && UserSettings.ImportActivitiesFrom == DateTime.MinValue)
            {
                filter = new Exchange.SearchFilter.IsGreaterThan(
                    Exchange.ItemSchema.LastModifiedTime, lastSyncDateUtc.ToLocalTime());
            }
            else if (lastSyncDateUtc == DateTime.MinValue && UserSettings.ImportActivitiesFrom != DateTime.MinValue)
            {
                filter = new Exchange.SearchFilter.IsGreaterThanOrEqualTo(
                    Exchange.AppointmentSchema.Start, importActivitiesFromDate);
            }
            return(filter);
        }
Example #4
0
 public Exchange.SearchFilter GetContactsFilters()
 {
     if (UserSettings.LastSyncDate != DateTime.MinValue)
     {
         DateTime lastSyncDateUtc =
             TimeZoneInfo.ConvertTimeToUtc(UserSettings.LastSyncDate, TimeZone);
         var lastSyncDateUtcFilter = new Exchange.SearchFilter.IsGreaterThan(
             Exchange.ItemSchema.LastModifiedTime, lastSyncDateUtc.ToLocalTime());
         var filterCollection       = new Exchange.SearchFilter.SearchFilterCollection(Exchange.LogicalOperator.Or);
         var customPropSetFilter    = new Exchange.SearchFilter.Exists(ExchangeUtilityImpl.LocalIdProperty);
         var notCustomPropSetFilter = new Exchange.SearchFilter.Not(customPropSetFilter);
         filterCollection.AddRange(new List <Exchange.SearchFilter> {
             lastSyncDateUtcFilter,
             notCustomPropSetFilter
         });
         return(filterCollection);
     }
     return(null);
 }
Example #5
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);
        }