Exemple #1
0
        public bool TryGetOscillogram(int index, out string oscillogramPath, IOscilloscopeViewModel oscilloscopeViewModel, IOscilloscopeModel oscilloscopeModel, DeviceContext deviceContext)
        {
            if ((oscilloscopeViewModel.Oscillograms != null) && oscilloscopeViewModel.Oscillograms.Any((oscillogram => oscillogram.OscillogramNumber == index)))
            {
                oscillogramPath = oscilloscopeViewModel.Oscillograms.First((oscillogram => oscillogram.OscillogramNumber == index)).OscillogramPath;
                return(true);
            }
            IJournalRecord oscilligramRecord = oscilloscopeModel.OscilloscopeJournal.JournalRecords[index];

            oscilloscopeModel.OscillogramLoadingParameters.Initialize(oscilligramRecord.FormattedValues, oscilloscopeModel.OscilloscopeJournal.RecordTemplate);
            string oscHdrFile = this.GetOscillogramSignature(oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName) + ".hdr";

            string[] oscFiles = Directory.GetFiles(GetOscillogramDirectoryPath(deviceContext));
            if (oscFiles.Any((s => s.Contains(oscHdrFile))))
            {
                oscillogramPath = Path.Combine(GetOscillogramDirectoryPath(deviceContext), oscHdrFile);
                return(true);
            }
            oscillogramPath = string.Empty;
            return(false);
        }
Exemple #2
0
        public async Task LoadOscillogramsByNumber(List <int> numberOfOscillograms,
                                                   IProgress <ITaskProgressReport> progress, CancellationToken cancellationToken,
                                                   IOscilloscopeModel oscilloscopeModel, IOscilloscopeViewModel oscilloscopeViewModel, DeviceContext deviceContext)
        {
            ITaskProgressReport progressReport = _taskProgressReportGettingFunc();
            int numberOfPages = 0;

            foreach (int numberOfOscillogram in numberOfOscillograms)
            {
                if (oscilloscopeViewModel.Oscillograms.Any((oscillogram1 => oscillogram1.OscillogramNumber == numberOfOscillogram)))
                {
                    continue;
                }
                IJournalRecord oscilligramRecord = oscilloscopeModel.OscilloscopeJournal.JournalRecords[numberOfOscillogram - 1];
                oscilloscopeModel.OscillogramLoadingParameters.Initialize(oscilligramRecord.FormattedValues,
                                                                          oscilloscopeModel.OscilloscopeJournal.RecordTemplate);
                int numberOfPoints = oscilloscopeModel.OscillogramLoadingParameters.GetOscillogramCountingsNumber() *
                                     oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords();
                numberOfPages += (int)Math.Ceiling((double)numberOfPoints / PAGE_SIZE_IN_WORD);
            }

            progressReport.TotalProgressAmount = numberOfPages;
            progress.Report(progressReport);

            foreach (int numberOfOscillogram in numberOfOscillograms)
            {
                IJournalRecord oscilligramRecord = oscilloscopeModel.OscilloscopeJournal.JournalRecords[numberOfOscillogram - 1];
                oscilloscopeModel.OscillogramLoadingParameters.Initialize(oscilligramRecord.FormattedValues,
                                                                          oscilloscopeModel.OscilloscopeJournal.RecordTemplate);
                double      oscLengthInCountings = oscilloscopeModel.OscillogramLoadingParameters.GetOscillogramCountingsNumber();
                double      sizeOfCounting       = oscilloscopeModel.OscillogramLoadingParameters.GetSizeOfCountingInWords();
                double      oscLengthInWords     = oscLengthInCountings * sizeOfCounting;
                double      pointOfOscStart      = oscilloscopeModel.OscillogramLoadingParameters.GetPointOfStart();
                double      pageCount            = (int)Math.Ceiling(oscLengthInWords / PAGE_SIZE_IN_WORD);
                ushort      oscStartPageIndex    = (ushort)(pointOfOscStart / PAGE_SIZE_IN_WORD);
                double      endPage     = oscStartPageIndex + pageCount;
                Oscillogram oscillogram = new Oscillogram();
                try
                {
                    await this.ReadOscilligramToEndRecursive(oscStartPageIndex, oscillogram, (ushort)endPage, progress,
                                                             progressReport, cancellationToken, deviceContext, oscilloscopeModel);
                }
                catch
                {
                    progressReport.CurrentProgressAmount = 0;
                    progressReport.TotalProgressAmount   = 1;
                    progress.Report(progressReport);
                    return;
                }

                OscillogramHelper.InvertOscillogram(oscillogram, oscilloscopeModel.OscillogramLoadingParameters, PAGE_SIZE_IN_WORD);
                oscillogram.OscillogramNumber = numberOfOscillogram - 1;
                if (oscilloscopeViewModel.Oscillograms.Any((oscillogram1 =>
                                                            oscillogram1.OscillogramNumber == oscillogram.OscillogramNumber)))
                {
                    oscilloscopeViewModel.Oscillograms.Remove(oscilloscopeViewModel.Oscillograms.First((oscillogram1 =>
                                                                                                        oscillogram1.OscillogramNumber == oscillogram.OscillogramNumber)));
                }

                oscilloscopeViewModel.Oscillograms.Add(oscillogram);


                await OscillogramHelper.SaveOscillogram(oscillogram, GetOscillogramDirectoryPath(deviceContext),
                                                        GetOscillogramSignature(oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName),
                                                        oscilloscopeModel.CountingTemplate, oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName, deviceContext);

                oscillogram.OscillogramPath = Path.Combine(GetOscillogramDirectoryPath(deviceContext),
                                                           GetOscillogramSignature(oscilloscopeModel.OscillogramLoadingParameters, deviceContext.DeviceName));
            }
        }