/// <summary> /// Call the <c>ShowEventLogFiles</c> method specifying the parameters associated with an event log. /// </summary> public void OpenEventLog() { MainWindow.CloseChildForms(); MainWindow.Cursor = Cursors.WaitCursor; try { EventLogFile_t eventLogFile = ImportEventLogFiles(); // Ensure that the selected files contained one or more events. if (eventLogFile.EventRecordList.Count <= 0) { MainWindow.Cursor = Cursors.Default; return; } FormOpenEventLog formOpenEventLog = new FormOpenEventLog(eventLogFile); MainWindow.ShowMdiChild(formOpenEventLog); } catch (Exception exception) { MessageBox.Show(exception.Message, Resources.MBCaptionInformation, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { MainWindow.Cursor = Cursors.Default; } }
/// <summary> /// Initialize a new instance of the class. Intialize the size of the various components, set-up the function keys and initialize the list of event records. /// </summary> public FormOpenEventLog(EventLogFile_t eventLogFile) { InitializeComponent(); m_MutexDataGridView = new Mutex(); m_MutexEventCount = new Mutex(); #region - [DataGridView] - // Ensure that the DataGridView is set up before performing a sort. m_DataGridViewEventLog.Columns[ColumnIndexCarIdentifier].Visible = true; m_DataGridViewEventLog.Columns[ColumnIndexLog].Visible = (Parameter.ShowLogName) ? true : false; #endregion - [DataGridView] - EventLogFile = eventLogFile; EventRecordList = EventLogFile.EventRecordList; // Sort the list of events, most recent event first. This ensures that the first row of the DataGridView is selected when the event log is first shown. EventRecordList.Sort(CompareByDateTimeDescending); #region - [Size Definitions] - m_EventVariableControlSize = new VariableControlSize_t(); m_EventVariableControlSize.Margin.Left = MarginLeftEventControl; m_EventVariableControlSize.Margin.Right = MarginRightEventControl; m_EventVariableControlSize.Margin.Top = MarginTopEventControl; m_EventVariableControlSize.Margin.Bottom = MarginBottomEventControl; m_EventVariableControlSize.WidthVariableNameField = WidthEventControlVariableNameField; m_EventVariableControlSize.WidthValueField = WidthEventControlValueField; m_EventVariableControlSize.WidthUnitsField = WidthEventControlUnitsField; m_EventVariableControlSize.Height = HeightEventControl; #endregion - [Size Definitions] - #region - [Function Keys] - DisplayFunctionKey(F3, Resources.FunctionKeyTextSave, Resources.FunctionKeyToolTipSaveEventLogs, Resources.Save); F3.Enabled = false; DisplayFunctionKey(F4, Resources.FunctionKeyTextLoad, Resources.FunctionKeyToolTipLoad, Resources.FolderOpen); DisplayFunctionKey(F12, Resources.FunctionKeyTextInfo, Resources.FunctionKeyToolTipInfo, Resources.FileInformation); #endregion - [Function Keys] - // InformationLabel 1 - Event Count DisplayLabel(InformationLabel1, Resources.InformationLegendEventCount, Color.FromKnownColor(KnownColor.Info)); #region - [Titles] - Text = string.Format(Resources.TitleOpenEventLog, EventLogFile.Filename); m_TabPage1.Text = string.Empty; #endregion - [Titles] - m_CommonEventVariableCount = Lookup.EventTable.CommonEventVariableCount; }
/// <summary> /// Event handler for the OK button <c>Click</c> event. Closes the form. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> private void m_ButtonOK_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Check whether the comments text of the header has been modified. if (m_TextBoxComments.Text != m_Header.Comments) { Cursor = Cursors.WaitCursor; // Check whether the calling form implements the IWatchFile interface. IWatchFile iWatchFile = CalledFrom as IWatchFile; if (iWatchFile != null) { // Yes - Update the WatchFile property with the current header. WatchFile_t watchFile = iWatchFile.WatchFile; watchFile.Header.Comments = m_TextBoxComments.Text; iWatchFile.WatchFile = watchFile; iWatchFile.SaveWatchFile(); } else { // No - Check whether the calling form implements the IEventLogFIle interface. IEventLogFile iEventLogFile = CalledFrom as IEventLogFile; if (iEventLogFile != null) { // Yes - Update the EventLogFile property with the current header. EventLogFile_t eventLogFile = iEventLogFile.EventLogFile; Header_t header = eventLogFile.Header; header.Comments = m_TextBoxComments.Text; eventLogFile.Header = header; iEventLogFile.EventLogFile = eventLogFile; iEventLogFile.SaveEventLogFile(); } } Cursor = Cursors.Default; } Close(); }
/// <summary> /// Ask the user to select one or more event log files, import the data contained in each of the files into an event log file structure and return /// this event log file structure. /// </summary> /// <remarks>The filename and header fileds associated with the new event log file structure will be set to those values associated with /// the first file included in the list.</remarks> /// <returns>The event log file containing all of the imported event date.</returns> public EventLogFile_t ImportEventLogFiles() { // Create a structure to contain all of the imported data. EventLogFile_t eventLogFile = new EventLogFile_t(); eventLogFile.EventRecordList = new List<EventRecord>(); Debug.Assert(MainWindow != null, "MenuInterface.ShowEventLogFile() - [MainWindow != null]"); string[] fullFilenames = General.FileDialogOpenFileMultiSelect(Resources.FileDialogOpenTitleEventLog, CommonConstants.ExtensionEventLog, Resources.FileDialogOpenFilterEventLog, InitialDirectory.EventLogsRead); // Skip, if the user didn't select a file. if (fullFilenames.Length == 0) { MainWindow.Cursor = Cursors.Default; return eventLogFile; } // Update the initial directory with the path of the selected files. InitialDirectory.EventLogsRead = Path.GetDirectoryName(fullFilenames[0]); // Create a structure to contain the data contained within each selected file. EventLogFile_t currentEventLogFile; FileInfo fileInfo; for (int fileIndex = 0; fileIndex < fullFilenames.Length; fileIndex++) { fileInfo = new FileInfo(fullFilenames[fileIndex]); MainWindow.WriteStatusMessage(string.Format(Resources.SMLoadFile,fileInfo.Name)); currentEventLogFile = FileHandling.Load<EventLogFile_t>(fullFilenames[fileIndex], FileHandling.FormatType.Xml); // Ensure that the de-serialized file contains data. if (currentEventLogFile.EventRecordList == null) { // File format is not recognised, report message. MessageBox.Show(string.Format(Resources.MBTFormatNotRecognized, fileInfo.Name), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } // Ensure that the selected log file is associated with the current project. if (currentEventLogFile.Header.ProjectInformation.ProjectIdentifier != Parameter.ProjectInformation.ProjectIdentifier) { MessageBox.Show(string.Format(Resources.MBTProjectIdMismatchMultipleImport, fileInfo.Name), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } // ------------------------------------- // The current file is valid, import it. // ------------------------------------- // Use the header and filename associated with the first entry in the file list. if (fileIndex == 0) { eventLogFile.Header = currentEventLogFile.Header; eventLogFile.Filename = fileInfo.Name; eventLogFile.FullFilename = fileInfo.FullName; } // Append the events contained within the current file into the existing event records. bool duplicationsFound; eventLogFile.AppendEventRecordList(currentEventLogFile.EventRecordList, out duplicationsFound); } MainWindow.WriteStatusMessage(string.Empty); return eventLogFile; }
/// <summary> /// Ask the user to select one or more event log files, import the data contained in each of the files into an event log file structure and return /// this event log file structure. /// </summary> /// <remarks>The filename and header fileds associated with the new event log file structure will be set to those values associated with /// the first file included in the list.</remarks> /// <returns>The event log file containing all of the imported event date.</returns> public EventLogFile_t ImportEventLogFiles() { // Create a structure to contain all of the imported data. EventLogFile_t eventLogFile = new EventLogFile_t(); eventLogFile.EventRecordList = new List <EventRecord>(); Debug.Assert(MainWindow != null, "MenuInterface.ShowEventLogFile() - [MainWindow != null]"); string[] fullFilenames = General.FileDialogOpenFileMultiSelect(Resources.FileDialogOpenTitleEventLog, CommonConstants.ExtensionEventLog, Resources.FileDialogOpenFilterEventLog, InitialDirectory.EventLogsRead); // Skip, if the user didn't select a file. if (fullFilenames.Length == 0) { MainWindow.Cursor = Cursors.Default; return(eventLogFile); } // Update the initial directory with the path of the selected files. InitialDirectory.EventLogsRead = Path.GetDirectoryName(fullFilenames[0]); // Create a structure to contain the data contained within each selected file. EventLogFile_t currentEventLogFile; FileInfo fileInfo; for (int fileIndex = 0; fileIndex < fullFilenames.Length; fileIndex++) { fileInfo = new FileInfo(fullFilenames[fileIndex]); MainWindow.WriteStatusMessage(string.Format(Resources.SMLoadFile, fileInfo.Name)); currentEventLogFile = FileHandling.Load <EventLogFile_t>(fullFilenames[fileIndex], FileHandling.FormatType.Xml); // Ensure that the de-serialized file contains data. if (currentEventLogFile.EventRecordList == null) { // File format is not recognised, report message. MessageBox.Show(string.Format(Resources.MBTFormatNotRecognized, fileInfo.Name), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } // Ensure that the selected log file is associated with the current project. if (currentEventLogFile.Header.ProjectInformation.ProjectIdentifier != Parameter.ProjectInformation.ProjectIdentifier) { MessageBox.Show(string.Format(Resources.MBTProjectIdMismatchMultipleImport, fileInfo.Name), Resources.MBCaptionError, MessageBoxButtons.OK, MessageBoxIcon.Error); continue; } // ------------------------------------- // The current file is valid, import it. // ------------------------------------- // Use the header and filename associated with the first entry in the file list. if (fileIndex == 0) { eventLogFile.Header = currentEventLogFile.Header; eventLogFile.Filename = fileInfo.Name; eventLogFile.FullFilename = fileInfo.FullName; } // Append the events contained within the current file into the existing event records. bool duplicationsFound; eventLogFile.AppendEventRecordList(currentEventLogFile.EventRecordList, out duplicationsFound); } MainWindow.WriteStatusMessage(string.Empty); return(eventLogFile); }
/// <summary> /// Event handler for F4 function key. Load additional saved event logs. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> protected override void F4_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip if the key isn't enabled. if (F4.Enabled == false) { return; } Cursor = Cursors.WaitCursor; F4.Checked = true; // Clear the status message. if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } MenuInterfaceEvent menuInterfaceEvent = new MenuInterfaceEvent(MainWindow); // Create an event log file structure to hold the imported events. EventLogFile_t eventLogFile = menuInterfaceEvent.ImportEventLogFiles(); if (eventLogFile.EventRecordList.Count <= 0) { F4.Checked = false; Cursor = Cursors.Default; return; } // Create a temporary event log file structure so that we can use the AppendEventRecordList() method to add the the imported events to the existing events // while ignoring duplicate entries. EventLogFile_t temporaryEventLogFile = new EventLogFile_t(); temporaryEventLogFile.EventRecordList = new List<EventRecord>(); // Add the existing events to the list. temporaryEventLogFile.AppendEventRecordList(EventRecordList); // Append the imported events to the list ignoring duplicate entries. bool duplicationsFound; temporaryEventLogFile.AppendEventRecordList(eventLogFile.EventRecordList, out duplicationsFound); // Clear the EventRecordList property then add the events stored in the temporary event file structure. EventRecordList.Clear(); EventRecordList.AddRange(temporaryEventLogFile.EventRecordList); // Sort the list of events, most recent event first. This ensures that the first row of the DataGridView is selected when the event log is first shown. EventRecordList.Sort(CompareByDateTimeDescending); ClearDataGridViewRows(); AddList(EventRecordList); // Simulate a SelectionChanged event to display the event variables associated with the selected event. m_DataGridViewEventLog_SelectionChanged(m_DataGridViewEventLog, new EventArgs()); F4.Checked = false; Cursor = Cursors.Default; }
/// <summary> /// Event handler for the F3 function key. Save the current events to disk. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> protected override void F3_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip if the key isn't enabled. if (F3.Enabled == false) { return; } Cursor = Cursors.WaitCursor; F3.Checked = true; // Clear the status message. if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } bool userCancelled = true; DateTime createdTime = DateTime.Now; string defaultFilename = General.DeriveName(FileHeader.HeaderCurrent.TargetConfiguration.CarIdentifier, createdTime, CommonConstants.ExtensionEventLog, string.Empty); string fullFilename = General.FileDialogSaveEventLog(defaultFilename, InitialDirectory.EventLogsWrite); if (fullFilename != string.Empty) { EventLogFile_t savedEventLogFile; Header_t header; userCancelled = CheckForAppend(fullFilename, ref createdTime, out header, out savedEventLogFile); if (userCancelled == true) { return; } // Update the initial directory with the path of the selected file. InitialDirectory.EventLogsWrite = Path.GetDirectoryName(fullFilename); if (MainWindow != null) { FileInfo fileInfo = new FileInfo(fullFilename); MainWindow.WriteStatusMessage(string.Format(Resources.SMSaveFile, fileInfo.Name)); } // Create a new event log file structure to store the event information. EventLogFile_t eventLogFile = new EventLogFile_t(header); // Check whether any saved events are to be added to the event log file structure. if (savedEventLogFile.EventRecordList.Count > 0) { eventLogFile.AppendEventRecordList(savedEventLogFile.EventRecordList); } // Add the current records. eventLogFile.AppendEventRecordList(EventRecordList); // Only serialize the structure if it contains one or more events. if (eventLogFile.EventRecordList.Count > 0) { // Serialize the data to the specified file. FileHandling.Serialize<EventLogFile_t>(fullFilename, eventLogFile, FileHandling.FormatType.Xml); } else { if (MainWindow != null) { MainWindow.WriteStatusMessage(Resources.SMEventListEmpty); } } if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } } F3.Checked = false; Cursor = Cursors.Default; }
/// <summary> /// Event handler for F4 function key. Load additional saved event logs. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> protected override void F4_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip if the key isn't enabled. if (F4.Enabled == false) { return; } Cursor = Cursors.WaitCursor; F4.Checked = true; // Clear the status message. if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } MenuInterfaceEvent menuInterfaceEvent = new MenuInterfaceEvent(MainWindow); // Create an event log file structure to hold the imported events. EventLogFile_t eventLogFile = menuInterfaceEvent.ImportEventLogFiles(); if (eventLogFile.EventRecordList.Count <= 0) { F4.Checked = false; Cursor = Cursors.Default; return; } // Create a temporary event log file structure so that we can use the AppendEventRecordList() method to add the the imported events to the existing events // while ignoring duplicate entries. EventLogFile_t temporaryEventLogFile = new EventLogFile_t(); temporaryEventLogFile.EventRecordList = new List <EventRecord>(); // Add the existing events to the list. temporaryEventLogFile.AppendEventRecordList(EventRecordList); // Append the imported events to the list ignoring duplicate entries. bool duplicationsFound; temporaryEventLogFile.AppendEventRecordList(eventLogFile.EventRecordList, out duplicationsFound); // Clear the EventRecordList property then add the events stored in the temporary event file structure. EventRecordList.Clear(); EventRecordList.AddRange(temporaryEventLogFile.EventRecordList); // Sort the list of events, most recent event first. This ensures that the first row of the DataGridView is selected when the event log is first shown. EventRecordList.Sort(CompareByDateTimeDescending); ClearDataGridViewRows(); AddList(EventRecordList); // Simulate a SelectionChanged event to display the event variables associated with the selected event. m_DataGridViewEventLog_SelectionChanged(m_DataGridViewEventLog, new EventArgs()); F4.Checked = false; Cursor = Cursors.Default; }
/// <summary> /// Event handler for the F3 function key. Save the current events to disk. /// </summary> /// <param name="sender">Reference to the object that raised the event.</param> /// <param name="e">Parameter passed from the object that raised the event.</param> protected override void F3_Click(object sender, EventArgs e) { // Skip, if the Dispose() method has been called. if (IsDisposed) { return; } // Skip if the key isn't enabled. if (F3.Enabled == false) { return; } Cursor = Cursors.WaitCursor; F3.Checked = true; // Clear the status message. if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } bool userCancelled = true; DateTime createdTime = DateTime.Now; string defaultFilename = General.DeriveName(FileHeader.HeaderCurrent.TargetConfiguration.CarIdentifier, createdTime, CommonConstants.ExtensionEventLog, string.Empty); string fullFilename = General.FileDialogSaveEventLog(defaultFilename, InitialDirectory.EventLogsWrite); if (fullFilename != string.Empty) { EventLogFile_t savedEventLogFile; Header_t header; userCancelled = CheckForAppend(fullFilename, ref createdTime, out header, out savedEventLogFile); if (userCancelled == true) { return; } // Update the initial directory with the path of the selected file. InitialDirectory.EventLogsWrite = Path.GetDirectoryName(fullFilename); if (MainWindow != null) { FileInfo fileInfo = new FileInfo(fullFilename); MainWindow.WriteStatusMessage(string.Format(Resources.SMSaveFile, fileInfo.Name)); } // Create a new event log file structure to store the event information. EventLogFile_t eventLogFile = new EventLogFile_t(header); // Check whether any saved events are to be added to the event log file structure. if (savedEventLogFile.EventRecordList.Count > 0) { eventLogFile.AppendEventRecordList(savedEventLogFile.EventRecordList); } // Add the current records. eventLogFile.AppendEventRecordList(EventRecordList); // Only serialize the structure if it contains one or more events. if (eventLogFile.EventRecordList.Count > 0) { // Serialize the data to the specified file. FileHandling.Serialize <EventLogFile_t>(fullFilename, eventLogFile, FileHandling.FormatType.Xml); if (Parameter.GenerateCSV == true) { // Change the extension to '.csv' for the CSV serialization. FileHandling.Serialize <EventLogFile_t>(fullFilename.Replace(CommonConstants.ExtensionEventLog, CommonConstants.ExtensionCSV), eventLogFile, FileHandling.FormatType.Csv); } } else { if (MainWindow != null) { MainWindow.WriteStatusMessage(Resources.SMEventListEmpty); } } if (MainWindow != null) { MainWindow.WriteStatusMessage(string.Empty); } } F3.Checked = false; Cursor = Cursors.Default; }