public WebDavApiTest() { //Report.LogDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test", "WebDavApiTest"); if (Directory.Exists(mainDir)) { Directory.Delete(mainDir, true); } Directory.CreateDirectory(NestedDir1_1); Directory.CreateDirectory(NestedDir1_2); Directory.CreateDirectory(NestedDir2_1); Directory.CreateDirectory(NestedDir2_2); foreach (var f in Directory.GetFiles(@"D:\Spectra\2020", "*.cnf", SearchOption.AllDirectories).Take(5).ToArray()) { File.Copy(f, Path.Combine(NestedDir1_1, Path.GetFileName(f))); File.Copy(f, Path.Combine(NestedDir1_2, Path.GetFileName(f))); File.Copy(f, Path.Combine(NestedDir2_1, Path.GetFileName(f))); File.Copy(f, Path.Combine(NestedDir2_2, Path.GetFileName(f))); } if (WebDavClientApi.IsExistsAsync(mainDir, _cts.Token).Result) { WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token).Wait(); } }
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)); }
public async Task DownloadFileTest() { await WebDavClientApi.DownloadFile("qb7cqjj2LcaQpNW", $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\1107798.cnf", _cts.Token); Assert.IsTrue(File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\1107798.cnf")); File.Delete($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\1107798.cnf"); Assert.IsFalse(File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\1107798.cnf")); }
public async Task UploadFileTest() { var ct = new CancellationTokenSource(); ct.CancelAfter(TimeSpan.FromSeconds(10)); await FileManager.CopyAndUpload(_sliFiles[0], "SLI-2"); var nf = MatchDir(Path.GetFileName(_sliFiles[0]), "kji"); Assert.IsTrue(await WebDavClientApi.IsExists(nf, ct.Token)); Assert.IsTrue(await WebDavClientApi.RemoveFile(nf, ct.Token)); Assert.IsFalse(await WebDavClientApi.IsExists(nf, ct.Token)); }
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() }); } }
public async Task UploadFilesTest() { foreach (var f in _lli1Files) { var ct = new CancellationTokenSource(); await FileManager.CopyAndUpload(f, "LLI-1"); var nf = MatchDir(Path.GetFileName(f), "dji-1"); ct.CancelAfter(TimeSpan.FromSeconds(10)); Assert.IsTrue(await WebDavClientApi.IsExists(nf, ct.Token)); Assert.IsTrue(await WebDavClientApi.RemoveFile(nf, ct.Token)); Assert.IsFalse(await WebDavClientApi.IsExists(nf, ct.Token)); } }
public void Dispose() { if (Directory.Exists(mainDir)) { Directory.Delete(mainDir, true); } if (Directory.Exists(mainDir_Downloaded)) { Directory.Delete(mainDir_Downloaded, true); } if (WebDavClientApi.IsExistsAsync(mainDir, _cts.Token).Result) { WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token).Wait(); } }
public async Task CreateAndRemoveFolderTest() { await WebDavClientApi.CreateFolderAsync(NestedDir1_1, _cts.Token); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir1_1, _cts.Token)); await WebDavClientApi.CreateFolderAsync(NestedDir1_2, _cts.Token); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir1_2, _cts.Token)); await WebDavClientApi.CreateFolderAsync(NestedDir2_1, _cts.Token); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir2_1, _cts.Token)); await WebDavClientApi.CreateFolderAsync(NestedDir2_1, _cts.Token); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(NestedDir2_1, _cts.Token)); Assert.IsTrue(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token)); Assert.IsTrue(await WebDavClientApi.RemoveFileAsync(mainDir, _cts.Token)); Assert.IsFalse(await WebDavClientApi.IsExistsAsync(mainDir, _cts.Token)); }
private void CancelMenuButton_Click(object sender, EventArgs e) { WebDavClientApi.Cancel(); _cts.Cancel(); }
public async Task MakeFileSharedTest() { Assert.AreEqual("qb7cqjj2LcaQpNW", await WebDavClientApi.MakeShareable(@"D:\Spectra\2020\01\dji-1\1107798.cnf", _cts.Token)); }
public async Task IsFolderExistsTest() { Assert.IsTrue(await WebDavClientApi.IsFolderExists(@"D:\Spectra\2020\01\dji-1", _cts.Token)); Assert.IsFalse(await WebDavClientApi.IsFolderExists(@"D:\Spectra\2020\01\dji-11", _cts.Token)); }
public async Task CreateFolderTest() { await WebDavClientApi.CreateFolder(@"D:\Spectra\2020\01\dji-1", _cts.Token); Assert.IsTrue(await WebDavClientApi.IsFolderExists(@"D:\Spectra\2020\01\dji-1", _cts.Token)); }
public async Task UploadNonExistedFileTest() { await WebDavClientApi.UploadFile(@"D:\Spectra\2020\01\dji-1\110779.cnf", _cts.Token); }
private async void MenuItemMenuSpectraAll_Click(object sender, EventArgs e) { if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } _cts = new CancellationTokenSource(); FooterStatusLabel.Text = $"{_labels.GetLabel("InitAllSpectraDownloading")}"; FooterStatusProgressBar.Value = 0; ButtonCancel.Enabled = true; try { _cts = new CancellationTokenSource(); var sliSpectras = SpectraTools.SLISetSpectrasAsync(SetKey, _cts.Token).WithCancellation(_cts.Token); var lli1Spectras = SpectraTools.LLISetSpectrasAsync(SetKey, IrradiationType.LLI1, _cts.Token).WithCancellation(_cts.Token); var lli2Spectras = SpectraTools.LLISetSpectrasAsync(SetKey, IrradiationType.LLI2, _cts.Token).WithCancellation(_cts.Token); var taskSli = Task.Run(async() => { await foreach (var ssi in sliSpectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, "SLI", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); var taskLLI1 = Task.Run(async() => { await foreach (var ssi in lli1Spectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[IrradiationType.LLI1], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); var taskLLI2 = Task.Run(async() => { await foreach (var ssi in lli2Spectras.WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[IrradiationType.LLI2], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); } }); await Task.WhenAll(taskSli, taskLLI1, taskLLI2); FooterStatusLabel.Text = $"{_labels.GetLabel("AllSpectraDownldCompl")}"; FooterStatusProgressBar.Value = FooterStatusProgressBar.Maximum; } catch (IndexOutOfRangeException) { MessageBox.Show(_labels.GetLabel("SpectraNotFound"), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (OperationCanceledException ose) { FooterStatusProgressBar.Value = 0; FooterStatusLabel.Text = _labels.GetLabel("CancelOperation"); } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ie, Level = ExceptionLevel.Error }); } } finally { ButtonCancel.Enabled = false; _cts.Dispose(); _cts = null; } }
public async Task UploadNonExistedFileTest() { Assert.IsFalse(await WebDavClientApi.UploadFileAsync(Path.Combine(mainDir, "3110779.cnf"), _cts.Token)); }
public async Task UploadFileTest() { Assert.IsTrue(await WebDavClientApi.UploadFile(@"D:\Spectra\2020\01\dji-1\1107815.cnf", _cts.Token)); Assert.IsTrue(await WebDavClientApi.IsFolderExists(@"D:\Spectra\2020\01\dji-1\1107815.cnf", _cts.Token)); }
private async void MenuItemMenuSpectraLLI_Click(object sender, EventArgs e) { if (_folderDialog.ShowDialog() != DialogResult.OK) { return; } var objName = (sender as ToolStripMenuItem)?.Name; var type = objName.Contains("LLI1") ? IrradiationType.LLI1 : IrradiationType.LLI2; _cts = new CancellationTokenSource(); ButtonCancel.Enabled = true; try { FooterStatusProgressBar.Value = 0; FooterStatusProgressBar.Maximum = 1; var i = 0; await foreach (var ssi in SpectraTools.LLISetSpectrasAsync(SetKey, type, _cts.Token).WithCancellation(_cts.Token)) { if (_cts == null) { _cts = new CancellationTokenSource(); } i++; if (i % 2 == 0) { FooterStatusProgressBar.Value = 0; } FooterStatusLabel.Text = $"{_labels.GetLabel("DownloadingFile")}{ssi.SampleSpectra}"; await WebDavClientApi.DownloadFile(ssi.token, Path.Combine(_folderDialog.SelectedPath, SetKey, SpectraTools.IrradiationTypeMap[type], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf"), _cts.Token); FooterStatusProgressBar.Value = 1; } if (i == 0) { throw new IndexOutOfRangeException(); } FooterStatusLabel.Text = $"{_labels.GetLabel("DownloadingHasDone")}{i}"; } catch (IndexOutOfRangeException) { MessageBox.Show(_labels.GetLabel("SpectraNotFound"), Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } catch (OperationCanceledException ose) { try { FooterStatusProgressBar.Value = 0; FooterStatusLabel.Text = _labels.GetLabel("CancelOperation"); } catch (NullReferenceException) { } } catch (AggregateException ae) { foreach (var ie in ae.InnerExceptions) { MessageBoxTemplates.WrapExceptionToMessageBox(new ExceptionEventsArgs() { exception = ie, Level = ExceptionLevel.Error }); } } finally { ButtonCancel.Enabled = false; _cts?.Dispose(); _cts = null; } }