Example #1
0
        public async Task <IReadOnlyList <EntityVersion <WebResourceName, string> > > GetAllVersions(IEnumerable <WebResourceName> idsOfknownEntities)
        {
            using (AutomaticStopwatch.StartInfo(s_logger, "CalDavRepository.GetVersions"))
            {
                switch (_entityType)
                {
                case EntityType.Event:

                    return(await _calDavDataAccess.GetEventVersions(_dateTimeRangeProvider.GetRange()));

                case EntityType.Todo:
                    return(await _calDavDataAccess.GetTodoVersions(_dateTimeRangeProvider.GetRange()));

                default:
                    throw new NotImplementedException(string.Format("EntityType '{0}' not implemented.", _entityType));
                }
            }
        }
Example #2
0
        public Task <IReadOnlyList <EntityIdWithVersion <Uri, string> > > GetVersions()
        {
            using (AutomaticStopwatch.StartInfo(s_logger, "CalDavRepository.GetVersions"))
            {
                switch (_entityType)
                {
                case EntityType.Event:

                    return(_calDavDataAccess.GetEvents(_dateTimeRangeProvider.GetRange()));

                case EntityType.Todo:
                    return(_calDavDataAccess.GetTodos(_dateTimeRangeProvider.GetRange()));

                default:
                    throw new NotImplementedException(string.Format("EntityType '{0}' not implemented.", _entityType));
                }
            }
        }
Example #3
0
        private Task <IReadOnlyList <T> > GetAll <T> (IEnumerable <string> idsOfknownEntities, IEventSynchronizationContext context, Func <AppointmentItem, T> selector)
            where T : IEntity <string>
        {
            var range = _dateTimeRangeProvider.GetRange();

            List <T> events;

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

                try
                {
                    using (var store = GenericComObjectWrapper.Create(calendarFolderWrapper.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.");
                }

                // Table Filtering in the MSDN: https://msdn.microsoft.com/EN-US/library/office/ff867581.aspx
                var filterBuilder = new StringBuilder(_daslFilterProvider.GetAppointmentFilter(isInstantSearchEnabled));

                if (range.HasValue)
                {
                    filterBuilder.AppendFormat(" And \"urn:schemas:calendar:dtstart\" < '{0}' And \"urn:schemas:calendar:dtend\" > '{1}'", ToOutlookDateString(range.Value.To), ToOutlookDateString(range.Value.From));
                }
                if (_configuration.UseEventCategoryAsFilter)
                {
                    AddCategoryFilter(filterBuilder, _configuration.EventCategory, _configuration.InvertEventCategoryFilter);
                }

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

                events = QueryFolder(_mapiNameSpace, calendarFolderWrapper, filterBuilder, selector);
            }

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

            return(Task.FromResult <IReadOnlyList <T> > (events));
        }
        public Task <IReadOnlyList <EntityIdWithVersion <string, DateTime> > > GetVersions()
        {
            var events = new List <EntityIdWithVersion <string, DateTime> >();

            var    range = _dateTimeRangeProvider.GetRange();
            object filter;

            if (range.HasValue)
            {
                filter = String.Format("[Start] < '{0}' And [End] > '{1}'", ToOutlookDateString(range.Value.To), ToOutlookDateString(range.Value.From));
            }
            else
            {
                filter = Type.Missing;
            }

            using (var calendarFolderWrapper = CreateFolderWrapper())
            {
                using (var tableWrapper = GenericComObjectWrapper.Create((Table)calendarFolderWrapper.Inner.GetTable(filter)))
                {
                    var table = tableWrapper.Inner;
                    table.Columns.RemoveAll();
                    table.Columns.Add(c_entryIdColumnName);

                    var storeId = calendarFolderWrapper.Inner.StoreID;

                    while (!table.EndOfTable)
                    {
                        var row     = table.GetNextRow();
                        var entryId = (string)row[c_entryIdColumnName];
                        using (var appointmentWrapper = GenericComObjectWrapper.Create((AppointmentItem)_mapiNameSpace.GetItemFromID(entryId, storeId)))
                        {
                            events.Add(new EntityIdWithVersion <string, DateTime> (appointmentWrapper.Inner.EntryID, appointmentWrapper.Inner.LastModificationTime));
                        }
                    }
                }
            }

            return(Task.FromResult <IReadOnlyList <EntityIdWithVersion <string, DateTime> > > (events));
        }
        public Task <IReadOnlyList <EntityVersion <string, DateTime> > > GetAllVersions(IEnumerable <string> idsOfknownEntities)
        {
            var range = _dateTimeRangeProvider.GetRange();

            // Table Filtering in the MSDN: https://msdn.microsoft.com/EN-US/library/office/ff867581.aspx
            var filterBuilder = new StringBuilder(PR_MESSAGE_CLASS_DASLFILTER);

            if (range.HasValue)
            {
                filterBuilder.AppendFormat(" And \"urn:schemas:calendar:dtstart\" < '{0}' And \"urn:schemas:calendar:dtend\" > '{1}'", ToOutlookDateString(range.Value.To), ToOutlookDateString(range.Value.From));
            }
            if (_configuration.UseEventCategoryAsFilter)
            {
                AddCategoryFilter(filterBuilder, _configuration.EventCategory);
            }
            s_logger.InfoFormat("Using Outlook DASL filter: {0}", filterBuilder.ToString());

            List <EntityVersion <string, DateTime> > events;

            using (var calendarFolderWrapper = CreateFolderWrapper())
            {
                events = QueryFolder(_mapiNameSpace, calendarFolderWrapper, filterBuilder);
            }

            if (_configuration.UseEventCategoryAsFilter)
            {
                var knownEntitesThatWereFilteredOut = idsOfknownEntities.Except(events.Select(e => e.Id));
                events.AddRange(
                    knownEntitesThatWereFilteredOut
                    .Select(GetAppointmentItemOrNull)
                    .Where(i => i != null)
                    .ToSafeEnumerable()
                    .Select(c => EntityVersion.Create(c.EntryID, c.LastModificationTime)));
            }

            return(Task.FromResult <IReadOnlyList <EntityVersion <string, DateTime> > > (events));
        }