public RecentFilesViewModel(IRecentFileCollection recentFileCollection, ISchedulerProvider schedulerProvider)
        {
            _recentFileCollection = recentFileCollection;
            if (recentFileCollection == null)
            {
                throw new ArgumentNullException(nameof(recentFileCollection));
            }
            if (schedulerProvider == null)
            {
                throw new ArgumentNullException(nameof(schedulerProvider));
            }

            ReadOnlyObservableCollection <RecentFileProxy> data;
            var recentLoader = recentFileCollection.Items
                               .Connect()
                               .Transform(rf => new RecentFileProxy(rf, toOpen =>
            {
                _fileOpenRequest.OnNext(new FileInfo(toOpen.Name));
            },
                                                                    recentFileCollection.Remove))
                               .Sort(SortExpressionComparer <RecentFileProxy> .Descending(proxy => proxy.Timestamp))
                               .ObserveOn(schedulerProvider.MainThread)
                               .Bind(out data)
                               .Subscribe();

            Files = data;

            _cleanUp = Disposable.Create(() =>
            {
                recentLoader.Dispose();
                _fileOpenRequest.OnCompleted();
            });
        }
예제 #2
0
        public RecentFilesViewModel(IRecentFileCollection recentFileCollection, ISchedulerProvider schedulerProvider)
        {
            _recentFileCollection = recentFileCollection;
            if (recentFileCollection == null) throw new ArgumentNullException(nameof(recentFileCollection));
            if (schedulerProvider == null) throw new ArgumentNullException(nameof(schedulerProvider));
            
            ReadOnlyObservableCollection<RecentFileProxy> data;
            var recentLoader = recentFileCollection.Items
                .Connect()
                .Transform(rf => new RecentFileProxy(rf, toOpen =>
                                                            {
                                                                _fileOpenRequest.OnNext(new FileInfo(toOpen.Name));
                                                            },
                                                            recentFileCollection.Remove))
                .Sort(SortExpressionComparer<RecentFileProxy>.Descending(proxy => proxy.Timestamp))
                .ObserveOn(schedulerProvider.MainThread)
                .Bind(out data)
                .Subscribe();

            Files = data;

            _cleanUp = Disposable.Create(() =>
            {
                recentLoader.Dispose();
                _fileOpenRequest.OnCompleted();
            }) ;
        }