Exemplo n.º 1
0
        async Task Process(MediaAsset media)
        {
            var suggestedRequest = new HttpTransferRequest(
                this.syncManager.DefaultUploadUri,
                media.FilePath,
                true
                );

            suggestedRequest.HttpMethod           = HttpMethod.Get;
            suggestedRequest.UseMeteredConnection = this.syncManager.AllowUploadOnMeteredConnection;
            var request = await this.syncDelegate.PreRequest(suggestedRequest, media);

            var transfer = await this.transfers.Enqueue(request);

            await this.repository.Set(
                transfer.Identifier,
                new SyncItem
            {
                Id          = transfer.Identifier,
                FilePath    = media.FilePath,
                DateStarted = DateTimeOffset.UtcNow
            }
                );

            if (this.syncManager.ShowBadgeCount)
            {
                this.notifications.Badge = this.notifications.Badge + 1;
            }
        }
Exemplo n.º 2
0
 public virtual Task <HttpTransferRequest> PreRequest(HttpTransferRequest request, MediaAsset media)
 => Task.FromResult(request);
Exemplo n.º 3
0
        public CreateViewModel(INavigationService navigationService,
                               IHttpTransferManager httpTransfers,
                               IDialogs dialogs,
                               IPlatform platform,
                               AppSettings appSettings)
        {
            this.platform = platform;
            this.Url      = appSettings.LastTransferUrl;

            this.WhenAnyValue(x => x.IsUpload)
            .Subscribe(upload =>
            {
                if (!upload && this.FileName.IsEmpty())
                {
                    this.FileName = Guid.NewGuid().ToString();
                }

                this.Title = upload ? "New Upload" : "New Download";
            });

            this.ManageUploads = navigationService.NavigateCommand("ManageUploads");

            this.ResetUrl = ReactiveCommand.Create(() =>
            {
                appSettings.LastTransferUrl = null;
                this.Url = appSettings.LastTransferUrl;
            });

            this.SelectUpload = ReactiveCommand.CreateFromTask(async() =>
            {
                var files = platform.AppData.GetFiles("upload.*", SearchOption.TopDirectoryOnly);
                if (!files.Any())
                {
                    await dialogs.Alert("There are not files to upload.  Use 'Manage Uploads' below to create them");
                }
                else
                {
                    var cfg = new Dictionary <string, Action>();
                    foreach (var file in files)
                    {
                        cfg.Add(file.Name, () => this.FileName = file.Name);
                    }

                    await dialogs.ActionSheet("Actions", cfg);
                }
            });
            this.Save = ReactiveCommand.CreateFromTask(
                async() =>
            {
                var path    = Path.Combine(this.platform.AppData.FullName, this.FileName);
                var request = new HttpTransferRequest(this.Url, path, this.IsUpload)
                {
                    UseMeteredConnection = this.UseMeteredConnection
                };
                await httpTransfers.Enqueue(request);
                appSettings.LastTransferUrl = this.Url;
                await navigationService.GoBackAsync();
            },
                this.WhenAny
                (
                    x => x.IsUpload,
                    x => x.Url,
                    x => x.FileName,
                    (up, url, fn) =>
            {
                this.ErrorMessage = String.Empty;
                if (!Uri.TryCreate(url.GetValue(), UriKind.Absolute, out _))
                {
                    this.ErrorMessage = "Invalid URL";
                }

                else if (up.GetValue() && fn.GetValue().IsEmpty())
                {
                    this.ErrorMessage = "You must select or enter a filename";
                }

                return(this.ErrorMessage.IsEmpty());
            }
                )
                );
        }
Exemplo n.º 4
0
 public Task <HttpTransfer> Enqueue(HttpTransferRequest request) => Task.FromResult(default(HttpTransfer));
 public static Task <HttpTransfer> Enqueue(HttpTransferRequest request) => Current.Enqueue(request);