private async void DownloadItemAsync(string url) { if (!Uri.TryCreate(url, UriKind.Absolute, out Uri uri)) { var msg = $"'{url}' isn't a valid URL."; this.ViewModel.ShowError(msg, lastActionStatus: msg); return; } var name = uri.Segments.Last(); bool success; try { success = await SimpleDownloaderHelper.DownloadItemAsync(this.ViewModel.Server, uri.AbsoluteUri); } catch (HttpRequestException e) { this.ViewModel.ShowError(e.Message, lastActionStatus: $"Cannot download '{name}'."); return; } if (!success) { var msg = $"Cannot download '{name}'."; this.ViewModel.ShowError(msg, lastActionStatus: msg); return; } this.ViewModel.Url = string.Empty; this.ViewModel.LoadItemsAsync(); this.ViewModel.LastActionStatus = $"Download of '{name}' was started."; }
public async void LoadItemsAsync() { try { this.reloadTimer.Stop(); this.Items.Clear(); foreach (var item in await SimpleDownloaderHelper.GetItemsAsync(this.Server)) { this.Items.Add(item); } this.ConnectionStatus = $"Connected to '{this.Server}'."; this.reloadTimer.Start(); } catch (HttpRequestException e) { this.ShowError(e.Message, connectionStatus: $"Cannot connect to '{this.Server}'."); } }
private async void DeleteItemAsync(Item item) { bool success; try { success = await SimpleDownloaderHelper.DeleteItemAsync(this.ViewModel.Server, item.Actions); } catch (HttpRequestException e) { this.ViewModel.ShowError(e.Message, lastActionStatus: $"Cannot delete '{item.Name}'."); return; } if (!success) { this.ViewModel.LastActionStatus = $"Cannot delete '{item.Name}'."; return; } this.ViewModel.LoadItemsAsync(); this.ViewModel.LastActionStatus = $"File '{item.Name}' was deleted."; }