Exemplo n.º 1
0
        public BookmarkInfoViewModel(IOrderBuilder orderBuilder, IBookmarkInfo bookmarkInfo)
        {
            this.LoadedCommand = new AsyncReactiveCommand()
                                 .WithSubscribe(async() =>
            {
                await orderBuilder.From("LoadingBookmarkSummary")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                                 .AddTo(this.CompositeDisposable);

            this.Title = bookmarkInfo.ObserveProperty(x => x.Title)
                         .ObserveOnUIDispatcher()
                         .ToReadOnlyReactivePropertySlim()
                         .AddTo(this.CompositeDisposable);

            this.Writer = bookmarkInfo.ObserveProperty(x => x.Writer)
                          .ObserveOnUIDispatcher()
                          .ToReadOnlyReactivePropertySlim()
                          .AddTo(this.CompositeDisposable);

            this.ChapterCount = bookmarkInfo.Chapters.ObserveProperty(x => x.Count)
                                .ObserveOnUIDispatcher()
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.CompositeDisposable);

            this.BookmarkedDate = bookmarkInfo.ObserveProperty(x => x.BookmarkedDate)
                                  .Select(x => $"{x}")
                                  .ObserveOnUIDispatcher()
                                  .ToReadOnlyReactivePropertySlim()
                                  .AddTo(this.CompositeDisposable);

            this.Updating = bookmarkInfo.ObserveProperty(x => x.Status)
                            .Select(x => x == BookmarkInfoStatus.SummaryDownloading || x == BookmarkInfoStatus.ChapterDownloading || x == BookmarkInfoStatus.SummaryLoading || x == BookmarkInfoStatus.ChapterLoading)
                            .ObserveOnUIDispatcher()
                            .ToReadOnlyReactivePropertySlim()
                            .AddTo(this.CompositeDisposable);

            this.UpdateCommand = new AsyncReactiveCommand()
                                 .WithSubscribe(async() =>
            {
                await orderBuilder.From("UpdatingBookmarkChapter")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                                 .AddTo(this.CompositeDisposable);

            this.ReadCommand = new AsyncReactiveCommand()
                               .WithSubscribe(async() =>
            {
                Transitioner.MoveNextCommand.Execute(null, null);
                await orderBuilder.From("RequestingBookmark")
                .With("Id", bookmarkInfo.Id)
                .DispatchAsync();
            })
                               .AddTo(this.CompositeDisposable);
        }
Exemplo n.º 2
0
        public NewBookmarkDialogViewModel(IOrderBuilder orderBuilder, ILoadableBookmarkService loadableBookmarkService)
        {
            this.Ncode = new ReactiveProperty <string>("")
                         .SetValidateNotifyError(x => string.IsNullOrWhiteSpace(x) ? "Empty" : null)
                         .SetValidateNotifyError(x => loadableBookmarkService.Bookmarks.Any(b => b.Ncode == x) ? "Already has !" : null);

            this.AcceptCommand = this.Ncode.ObserveHasErrors
                                 .Select(x => !x)
                                 .ObserveOnUIDispatcher()
                                 .ToAsyncReactiveCommand();

            this.AcceptCommand.Subscribe(async() =>
            {
                MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand.Execute(null, null);
                await orderBuilder.From("DownloadingBookmarkInfo")
                .With("Ncode", this.Ncode.Value)
                .DispatchAsync();
                this.Ncode.Value = "";
            });

            this.CancelCommand.Subscribe(async() =>
            {
                MaterialDesignThemes.Wpf.DialogHost.CloseDialogCommand.Execute(null, null);
                this.Ncode.Value = "";
            });
        }
Exemplo n.º 3
0
        public ChapterViewModel(IOrderBuilder orderBuilder, ILoadableBookmarkService loadableBookmarkService, IChapter chapter)
        {
            this.Id = chapter.Id;

            this.LoadedCommand = new AsyncReactiveCommand()
                                 .WithSubscribe(async() =>
            {
                if (isLoaded)
                {
                    return;
                }
                isLoaded = true;
                await orderBuilder.From("LoadingChapterTitle")
                .With("Id", chapter.Id)
                .DispatchAsync();
            })
                                 .AddTo(this.CompositeDisposable);

            this.IsSelected = new ReactivePropertySlim <bool>().AddTo(this.CompositeDisposable);

            Observable.FromEventPattern <ChapterRequestEventArgs>(h => loadableBookmarkService.ChapterRequested += h, h => loadableBookmarkService.ChapterRequested -= h)
            .Select(x => x.EventArgs.Chapter != null && x.EventArgs.Chapter.Id == chapter.Id)
            .ObserveOnUIDispatcher()
            .Subscribe(x => this.IsSelected.Value = x)
            .AddTo(this.CompositeDisposable);

            this.Title = chapter.ObserveProperty(x => x.Title)
                         .ObserveOnUIDispatcher()
                         .ToReadOnlyReactivePropertySlim()
                         .AddTo(this.CompositeDisposable);

            this.Status = chapter.ObserveProperty(x => x.Status)
                          .Select(x => x.ToString())
                          .ObserveOnUIDispatcher()
                          .ToReadOnlyReactivePropertySlim()
                          .AddTo(this.CompositeDisposable);

            this.IsSelected.Where(x => x).Take(1).SelectMany(x =>
            {
                return(orderBuilder.From("LoadingChapterContent")
                       .With("Id", chapter.Id)
                       .DispatchAsync()
                       .ToObservable());
            })
            .Subscribe()
            .AddTo(this.CompositeDisposable);
        }
Exemplo n.º 4
0
 public static IOrderDiapatchable From <TOrder>(this IOrderBuilder self) where TOrder : IOrder
 => self.From(typeof(TOrder));
Exemplo n.º 5
0
        public ReadingRoomViewModel(IOrderBuilder orderBuilder, ILoadableBookmarkService loadableBookmarkService, IBookmarkInfo bookmarkInfo)
        {
            this.Loading = bookmarkInfo.ObserveProperty(x => x.Status)
                           .Select(x => x == BookmarkInfoStatus.SummaryLoading || x == BookmarkInfoStatus.SummaryDownloading || x == BookmarkInfoStatus.ChapterLoading || x == BookmarkInfoStatus.ChapterDownloading)
                           .ObserveOnUIDispatcher()
                           .ToReadOnlyReactivePropertySlim()
                           .AddTo(this.CompositeDisposable);

            this.BackCommand = new AsyncReactiveCommand()
                               .WithSubscribe(async() =>
            {
                Transitioner.MovePreviousCommand.Execute(null, null);
                await orderBuilder.From("RequestingChapter")
                .With("Id", Guid.Empty)
                .Next("RequestingBookmark")
                .With("Id", Guid.Empty)
                .DispatchAsync();
            })
                               .AddTo(this.CompositeDisposable);

            this.Chapters = bookmarkInfo.Chapters.ToReadOnlyReactiveCollection(x => new ChapterViewModel(orderBuilder, loadableBookmarkService, x), UIDispatcherScheduler.Default)
                            .AddTo(this.CompositeDisposable);

            this.SelectionChangedCommand = new AsyncReactiveCommand <SelectionChangedEventArgs>()
                                           .WithSubscribe(async e =>
            {
                var selectred = e.AddedItems.Cast <ChapterViewModel>().FirstOrDefault();
                await orderBuilder.From("RequestingChapter")
                .With("Id", selectred?.Id ?? Guid.Empty)
                .DispatchAsync();
            })
                                           .AddTo(this.CompositeDisposable);

            this.IsSelected = Observable.FromEventPattern <BookmarkRequestEventArgs>(h => loadableBookmarkService.BookmarkRequested += h, h => loadableBookmarkService.BookmarkRequested -= h)
                              .Select(x => x.EventArgs.Bookmark != null && x.EventArgs.Bookmark.Id == bookmarkInfo.Id)
                              .ObserveOnUIDispatcher()
                              .ToReadOnlyReactivePropertySlim()
                              .AddTo(this.CompositeDisposable);

            this.ChapterTitle = Observable.FromEventPattern <ChapterRequestEventArgs>(h => loadableBookmarkService.ChapterRequested += h, h => loadableBookmarkService.ChapterRequested -= h)
                                .Select(x => x.EventArgs.Chapter?.Title ?? "")
                                .ObserveOnUIDispatcher()
                                .ToReadOnlyReactivePropertySlim()
                                .AddTo(this.CompositeDisposable);

            //this.ChapterContent = new ReactivePropertySlim<string>("").AddTo(this.CompositeDisposable);

            this.ChapterContent = Observable.FromEventPattern <ChapterRequestEventArgs>(h => loadableBookmarkService.ChapterRequested += h, h => loadableBookmarkService.ChapterRequested -= h)
                                  .SelectMany(x =>
            {
                var chapter = x.EventArgs.Chapter;
                if (chapter == null || bookmarkInfo.Chapters.All(c => c.Id != chapter.Id))
                {
                    return(Observable.Return(""));
                }
                return(chapter.ObserveProperty(c => c.Content));
            })
                                  .ObserveOnUIDispatcher()
                                  //.Subscribe(x => this.ChapterContent.Value = x)
                                  .ToReadOnlyReactivePropertySlim()
                                  .AddTo(this.CompositeDisposable);

            this.IsSelected.Where(x => x).Take(1).SelectMany(x =>
            {
                return(orderBuilder.From("LoadingBookmarkChapter")
                       .With("Id", bookmarkInfo.Id)
                       .DispatchAsync()
                       .ToObservable());
            })
            .Subscribe()
            .AddTo(this.CompositeDisposable);
        }