/// <summary> /// If a fault log data stream has been saved for the selected event record, retrieve the fault log from disk and call the form used to plot the fault log. /// </summary> /// <param name="selectedEventRecord">The selected event record.</param> protected override void ShowFaultLog(EventRecord selectedEventRecord) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip, if a data stream hasn't been saved for the selected record. if ((selectedEventRecord == null) || (selectedEventRecord.StreamSaved == false)) { MessageBox.Show(Resources.MBTFaultLogNotAvailable, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // ------------------------------------------------------------------------ // Retrieve the data stream corresponding to the selected record from disk. // ------------------------------------------------------------------------ string fullyQualifiedFaultLogFilename = General.GetFullyQualifiedFaultLogFilename(selectedEventRecord); FileInfo fileInfo = new FileInfo(fullyQualifiedFaultLogFilename); WatchFile_t watchFile; if (fileInfo.Exists) { // De-serialize the selected file. watchFile = FileHandling.Load<WatchFile_t>(fullyQualifiedFaultLogFilename, FileHandling.FormatType.Binary); // Ensure that the de-serialized file contains data. if (watchFile.DataStream.WatchFrameList == null) { // File format is not recognised, report message. MessageBox.Show(Resources.MBTInvalidFormat, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Ensure that the selected log file is associated with the current project. if (watchFile.Header.ProjectInformation.ProjectIdentifier != Parameter.ProjectInformation.ProjectIdentifier) { MessageBox.Show(Resources.MBTProjectIdMismatch, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } watchFile.Filename = fileInfo.Name; watchFile.FullFilename = fileInfo.FullName; } else { MessageBox.Show(Resources.MBTDataStreamNotSaved, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); Cursor = Cursors.Default; return; } // ------------------------- // Plot the saved fault log. // ------------------------- try { FormOpenFaultLog formViewSavedFaultLog = new FormOpenFaultLog(watchFile); formViewSavedFaultLog.MdiParent = MdiParent; // The CalledFrom property is used to allow the called form to reference back to this form. formViewSavedFaultLog.CalledFrom = this; formViewSavedFaultLog.Show(); Hide(); } catch (Exception exception) { MessageBox.Show(Resources.MBTShowFaultLogFailed + CommonConstants.NewLine + CommonConstants.NewLine + exception.Message, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; }
/// <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 /// <c>FormDataStreamPlot</c> 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 override bool ShowDataStreamFile(string title, string defaultExtension, string filterText, string initialDirectory) { // Default to the selected file being invalid. bool selectedFileIsValid = false; selectedFileIsValid = base.ShowDataStreamFile(title, defaultExtension, filterText, initialDirectory); if (selectedFileIsValid == true) { // The data-stream file is valid , display it using the appropriate form. MainWindow.Cursor = Cursors.WaitCursor; // The data-stream file is valid , display it. FormDataStreamPlot formDataStreamPlot; if (m_WatchFile.DataStream.LogType == LogType.DataStream) { formDataStreamPlot = new FormOpenFaultLog(m_WatchFile); MainWindow.ShowMdiChild(formDataStreamPlot); } else { MessageBox.Show(Resources.MBTLogFileTypeNotSupported, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); } MainWindow.Cursor = Cursors.Default; } return selectedFileIsValid; }
/// <summary> /// If a fault log data stream has been saved for the selected event record, retrieve the fault log from disk and call the form used to plot the fault log. /// </summary> /// <param name="selectedEventRecord">The selected event record.</param> protected override void ShowFaultLog(EventRecord selectedEventRecord) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip, if a data stream hasn't been saved for the selected record. if ((selectedEventRecord == null) || (selectedEventRecord.StreamSaved == false)) { MessageBox.Show(Resources.MBTFaultLogNotAvailable, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); return; } // ------------------------------------------------------------------------ // Retrieve the data stream corresponding to the selected record from disk. // ------------------------------------------------------------------------ string fullyQualifiedFaultLogFilename = General.GetFullyQualifiedFaultLogFilename(selectedEventRecord); FileInfo fileInfo = new FileInfo(fullyQualifiedFaultLogFilename); WatchFile_t watchFile; if (fileInfo.Exists) { // De-serialize the selected file. watchFile = FileHandling.Load <WatchFile_t>(fullyQualifiedFaultLogFilename, FileHandling.FormatType.Binary); // Ensure that the de-serialized file contains data. if (watchFile.DataStream.WatchFrameList == null) { // File format is not recognised, report message. MessageBox.Show(Resources.MBTInvalidFormat, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // Ensure that the selected log file is associated with the current project. if (watchFile.Header.ProjectInformation.ProjectIdentifier != Parameter.ProjectInformation.ProjectIdentifier) { MessageBox.Show(Resources.MBTProjectIdMismatch, Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } watchFile.Filename = fileInfo.Name; watchFile.FullFilename = fileInfo.FullName; } else { MessageBox.Show(Resources.MBTDataStreamNotSaved, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Information); Cursor = Cursors.Default; return; } // ------------------------- // Plot the saved fault log. // ------------------------- try { FormOpenFaultLog formViewSavedFaultLog = new FormOpenFaultLog(watchFile); formViewSavedFaultLog.MdiParent = MdiParent; // The CalledFrom property is used to allow the called form to reference back to this form. formViewSavedFaultLog.CalledFrom = this; formViewSavedFaultLog.Show(); Hide(); } catch (Exception exception) { MessageBox.Show(Resources.MBTShowFaultLogFailed + CommonConstants.NewLine + CommonConstants.NewLine + exception.Message, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error); } return; }