Example #1
0
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            IsUploading = _isUploading;
            Picker      = new FilePickerVM(this);

            _isVisible = AuthorAPI.HaveAuthorAPIKey.Select(h => h ? Visibility.Visible : Visibility.Collapsed)
                         .ToProperty(this, x => x.IsVisible);

            SelectFile = Picker.ConstructTypicalPickerCommand(IsUploading.StartWith(false).Select(u => !u));

            HyperlinkCommand = ReactiveCommand.Create(() => Clipboard.SetText(FinalUrl));

            Upload = ReactiveCommand.Create(async() =>
            {
                _isUploading.OnNext(true);
                try
                {
                    FinalUrl = await AuthorAPI.UploadFile(Picker.TargetPath,
                                                          progress => UploadProgress = progress);
                }
                catch (Exception ex)
                {
                    FinalUrl = ex.ToString();
                }
                finally
                {
                    _isUploading.OnNext(false);
                }
            }, IsUploading.StartWith(false).Select(u => !u)
                                            .CombineLatest(Picker.WhenAnyValue(t => t.TargetPath).Select(f => f != null),
                                                           (a, b) => a && b));
        }
Example #2
0
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            IsUploading = _isUploading;
            Picker      = new FilePickerVM(this);

            _isVisible = AuthorAPI.HaveAuthorAPIKey.Select(h => h ? Visibility.Visible : Visibility.Collapsed)
                         .ToProperty(this, x => x.IsVisible);

            SelectFile = Picker.ConstructTypicalPickerCommand(IsUploading.StartWith(false).Select(u => !u));

            HyperlinkCommand = ReactiveCommand.Create(() => Clipboard.SetText(FinalUrl));

            ManageFiles = ReactiveCommand.Create(async() =>
            {
                var authorApiKey = await AuthorAPI.GetAPIKey();
                Utils.OpenWebsite(new Uri($"{Consts.WabbajackBuildServerUri}author_controls/login/{authorApiKey}"));
            });

            Upload = ReactiveCommand.Create(async() =>
            {
                _isUploading.OnNext(true);
                try
                {
                    using var queue = new WorkQueue();
                    var result      = await(await Client.Create()).UploadFile(queue, Picker.TargetPath,
                                                                              (msg, progress) =>
                    {
                        FinalUrl       = msg;
                        UploadProgress = (double)progress;
                    });
                    FinalUrl = result.ToString();
                }
                catch (Exception ex)
                {
                    FinalUrl = ex.ToString();
                }
                finally
                {
                    FinalUrl = FinalUrl.Replace(" ", "%20");
                    _isUploading.OnNext(false);
                }
            }, IsUploading.StartWith(false).Select(u => !u)
                                            .CombineLatest(Picker.WhenAnyValue(t => t.TargetPath).Select(f => f != default),
                                                           (a, b) => a && b));
        }