private LoggingStates UpdateLoggingState() { if ((_LoggingState == LoggingStates.delayed_logging) && (DateTime.Now.CompareTo(_DelayedLoggingStartTime) >= 0)) { if (_DurationLoggingStopTime > DateTime.Now) { _LoggingState = LoggingStates.duration_logging; } else { _LoggingState = LoggingStates.logging; } return(_LoggingState); } if (_LoggingState == LoggingStates.duration_logging) { string msgStr = string.Format("Duration Logging Stop Time: {0} -- {1}", _DurationLoggingStopTime.ToString(), filename); _DurationLoggingStatusLabel.BeginInvoke((MethodInvoker) delegate { _DurationLoggingStatusLabel.Text = msgStr; }); if (DateTime.Now.CompareTo(_DurationLoggingStopTime) >= 0) { LoggingStoppedTime = DateTime.Now; _LoggingState = LoggingStates.stopped_logging; closeFileHandler(); return(_LoggingState); } } return(_LoggingState); }
public bool CloseFile() { EventHandler method = null; _LoggingState = LoggingStates.idle; if (_DurationLoggingStatusLabel != null) { if (method == null) { method = delegate { _DurationLoggingStatusLabel.Text = filename; }; } _DurationLoggingStatusLabel.BeginInvoke(method); } return(closeFileHandler()); }
public LogManager() { _lockFileOpenIndication = new object(); lockwrite = new object(); lockread = new object(); lockErrorWrite = new object(); _version = string.Empty; PCname = Environment.MachineName; PhysicalConnection = "UART"; FirmwareSWVersion = string.Empty; DUTName = string.Empty; _logDirectory = string.Empty; _filename = string.Empty; _newFilePath = string.Empty; m_FileOpen = false; _LoggingState = LoggingStates.idle; }
public bool WriteLine(string msg) { EventHandler method = null; try { if (_LoggingState == LoggingStates.idle) { return(true); } if (((_LoggingState == LoggingStates.logging) || (_LoggingState == LoggingStates.duration_logging)) && m_FileOpen) { lock (lockwrite) { _myWriter.WriteLine(msg); } } if ((_LoggingState == LoggingStates.delayed_logging) || (_LoggingState == LoggingStates.duration_logging)) { LoggingState = UpdateLoggingState(); } if (_LoggingState == LoggingStates.stopped_logging) { if (method == null) { method = delegate { _DurationLoggingStatusLabel.Text = "Logging Stopped at: " + LoggingStoppedTime.ToString(); }; } _DurationLoggingStatusLabel.BeginInvoke(method); _LoggingState = LoggingStates.idle; if (UpdateMainWindow != null) { UpdateMainWindow(); } } LoggingStates states1 = _LoggingState; } catch { return(false); } return(true); }
public void OpenFile(string filename, bool append) { if (append) { _filename = filename; m_fileWriter = new FileStream(_filename, FileMode.Append); if (_isBin) { m_binaryWriter = new BinaryWriter(m_fileWriter); _myWriter = new writeBin(m_binaryWriter); } else { m_streamwriter = new StreamWriter(m_fileWriter); _myWriter = new writeText(m_streamwriter); } m_FileOpen = true; _LoggingState = LoggingStates.logging; if (UpdateMainWindow != null) { UpdateMainWindow(); } } }
public bool OpenFile(string inFilename) { try { closeFileHandler(); _filename = inFilename; if (File.Exists(inFilename)) { new FileInfo(inFilename); string str = string.Format("File exists: {0}", inFilename); frmDialogWith3Button button = new frmDialogWith3Button("Log Message", "&Append", "&Overwrite", "&Cancel"); button.DisplayMessage = str; switch (button.ShowDialog()) { case DialogResult.OK: m_fileWriter = new FileStream(inFilename, FileMode.Append); goto Label_009F; case DialogResult.Yes: m_fileWriter = new FileStream(inFilename, FileMode.Create); goto Label_009F; } if (UpdateMainWindow != null) { UpdateMainWindow(); } return(false); } m_fileWriter = new FileStream(inFilename, FileMode.Create); Label_009F: if (_isBin) { m_binaryWriter = new BinaryWriter(m_fileWriter); _myWriter = new writeBin(m_binaryWriter); } else { m_streamwriter = new StreamWriter(m_fileWriter); _myWriter = new writeText(m_streamwriter); } if (_LoggingState == LoggingStates.idle) { _LoggingState = LoggingStates.logging; } m_FileOpen = true; if ((_version != string.Empty) && !inFilename.EndsWith(".csv")) { StringBuilder builder = new StringBuilder(); builder.Append("SiRFLive Version: "); builder.Append(_version); builder.Append("\r\n"); builder.Append(DateTime.Now.ToLongDateString()); builder.Append("\r\nPC: "); builder.Append(PCname); builder.Append("\r\nPhysical Connection: "); builder.Append(PhysicalConnection); builder.Append("\r\n"); builder.Append(FirmwareSWVersion); builder.Append("\r\nDUT Name: "); builder.Append(DUTName); builder.Append("\r\n"); Write(builder.ToString()); FileInfo info = new FileInfo(inFilename); if (info.Extension == string.Empty) { _errorFilename = inFilename + "_error.txt"; } else { _errorFilename = inFilename.Replace(info.Extension, "_error.txt"); } m_errorLogWriter = new StreamWriter(_errorFilename, false); m_ErrorFileOpen = true; } FileInfo info2 = new FileInfo(_filename); _logDirectory = info2.DirectoryName; if (UpdateMainWindow != null) { UpdateMainWindow(); } return(true); } catch (Exception exception) { MessageBox.Show(exception.Message, "SiRFLive...", MessageBoxButtons.OK, MessageBoxIcon.Hand); if (UpdateMainWindow != null) { UpdateMainWindow(); } return(false); } }
private LoggingStates UpdateLoggingState() { if ((_LoggingState == LoggingStates.delayed_logging) && (DateTime.Now.CompareTo(_DelayedLoggingStartTime) >= 0)) { if (_DurationLoggingStopTime > DateTime.Now) { _LoggingState = LoggingStates.duration_logging; } else { _LoggingState = LoggingStates.logging; } return _LoggingState; } if (_LoggingState == LoggingStates.duration_logging) { string msgStr = string.Format("Duration Logging Stop Time: {0} -- {1}", _DurationLoggingStopTime.ToString(), filename); _DurationLoggingStatusLabel.BeginInvoke((MethodInvoker)delegate { _DurationLoggingStatusLabel.Text = msgStr; }); if (DateTime.Now.CompareTo(_DurationLoggingStopTime) >= 0) { LoggingStoppedTime = DateTime.Now; _LoggingState = LoggingStates.stopped_logging; closeFileHandler(); return _LoggingState; } } return _LoggingState; }
public bool WriteLine(string msg) { EventHandler method = null; try { if (_LoggingState == LoggingStates.idle) { return true; } if (((_LoggingState == LoggingStates.logging) || (_LoggingState == LoggingStates.duration_logging)) && m_FileOpen) { lock (lockwrite) { _myWriter.WriteLine(msg); } } if ((_LoggingState == LoggingStates.delayed_logging) || (_LoggingState == LoggingStates.duration_logging)) { LoggingState = UpdateLoggingState(); } if (_LoggingState == LoggingStates.stopped_logging) { if (method == null) { method = delegate { _DurationLoggingStatusLabel.Text = "Logging Stopped at: " + LoggingStoppedTime.ToString(); }; } _DurationLoggingStatusLabel.BeginInvoke(method); _LoggingState = LoggingStates.idle; if (UpdateMainWindow != null) { UpdateMainWindow(); } } LoggingStates states1 = _LoggingState; } catch { return false; } return true; }
public bool OpenFile(string inFilename) { try { closeFileHandler(); _filename = inFilename; if (File.Exists(inFilename)) { new FileInfo(inFilename); string str = string.Format("File exists: {0}", inFilename); frmDialogWith3Button button = new frmDialogWith3Button("Log Message", "&Append", "&Overwrite", "&Cancel"); button.DisplayMessage = str; switch (button.ShowDialog()) { case DialogResult.OK: m_fileWriter = new FileStream(inFilename, FileMode.Append); goto Label_009F; case DialogResult.Yes: m_fileWriter = new FileStream(inFilename, FileMode.Create); goto Label_009F; } if (UpdateMainWindow != null) { UpdateMainWindow(); } return false; } m_fileWriter = new FileStream(inFilename, FileMode.Create); Label_009F: if (_isBin) { m_binaryWriter = new BinaryWriter(m_fileWriter); _myWriter = new writeBin(m_binaryWriter); } else { m_streamwriter = new StreamWriter(m_fileWriter); _myWriter = new writeText(m_streamwriter); } if (_LoggingState == LoggingStates.idle) { _LoggingState = LoggingStates.logging; } m_FileOpen = true; if ((_version != string.Empty) && !inFilename.EndsWith(".csv")) { StringBuilder builder = new StringBuilder(); builder.Append("SiRFLive Version: "); builder.Append(_version); builder.Append("\r\n"); builder.Append(DateTime.Now.ToLongDateString()); builder.Append("\r\nPC: "); builder.Append(PCname); builder.Append("\r\nPhysical Connection: "); builder.Append(PhysicalConnection); builder.Append("\r\n"); builder.Append(FirmwareSWVersion); builder.Append("\r\nDUT Name: "); builder.Append(DUTName); builder.Append("\r\n"); Write(builder.ToString()); FileInfo info = new FileInfo(inFilename); if (info.Extension == string.Empty) { _errorFilename = inFilename + "_error.txt"; } else { _errorFilename = inFilename.Replace(info.Extension, "_error.txt"); } m_errorLogWriter = new StreamWriter(_errorFilename, false); m_ErrorFileOpen = true; } FileInfo info2 = new FileInfo(_filename); _logDirectory = info2.DirectoryName; if (UpdateMainWindow != null) { UpdateMainWindow(); } return true; } catch (Exception exception) { MessageBox.Show(exception.Message, "SiRFLive...", MessageBoxButtons.OK, MessageBoxIcon.Hand); if (UpdateMainWindow != null) { UpdateMainWindow(); } return false; } }
public bool CloseFile() { EventHandler method = null; _LoggingState = LoggingStates.idle; if (_DurationLoggingStatusLabel != null) { if (method == null) { method = delegate { _DurationLoggingStatusLabel.Text = filename; }; } _DurationLoggingStatusLabel.BeginInvoke(method); } return closeFileHandler(); }