Exemplo n.º 1
0
        private async Task UploadFiles(IEnumerable <string> spectra)
        {
            try
            {
                if (_cts.IsCancellationRequested)
                {
                    return;
                }
                foreach (var f in spectra)
                {
                    await SpectraTools.UploadFileToCloudAsync(chosenSpectra[f], _cts.Token);

                    var currentView = listView1.Items.Cast <ListViewItem>().Where(l => l.Text == f).FirstOrDefault();
                    listView1.Items.Remove(currentView);
                    _currentSpectra.Add(f);
                }
            }
            catch (TaskCanceledException)
            {
                MessageBox.Show("Операция была отменена!", "Отмена загрузки спектров", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (OperationCanceledException)
            {
                MessageBox.Show("Операция была отменена!", "Отмена загрузки спектров", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка при загрузке спектров", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Exemplo n.º 2
0
        public async Task DownloadNonExistedFileTest()
        {
            var spctr = "11078166";
            await SpectraTools.DownloadSpectraAsync(spctr, Environment.GetFolderPath(Environment.SpecialFolder.Desktop), _cts.Token);

            Assert.IsFalse(File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), $"{spctr}.cnf")));
        }
Exemplo n.º 3
0
        public async Task DownloadNonExistedFileTest()
        {
            var spctr = "11078166";

            Settings.ConnectionString = cons;
            await SpectraTools.DownloadSpectraAsync($"{spctr}", $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}", _cts.Token);
        }
Exemplo n.º 4
0
        public async Task LLI2FilesListTest()
        {
            var SetKey = "VN-02-18-56-d";

            Settings.ConnectionString = cons;
            await foreach (var ssi in SpectraTools.LLISetSpectrasAsync(SetKey, IrradiationType.LLI2, _cts.Token))
            {
                Assert.IsTrue(File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), SetKey, SpectraTools.IrradiationTypeMap[IrradiationType.LLI2], ssi.LoadNumber.ToString(), $"c-{ssi.Container}", ssi.SampleType, $"{ssi.SampleSpectra}.cnf")));
            }
        }
Exemplo n.º 5
0
        public async Task SLIFilesListTest()
        {
            var SetKey = "VN-02-18-56-d";

            Settings.ConnectionString = cons;
            await foreach (var ssi in SpectraTools.SLISetSpectrasAsync(SetKey, _cts.Token))
            {
                Assert.IsTrue(File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), SetKey, "SLI", ssi.SampleType, $"{ssi.SampleSpectra}.cnf")));
            }
        }
Exemplo n.º 6
0
        public async Task DownloadFileByNameTest()
        {
            //var spctr = "1107816";
            var spctr = "1006019";

            Assert.IsFalse(File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{spctr}.cnf"));
            await SpectraTools.DownloadSpectraAsync(spctr, $"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}", _cts.Token);

            Assert.IsTrue(File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{spctr}.cnf"));
            File.Delete($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{spctr}.cnf");
            Assert.IsFalse(File.Exists($"{Environment.GetFolderPath(Environment.SpecialFolder.Desktop)}\\{spctr}.cnf"));
        }
Exemplo n.º 7
0
        public async Task LLI2FilesListTest()
        {
            var dir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test", "LLI2FilesListTest");

            if (Directory.Exists(dir))
            {
                Directory.Delete(dir, true);
            }

            Directory.CreateDirectory(dir);
            var SetKey = "VN-02-18-56-d";

            await foreach (var ssi in SpectraTools.GetLLISpectraForSampleSetAsync(SetKey, IrradiationType.LLI2, _cts.Token))
            {
                await SpectraTools.DownloadSpectraAsync(ssi.SampleSpectra, dir, _cts.Token);
            }
            Assert.AreEqual(70, Directory.GetFiles(dir).Length);

            Directory.Delete(dir, true);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Save current measurement session on the device.
        /// </summary>
        public async Task SaveAsync(string fileName = "")
        {
            try
            {
                if (!_device.IsConnected || Status == DetectorStatus.off)
                {
                    Report.Notify(new DetectorMessage(Codes.ERR_DET_FSAVE_DCON));
                    return;
                }

                if (string.IsNullOrEmpty(fileName))
                {
                    var _currentDir = Path.Combine(@"D:\Spectra",
                                                   DateTime.Now.Year.ToString(),
                                                   DateTime.Now.Month.ToString("D2"),
                                                   Measurement.TypeToString[(MeasurementsType)CurrentMeasurement.Type].ToLower()
                                                   );

                    Directory.CreateDirectory(_currentDir);
                    if (string.IsNullOrEmpty(CurrentMeasurement.FileSpectra))
                    {
                        FullFileSpectraName = Path.Combine(_currentDir, $"{CurrentMeasurement}.cnf");
                    }
                    else
                    {
                        FullFileSpectraName = Path.Combine(_currentDir, $"{CurrentMeasurement.FileSpectra}.cnf");
                    }
                }

                if (File.Exists(FullFileSpectraName))
                {
                    Report.Notify(new DetectorMessage(Codes.WARN_DET_FSAVE_DUPL));
                    FullFileSpectraName = GetUniqueName(FullFileSpectraName);
                }

                _device.Save(FullFileSpectraName);

                if (File.Exists(FullFileSpectraName))
                {
                    AddEfficiencyCalibrationToFile(FullFileSpectraName, CurrentMeasurement.Height.Value);
                    await SpectraTools.UploadFileToCloudAsync(FullFileSpectraName, new System.Threading.CancellationTokenSource(TimeSpan.FromSeconds(30)).Token);

                    Report.Notify(new DetectorMessage(Codes.SUCC_DET_FILE_SAVED));
                }
                else
                {
                    Report.Notify(new DetectorMessage(Codes.ERR_DET_FILE_NOT_SAVED));
                    return;
                }
            }
            catch (TaskCanceledException)
            {
                Report.Notify(new DetectorMessage(Codes.WARN_DET_FILE_NOT_UPL_CLD));
            }
            catch (Exception ex)
            {
                Report.Notify(new DetectorMessage(Codes.ERR_DET_FILE_SAVE_UNREG)
                {
                    DetailedText = ex.ToString()
                });
            }
        }
Exemplo n.º 9
0
        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;
            }
        }
Exemplo n.º 10
0
        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;
            }
        }