private static (bool, int) CheckRecordByParameter(IJournalRecord journalRecord, IJournalParameter journalParameter, int recordTemplateCounter) { if (journalParameter is IComplexJournalParameter complexJournalParameter) { foreach (var childJournalParameter in complexJournalParameter.ChildJournalParameters) { var res = CheckRecordByParameter(journalRecord, childJournalParameter, recordTemplateCounter); if (!res.Item1) { return(false, res.Item2); } recordTemplateCounter = res.Item2; } return(true, recordTemplateCounter); } if (journalRecord.FormattedValues.Count <= recordTemplateCounter) { return(false, ++recordTemplateCounter); } else { return(true, ++recordTemplateCounter); } }
public async Task Load() { _uniconJournal.JournalRecords.Clear(); var sequenceLoader = StaticContainer.Container.Resolve <ILoadingSequenceLoaderRegistry>().ResolveLoader( _uniconJournal.JournalLoadingSequence, _deviceContext); _loaderHooks.OnBeforeLoading(); while (sequenceLoader.GetIsNextRecordAvailable()) { var recordValues = await sequenceLoader.GetNextRecordUshorts(); if (!recordValues.IsSuccess) { break; } IJournalRecord newRec = await _journalRecordFactory.CreateJournalRecord(recordValues.Item, _uniconJournal.RecordTemplate, _deviceContext); if (newRec != null) { _uniconJournal.JournalRecords.Add(newRec); _loaderHooks.OnRecordValuesLoaded(newRec.FormattedValues); } } }
public IJournalRecordViewModel CreateJournalRecordViewModel(IJournalRecord journalRecord) { IJournalRecordViewModel journalRecordViewModel = _container.Resolve <IJournalRecordViewModel>(); foreach (Unicon2.Infrastructure.Values.IFormattedValue formattedValue in journalRecord .FormattedValues) { journalRecordViewModel.FormattedValueViewModels.Add( _valueViewModelFactory.CreateFormattedValueViewModel(formattedValue)); } return(journalRecordViewModel); }
public async Task <IJournalRecord> CreateJournalRecord(ushort[] values, IRecordTemplate recordTemplate, DeviceContext deviceContext) { if (values.All(o => o == 0)) { return(null); } IJournalRecord journalRecord = _container.Resolve <IJournalRecord>(); foreach (IJournalParameter journalParameter in recordTemplate.JournalParameters) { journalRecord.FormattedValues.AddRange( await GetValuesForRecord(journalParameter, values, deviceContext)); } return(journalRecord); }
private static bool CheckRecordByTemplate(IRecordTemplate recordTemplate, IJournalRecord journalRecord) { var recordTemplateCounter = 0; foreach (var journalParameter in recordTemplate.JournalParameters) { var res = CheckRecordByParameter(journalRecord, journalParameter, recordTemplateCounter); recordTemplateCounter = res.Item2; if (!res.Item1) { return(false); } } if (journalRecord.FormattedValues.Count != recordTemplateCounter) { return(false); } return(true); }
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); }
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)); } }