public Task <IReadOnlyList <EntityVersion <string, DateTime> > > GetAllVersions(IEnumerable <string> idsOfknownEntities)
        {
            var entities = new List <EntityVersion <string, DateTime> >();

            using (var taskFolderWrapper = CreateFolderWrapper())
            {
                bool isInstantSearchEnabled = false;

                try
                {
                    using (var store = GenericComObjectWrapper.Create(taskFolderWrapper.Inner.Store))
                    {
                        if (store.Inner != null)
                        {
                            isInstantSearchEnabled = store.Inner.IsInstantSearchEnabled;
                        }
                    }
                }
                catch (COMException)
                {
                    s_logger.Info("Can't access IsInstantSearchEnabled property of store, defaulting to false.");
                }
                using (var tableWrapper =
                           GenericComObjectWrapper.Create(
                               taskFolderWrapper.Inner.GetTable(
                                   _daslFilterProvider.GetTaskFilter(isInstantSearchEnabled))))
                {
                    var table = tableWrapper.Inner;
                    table.Columns.RemoveAll();
                    table.Columns.Add(c_entryIdColumnName);

                    while (!table.EndOfTable)
                    {
                        var row     = table.GetNextRow();
                        var entryId = (string)row[c_entryIdColumnName];
                        try
                        {
                            using (
                                var taskItemWrapper =
                                    GenericComObjectWrapper.Create((TaskItem)_mapiNameSpace.GetItemFromID(entryId, _folderStoreId)))
                            {
                                entities.Add(EntityVersion.Create(taskItemWrapper.Inner.EntryID,
                                                                  taskItemWrapper.Inner.LastModificationTime));
                            }
                        }
                        catch (COMException ex)
                        {
                            s_logger.Error("Could not fetch TaskItem, skipping.", ex);
                        }
                    }
                }
            }

            return(Task.FromResult <IReadOnlyList <EntityVersion <string, DateTime> > > (entities));
        }
Ejemplo n.º 2
0
        public Task <IReadOnlyList <EntityVersion <string, DateTime> > > GetAllVersions(IEnumerable <string> idsOfknownEntities, int context)
        {
            List <EntityVersion <string, DateTime> >           tasks;
            Func <TaskItem, EntityVersion <string, DateTime> > selector = a => new EntityVersion <string, DateTime>(a.EntryID, a.LastModificationTime);

            using (var taskFolderWrapper = CreateFolderWrapper())
            {
                bool isInstantSearchEnabled = false;

                try
                {
                    using (var store = GenericComObjectWrapper.Create(taskFolderWrapper.Inner.Store))
                    {
                        if (store.Inner != null)
                        {
                            isInstantSearchEnabled = store.Inner.IsInstantSearchEnabled;
                        }
                    }
                }
                catch (COMException)
                {
                    s_logger.Info("Can't access IsInstantSearchEnabled property of store, defaulting to false.");
                }

                var filterBuilder = new StringBuilder(_daslFilterProvider.GetTaskFilter(isInstantSearchEnabled));
                if (_configuration.UseTaskCategoryAsFilter)
                {
                    OutlookEventRepository.AddCategoryFilter(filterBuilder, _configuration.TaskCategory, _configuration.InvertTaskCategoryFilter);
                }

                s_logger.InfoFormat("Using Outlook DASL filter: {0}", filterBuilder.ToString());

                tasks = QueryFolder(_mapiNameSpace, taskFolderWrapper, filterBuilder, selector);
            }

            if (_configuration.UseTaskCategoryAsFilter)
            {
                var knownEntitesThatWereFilteredOut = idsOfknownEntities.Except(tasks.Select(e => e.Id));
                tasks.AddRange(
                    knownEntitesThatWereFilteredOut
                    .Select(id => _mapiNameSpace.GetEntryOrNull <TaskItem>(id, _folderId, _folderStoreId))
                    .Where(i => i != null)
                    .ToSafeEnumerable()
                    .Select(selector));
            }

            return(Task.FromResult <IReadOnlyList <EntityVersion <string, DateTime> > > (tasks));
        }
        public Task <IEnumerable <EntityVersion <string, DateTime> > > GetAllVersions(IEnumerable <string> idsOfknownEntities, int context, IGetVersionsLogger logger)
        {
            List <EntityVersion <string, DateTime> > tasks;

            using (var taskFolderWrapper = CreateFolderWrapper())
            {
                bool isInstantSearchEnabled = false;

                try
                {
                    using (var store = GenericComObjectWrapper.Create(taskFolderWrapper.Inner.Store))
                    {
                        if (store.Inner != null)
                        {
                            isInstantSearchEnabled = store.Inner.IsInstantSearchEnabled;
                        }
                    }
                }
                catch (COMException)
                {
                    s_logger.Info("Can't access IsInstantSearchEnabled property of store, defaulting to false.");
                }

                var filterBuilder = new StringBuilder(_daslFilterProvider.GetTaskFilter(isInstantSearchEnabled));
                if (_configuration.UseTaskCategoryAsFilter)
                {
                    OutlookEventRepository.AddCategoryFilter(filterBuilder, _configuration.TaskCategory, _configuration.InvertTaskCategoryFilter, _configuration.IncludeEmptyTaskCategoryFilter);
                }

                s_logger.DebugFormat("Using Outlook DASL filter: {0}", filterBuilder.ToString());

                tasks = _queryFolderStrategy.QueryTaskFolder(_session, taskFolderWrapper.Inner, filterBuilder.ToString(), logger);
            }

            if (_configuration.IsCategoryFilterSticky && _configuration.UseTaskCategoryAsFilter)
            {
                var knownEntitesThatWereFilteredOut = idsOfknownEntities.Except(tasks.Select(e => e.Id));
                tasks.AddRange(
                    knownEntitesThatWereFilteredOut
                    .Select(id => _session.GetTaskItemOrNull(id, _folderId, _folderStoreId))
                    .Where(i => i != null)
                    .ToSafeEnumerable()
                    .Select(t => new EntityVersion <string, DateTime> (t.EntryID, t.LastModificationTime.ToUniversalTime())));
            }

            return(Task.FromResult <IEnumerable <EntityVersion <string, DateTime> > > (tasks));
        }