Exemplo n.º 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);
        }
Exemplo n.º 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}'");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
 }