/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="watchFile">The file structure of the log that was saved to disk.</param> public HistoricDataManager(WatchFile_t watchFile) { // Create the list containing all the frames associated with the set. Debug.Assert(watchFile.DataStream.WatchFrameList.Count > 1, "HistoricDataManager.Ctor() - [watchFile.WatchFrameList.Count > 1]"); m_FramesAll = new List <WatchFrame_t>(); m_FramesAll = watchFile.DataStream.WatchFrameList; // Copy All the records in the above list to the list associated with the frames associated with the start and stop times. m_FramesToPlot = new List <WatchFrame_t>(); m_FramesToPlot = m_FramesAll; m_StartTime = m_FramesAll[0].CurrentDateTime; m_StopTime = m_FramesAll[m_FramesAll.Count - 1].CurrentDateTime; m_LogType = watchFile.DataStream.LogType; Debug.Assert(watchFile.DataStream.FrameIntervalMs > 0, "HistoricDataManager.Ctor() - [watchFile.DataStream.FrameIntervalMs > 0]"); m_FrameIntervalMs = watchFile.DataStream.FrameIntervalMs; m_Workset = watchFile.DataStream.Workset; m_WatchFile = watchFile; // Convert the DataStream.AutoScaleWatchValues property of the watch file to a list. m_AutoScaleWatchValueList = new List <AutoScale_t>(); AutoScale_t autoScale; for (int watchElementIndex = 0; watchElementIndex < m_WatchFile.DataStream.AutoScaleWatchValues.Length; watchElementIndex++) { autoScale = m_WatchFile.DataStream.AutoScaleWatchValues[watchElementIndex]; m_AutoScaleWatchValueList.Add(autoScale); } }
/// <summary> /// Ask the user to select a data-stream file, de-serialized this to the appropriate object type and then display the data using the appropriate /// <c>FormDataStreamPlot</c> derived class. /// </summary> /// <param name="title">The title that is to appear on the <c>OpenFileDialog</c> form.</param> /// <param name="defaultExtension">The default extension associated with the type of log.</param> /// <param name="filterText">The filter text. Used to filter the list of available files.</param> /// <param name="initialDirectory">The initial directory that will be show.</param> /// <returns>A flag to indicate whether a valid watch file was selected. True, indicates that the selected file was valid; otherwise, false.</returns> public virtual bool ShowDataStreamFile(string title, string defaultExtension, string filterText, string initialDirectory) { // Default to the selected file being invalid. bool selectedFileIsValid = false; MainWindow.CloseChildForms(); MainWindow.Cursor = Cursors.WaitCursor; string fullFilename = General.FileDialogOpenFile(title, defaultExtension, filterText, initialDirectory); // Skip, if the user didn't select a simulated fault log file. if (fullFilename == string.Empty) { MainWindow.Cursor = Cursors.Default; return(selectedFileIsValid); } // Update the appropriate InitialDirectory property with the path of the specified data stream file. switch (defaultExtension) { case CommonConstants.ExtensionFaultLog: InitialDirectory.FaultLogsRead = Path.GetDirectoryName(fullFilename); break; case CommonConstants.ExtensionSimulatedFaultLog: InitialDirectory.SimulatedFaultLogsRead = Path.GetDirectoryName(fullFilename); break; case CommonConstants.ExtensionWatchFile: InitialDirectory.WatchFilesRead = Path.GetDirectoryName(fullFilename); break; default: break; } // De-serialize the selected file. m_WatchFile = FileHandling.Load <WatchFile_t>(fullFilename, FileHandling.FormatType.Binary); // Ensure that the de-serialized file contains data. if (m_WatchFile.DataStream.WatchFrameList == null) { // File format is not recognised, report message. MessageBox.Show(Resources.MBTInvalidFormat, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); MainWindow.Cursor = Cursors.Default; return(selectedFileIsValid); } // Ensure that the selected log file is associated with the current project. if (m_WatchFile.Header.ProjectInformation.ProjectIdentifier != Parameter.ProjectInformation.ProjectIdentifier) { MessageBox.Show(Resources.MBTProjectIdMismatch, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); MainWindow.Cursor = Cursors.Default; return(selectedFileIsValid); } FileInfo fileInfo = new FileInfo(fullFilename); m_WatchFile.Filename = fileInfo.Name; m_WatchFile.FullFilename = fileInfo.FullName; selectedFileIsValid = true; MainWindow.Cursor = Cursors.Default; return(selectedFileIsValid); }