/// <summary> /// 删除指定的项目并在删除前要求用户确认。 /// </summary> /// <param name="item">要删除的项目</param> /// <returns>是否已删除项目</returns> private async Task <bool> DeleteItemAsync(FluentFTP.FtpListItem item) { await ftpSemaphore.WaitAsync(); try { ContentDialog dialog = new ContentDialog() { Content = string.Format("你确定要删除{0}吗?", item.Name), PrimaryButtonText = "是", CloseButtonText = "否" }; var result = await dialog.ShowAsync(); progressBar.Visibility = Visibility.Visible; progressBar.IsIndeterminate = true; if (result != ContentDialogResult.Primary) { return(false); } switch (item.Type) { case FluentFTP.FtpFileSystemObjectType.Directory: await client.SetWorkingDirectoryAsync(Path.GetDirectoryName(item.FullName)); await client.DeleteDirectoryAsync(item.Name); break; case FluentFTP.FtpFileSystemObjectType.File: await client.SetWorkingDirectoryAsync(Path.GetDirectoryName(item.FullName)); await client.DeleteFileAsync(item.Name); break; default: throw new NotImplementedException("不支持删除除文件夹和文件以外的类型"); } progressBar.Visibility = Visibility.Collapsed; ContentDialog resultDialog = new ContentDialog() { Content = string.Format("已经成功删除{0}。", item.Name), CloseButtonText = "确定" }; await resultDialog.ShowAsync(); } catch (Exception ex) { ContentDialog exceptionDialog = new ContentDialog() { Content = string.Format("遇到未知错误。错误信息:{0}", ex.Message), CloseButtonText = "确定" }; await exceptionDialog.ShowAsync(); } finally { progressBar.Visibility = Visibility.Collapsed; ftpSemaphore.Release(); } return(true); }