Exemple #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));
        }
Exemple #2
0
        public async Task CanUploadFilesUsingClientApi()
        {
            using (var file = new TempFile())
            {
                var data = new byte[1024 * 1024 * 8 * 4];
                await using (var fs = file.Path.Create())
                {
                    await fs.WriteAsync(data);
                }

                Utils.Log($"Uploading {file.Path.Size.ToFileSizeString()} file");
                var result = await AuthorAPI.UploadFile(file.Path,
                                                        progress => Utils.Log($"Uploading : {progress * 100}%"), Fixture.APIKey);

                Utils.Log($"Result {result}");
                Assert.StartsWith("https://wabbajackpush.b-cdn.net/" + (string)file.Path.FileNameWithoutExtension, result);
            }
        }
        public AuthorFilesVM(SettingsVM vm) : base(vm.MWVM)
        {
            var sub = new Subject <double>();

            Queue.Status.Select(s => (double)s.ProgressPercent).Subscribe(v =>
            {
                UploadProgress = v;
            });
            IsVisible = AuthorAPI.HasAPIKey ? Visibility.Visible : Visibility.Collapsed;

            SelectFile = ReactiveCommand.Create(() =>
            {
                var fod = UIUtils.OpenFileDialog("*|*");
                if (fod != null)
                {
                    SelectedFile = fod;
                }
            });

            Upload = ReactiveCommand.Create(async() =>
            {
                SelectedFile = await AuthorAPI.UploadFile(Queue, SelectedFile);
            });
        }