예제 #1
0
        public ApplicationDataUpdateWhenPathReferenceCountChanged(
            IEventAggregator eventAggregator,
            RecentlyAccessManager recentlyAccessManager,
            BookmarkManager bookmarkManager,
            StorageItemSearchManager storageItemSearchManager,
            FolderContainerTypeManager folderContainerTypeManager,
            ThumbnailManager thumbnailManager,
            SecondaryTileManager secondaryTileManager,
            FolderLastIntractItemManager folderLastIntractItemManager
            )
        {
            _eventAggregator              = eventAggregator;
            _recentlyAccessManager        = recentlyAccessManager;
            _bookmarkManager              = bookmarkManager;
            _storageItemSearchManager     = storageItemSearchManager;
            _folderContainerTypeManager   = folderContainerTypeManager;
            _thumbnailManager             = thumbnailManager;
            _folderLastIntractItemManager = folderLastIntractItemManager;
            _eventAggregator.GetEvent <PathReferenceCountManager.PathReferenceAddedEvent>()
            .Subscribe(args =>
            {
            }
                       , keepSubscriberReferenceAlive: true
                       )
            .AddTo(_disposables);

            _eventAggregator.GetEvent <PathReferenceCountManager.PathReferenceRemovedEvent>()
            .Subscribe(async args =>
            {
                _recentlyAccessManager.Delete(args.Path);
                _bookmarkManager.RemoveBookmark(args.Path);
                _storageItemSearchManager.Remove(args.Path);
                _folderContainerTypeManager.Delete(args.Path);
                _folderLastIntractItemManager.Remove(args.Path);
                await _thumbnailManager.DeleteFromPath(args.Path);
                await secondaryTileManager.RemoveSecondaryTile(args.Path);
            }
                       , keepSubscriberReferenceAlive: true
                       )
            .AddTo(_disposables);
        }
예제 #2
0
        public override async Task OnNavigatedToAsync(INavigationParameters parameters)
        {
            _navigationDisposables = new CompositeDisposable();
            if (!_foldersInitialized)
            {
                _foldersInitialized = true;

                Folders.Add(new StorageItemViewModel(_sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager)
                {
                });
                await foreach (var item in _sourceStorageItemsRepository.GetParsistantItems())
                {
                    var storageItemImageSource = new StorageItemImageSource(item.item, _thumbnailManager);
                    if (storageItemImageSource.ItemTypes == Models.Domain.StorageItemTypes.Folder)
                    {
                        Folders.Add(new StorageItemViewModel(storageItemImageSource, item.token, _sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager));
                    }
                    else
                    {
                        //throw new NotSupportedException();
                    }
                }
            }
            else
            {
                Folders.ForEach(x => x.UpdateLastReadPosition());
            }

            async Task <StorageItemViewModel> ToStorageItemViewModel(RecentlyAccessManager.RecentlyAccessEntry entry)
            {
                //_currentFolderItem =
                var token       = _PathReferenceCountManager.GetToken(entry.Path);
                var storageItem = await _sourceStorageItemsRepository.GetStorageItemFromPath(token, entry.Path);

                var storageItemImageSource = new StorageItemImageSource(storageItem, _thumbnailManager);

                return(new StorageItemViewModel(storageItemImageSource, token, _sourceStorageItemsRepository, _folderListingSettings, _bookmarkManager));
            }

            var recentlyAccessItems = _recentlyAccessManager.GetItemsSortWithRecently(10);

            if (_LastUpdatedRecentlyAccessEnties != null)
            {
                var idSet = _LastUpdatedRecentlyAccessEnties.Select(x => x.Path).ToHashSet();
                {
                    var addNewItems = recentlyAccessItems.TakeWhile(x => !idSet.Contains(x.Path)).Reverse();
                    foreach (var newItem in addNewItems)
                    {
                        var alreadyAdded = RecentlyItems.FirstOrDefault(x => x.Path == newItem.Path);
                        if (alreadyAdded != null)
                        {
                            RecentlyItems.Remove(alreadyAdded);
                            RecentlyItems.Insert(0, alreadyAdded);
                        }
                        else
                        {
                            RecentlyItems.Insert(0, await ToStorageItemViewModel(newItem));
                        }
                    }
                }
                {
                    var deletedItems = recentlyAccessItems.OrderByDescending(x => x.LastAccess).TakeWhile(x => !idSet.Contains(x.Path));
                    foreach (var i in Enumerable.Range(0, deletedItems.Count()))
                    {
                        if (RecentlyItems.Count == 0)
                        {
                            break;
                        }
                        if (RecentlyItems.Count <= 10)
                        {
                            break;
                        }

                        RecentlyItems.RemoveAt(RecentlyItems.Count - 1);
                    }
                }
            }
            else
            {
                foreach (var item in recentlyAccessItems)
                {
                    try
                    {
                        RecentlyItems.Add(await ToStorageItemViewModel(item));
                    }
                    catch
                    {
                        _recentlyAccessManager.Delete(item);
                    }
                }
            }

            _LastUpdatedRecentlyAccessEnties = recentlyAccessItems;

            await base.OnNavigatedToAsync(parameters);
        }