コード例 #1
0
        public MainWindowVm(ConfigService configService, Project project, ThumbnailService thumbnailService, IWindowService windowService, DocumentOperator documentOperator, ILogger logger)
        {
            Tags      = configService.Tags.ToReadOnlyReactiveCollection(x => new TagItemVm(x, false)).AddTo(Disposables);
            Recent    = configService.Recent.ToReadOnlyReactiveCollection(x => new RecentVm(project.Documents.FirstOrDefault(doc => doc.MetaData.Id == x))).AddTo(Disposables);
            Documents = project.Documents.ToReadOnlyReactiveCollection(x => new DocumentVm(x, documentOperator, thumbnailService)).AddTo(Disposables);

            // ドキュメントの非同期読み込み
            _ = project.LoadDocumentAsync();
            project.DocumentLoaded += (s, e) =>
            {
                configService.ReloadRecent();
            };

            AddTagCommand = new DelegateCommand <string>(configService.AddTag);
            ReloadCommand = new DelegateCommand(() => _ = project.LoadDocumentAsync());

            ShowDocumentCommand = new DelegateCommand <object>(args =>
            {
                var option = new WindowOpenOption()
                {
                    Maximize = true,
                };

                if (args is DocumentVm documentVm)
                {
                    windowService.Show <DocumentWindow, DocumentVm>(documentVm, option);
                    configService.AddRecent(documentVm.Document.MetaData.Id);
                }

                if (args is RecentVm recentVm)
                {
                    var context = Documents.FirstOrDefault(x => x.Document.MetaData.Id == recentVm.Document?.MetaData.Id);
                    if (context != null)
                    {
                        windowService.Show <DocumentWindow, DocumentVm>(context, option);
                    }
                }
            });

            ShowRenbanEditorCommand = new DelegateCommand(() =>
            {
                var editor      = new RenbanDownLoader(project, configService.Config, logger);
                var dataContext = new RenbanVm(editor);
                windowService.Show <RenbanDownloadWindow, RenbanVm>(dataContext, WindowOpenOption.Default);
            });
        }
コード例 #2
0
        public RenbanVm(RenbanDownLoader renbanDownLoader)
        {
            _renbanDownLoader = renbanDownLoader;

            Address     = new ReactiveProperty <string>(string.Empty);
            UrlsPreview = new ReactivePropertySlim <string>(string.Empty).AddTo(Disposables);
            TextInput   = new ReactiveProperty <string>(string.Empty).AddTo(Disposables);

            // ダウンロードコマンド
            {
                DownLoadCommand = UrlsPreview
                                  .Select(x => ToUrls())
                                  .Select(urls => urls.Any() && urls.All(url => Uri.TryCreate(url, UriKind.Absolute, out _)))
                                  .ToAsyncReactiveCommand();

                DownLoadCommand.Subscribe(async() =>
                {
                    DownloadLogInfo.Value = string.Empty;
                    await _renbanDownLoader.DownLoad(ToUrls());
                })
                .AddTo(Disposables);
            }

            // Vmの入力を RenbanDownloaderで処理し、データを加工する
            Address.Throttle(TimeSpan.FromMilliseconds(100), UIDispatcherScheduler.Default)
            .Subscribe(x =>
            {
                _renbanDownLoader.SetAddressWithAutoUpdateProperties(x);
                Address.Value = renbanDownLoader.Address.Value;
            })
            .AddTo(Disposables);

            // 各パラメータの更新に併せてダウンロード候補一覧表示を更新する
            Observable.Merge(Address.ToUnit(),
                             TextInput.ToUnit(),
                             Start.ToUnit(),
                             End.ToUnit(),
                             FillZero.ToUnit())
            .Throttle(TimeSpan.FromMilliseconds(250), UIDispatcherScheduler.Default)
            .Select(_ => CreateDownloadCandidate())
            .Subscribe(x => UrlsPreview.Value = x).AddTo(Disposables);

            UrlsPreview.Throttle(TimeSpan.FromMilliseconds(500), UIDispatcherScheduler.Default)
            .Subscribe(async _ => await CreatePreviewThumbnailsAsync()).AddTo(Disposables);
        }