public async Task UploadAndDownloadFileTest() { var tokens = new Dictionary <string, string>(); var files = Directory.GetFiles(mainDir, "*.cnf", SearchOption.AllDirectories); foreach (var f in files) { Assert.IsTrue(await WebDavClientApi.UploadFileAsync(f, _cts.Token)); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(f, _cts.Token)); tokens[await WebDavClientApi.MakeShareableAsync(f, _cts.Token)] = f; } Assert.AreEqual(files.Length, tokens.Count); foreach (var t in tokens.Keys) { await WebDavClientApi.DownloadFileAsync(t, tokens[t].Replace("WebDavApiTest", "WebDavApiTest_Downloaded"), _cts.Token); Assert.IsTrue(File.Exists(tokens[t].Replace("WebDavApiTest", "WebDavApiTest_Downloaded"))); } Assert.IsTrue(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token)); Assert.IsTrue(await WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token)); Assert.IsFalse(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token)); Assert.AreEqual(files.Length, Directory.GetFiles(mainDir_Downloaded, "*.cnf", SearchOption.AllDirectories).Length); Assert.IsTrue(Directory.Exists(mainDir_Downloaded)); Directory.Delete(mainDir_Downloaded, true); Assert.IsFalse(Directory.Exists(mainDir_Downloaded)); }
private async void _downloadpectraMenuItem_Click(object sender, EventArgs e) { try { if (mainForm.MainRDGV == null || mainForm.MainRDGV.SelectedCells.Count <= 0) { return; } if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } var _cts = new CancellationTokenSource(TimeSpan.FromMinutes(2)); mainForm.ProgressBar.Value = 0; mainForm.ProgressBar.Maximum = mainForm.MainRDGV.SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct().Count(); foreach (var i in mainForm.MainRDGV.SelectedCells.OfType <DataGridViewCell>().Select(c => c.RowIndex).Where(c => c >= 0).Distinct()) { var fileS = mainForm.MainRDGV.Rows[i].Cells["FileSpectra"].Value.ToString(); if (string.IsNullOrEmpty(fileS)) { continue; } using (var rc = new RegataContext()) { var sharedSpectra = rc.SharedSpectra.Where(ss => ss.fileS == fileS).FirstOrDefault(); if (sharedSpectra == null) { continue; } await WebDavClientApi.DownloadFileAsync(sharedSpectra.token, Path.Combine(_folderDialog.SelectedPath, MeasurementsTypeItems.CheckedItem.ToString(), $"{fileS}.cnf"), _cts.Token); mainForm.ProgressBar.Value++; } } } catch (TaskCanceledException) { } catch (Exception ex) { Report.Notify(new RCM.Message(Codes.ERR_WF_IRR_REG_DWNL_SPECTRA_UNREG) { DetailedText = ex.ToString() }); } }