private void SwitchTaskCategories(ChangedOptions changedOption, string oldCategory, string newCategory, string eventId)
        {
            using (var taskWrapper = new TaskItemWrapper(
                       (TaskItem)_session.GetItemFromID(eventId, changedOption.New.OutlookFolderStoreId),
                       entryId => (TaskItem)_session.GetItemFromID(entryId, changedOption.New.OutlookFolderStoreId)))
            {
                var categories = taskWrapper.Inner.Categories
                                 .Split(new[] { CultureInfo.CurrentCulture.TextInfo.ListSeparator }, StringSplitOptions.RemoveEmptyEntries)
                                 .Select(c => c.Trim());

                taskWrapper.Inner.Categories = string.Join(
                    CultureInfo.CurrentCulture.TextInfo.ListSeparator,
                    categories
                    .Except(new[] { oldCategory })
                    .Concat(new[] { newCategory })
                    .Distinct());

                taskWrapper.Inner.Save();
            }
        }
Exemplo n.º 2
0
        private void SwitchTaskCategories(ChangedOptions changedOption, string oldCategory, string newCategory)
        {
            using (var taskFolderWrapper = GenericComObjectWrapper.Create(
                       (Folder)_session.GetFolderFromID(changedOption.New.OutlookFolderEntryId, changedOption.New.OutlookFolderStoreId)))
            {
                s_logger.Info($"Switching category of items in folder '{taskFolderWrapper.Inner.Name}' from '{oldCategory}' to '{newCategory}', due to changes in profile '{changedOption.New.Name}' (OptionId:'{changedOption.New.Id}' FolderId:'{changedOption.New.OutlookFolderEntryId}' StoreId:'{changedOption.New.OutlookFolderStoreId}')");

                var 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));
                OutlookEventRepository.AddCategoryFilter(filterBuilder, oldCategory, false, false);
                var taskIds = _queryFolderStrategyWrapper.QueryTaskFolder(_session, taskFolderWrapper.Inner, filterBuilder.ToString()).Select(e => e.Id);
                // todo concat Ids from cache

                foreach (var taskId in taskIds)
                {
                    try
                    {
                        SwitchTaskCategories(changedOption, oldCategory, newCategory, taskId);
                    }
                    catch (Exception x)
                    {
                        s_logger.Error(null, x);
                    }
                }
            }
        }
        private void SwitchEventCategories(ChangedOptions changedOption, string oldCategory, string newCategory)
        {
            using (var calendarFolderWrapper = GenericComObjectWrapper.Create(
                       (Folder)_session.GetFolderFromID(changedOption.New.OutlookFolderEntryId, changedOption.New.OutlookFolderStoreId)))
            {
                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.");
                }
                var filterBuilder = new StringBuilder(_daslFilterProvider.GetAppointmentFilter(isInstantSearchEnabled));
                OutlookEventRepository.AddCategoryFilter(filterBuilder, oldCategory, false);
                var eventIds = OutlookEventRepository.QueryFolder(_session, calendarFolderWrapper, filterBuilder).Select(e => e.Id);
                // todo concat Ids from cache

                foreach (var eventId in eventIds)
                {
                    try
                    {
                        SwitchEventCategories(changedOption, oldCategory, newCategory, eventId);
                    }
                    catch (Exception x)
                    {
                        s_logger.Error(null, x);
                    }
                }
            }
        }
        private void SwitchCategories(ChangedOptions changedOption, string oldCategory, string newCategory)
        {
            using (var calendarFolderWrapper = GenericComObjectWrapper.Create(
                       (Folder)_session.GetFolderFromID(changedOption.New.OutlookFolderEntryId, changedOption.New.OutlookFolderStoreId)))
            {
                var filterBuilder = new StringBuilder(OutlookEventRepository.PR_MESSAGE_CLASS_DASLFILTER);
                OutlookEventRepository.AddCategoryFilter(filterBuilder, oldCategory);
                var eventIds = OutlookEventRepository.QueryFolder(_session, calendarFolderWrapper, filterBuilder).Select(e => e.Id);
                // todo concat Ids from cache

                foreach (var eventId in eventIds)
                {
                    try
                    {
                        SwitchCategories(changedOption, oldCategory, newCategory, eventId);
                    }
                    catch (Exception x)
                    {
                        s_logger.Error(null, x);
                    }
                }
            }
        }