private void BUT_bintolog_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Binary Log|*.bin"; ofd.ShowDialog(); if (File.Exists(ofd.FileName)) { List <string> log = BinaryLog.ReadLog(ofd.FileName); SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "log|*.log"; DialogResult res = sfd.ShowDialog(); if (res == System.Windows.Forms.DialogResult.OK) { StreamWriter sw = new StreamWriter(sfd.OpenFile()); foreach (string line in log) { sw.Write(line); } sw.Close(); } } }
public static void log(string fn) { string[] filelines; if (fn.ToLower().EndsWith(".bin")) { filelines = BinaryLog.ReadLog(fn).ToArray(); } else { // read the file filelines = File.ReadAllLines(fn); } // store all the arrays List <MLArray> mlList = new List <MLArray>(); // store data to putinto the arrays Dictionary <string, List <double[]> > data = new Dictionary <string, List <double[]> >(); // store line item lengths Hashtable len = new Hashtable(); // store whats we have seen in the log Hashtable seen = new Hashtable(); // store the params seen SortedDictionary <string, double> param = new SortedDictionary <string, double>(); // keep track of line no int a = 0; foreach (var line in filelines) { a++; Console.Write(a + "\r"); string strLine = line.Replace(", ", ","); strLine = strLine.Replace(": ", ":"); string[] items = strLine.Split(',', ':'); // process the fmt messages if (line.StartsWith("FMT")) { // +1 for line no string[] names = new string[items.Length - 5 + 1]; names[0] = "LineNo"; Array.ConstrainedCopy(items, 5, names, 1, names.Length - 1); MLArray format = CreateCellArray(items[3] + "_label", names); if (items[3] == "PARM") { } else { mlList.Add(format); } len[items[3]] = names.Length; } // process param messages else if (line.StartsWith("PARM")) { try { param[items[1]] = double.Parse(items[2], CultureInfo.InvariantCulture); } catch { } }// everyting else is generic else { // make sure the line is long enough if (items.Length < 2) { continue; } // check we have a valid fmt message for this message type if (!len.ContainsKey(items[0])) { continue; } // check the fmt length matchs what the log has if (items.Length != (int)len[items[0]]) { continue; } // make it as being seen seen[items[0]] = 1; double[] dbarray = new double[items.Length]; // set line no dbarray[0] = a; for (int n = 1; n < items.Length; n++) { try { dbarray[n] = double.Parse(items[n], CultureInfo.InvariantCulture); } catch { } } if (!data.ContainsKey(items[0])) { data[items[0]] = new List <double[]>(); } data[items[0]].Add(dbarray); } } foreach (var item in data) { double[][] temp = item.Value.ToArray(); MLArray dbarray = new MLDouble(item.Key, temp); mlList.Add(dbarray); } MLCell cell = new MLCell("PARM", new int[] { param.Keys.Count, 2 }); int m = 0; foreach (var item in param.Keys) { cell[m, 0] = new MLChar(null, item.ToString()); cell[m, 1] = new MLDouble(null, new double[] { (double)param[item] }, 1); m++; } mlList.Add(cell); MLArray seenmsg = CreateCellArray("Seen", seen.Keys.Cast <string>().ToArray()); mlList.Add(seenmsg); try { MatFileWriter mfw = new MatFileWriter(fn + ".mat", mlList, true); } catch (Exception err) { MessageBox.Show("There was an error when creating the MAT-file: \n" + err.ToString(), "MAT-File Creation Error!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } }
private void Form1_Load(object sender, EventArgs e) { Hashtable seenmessagetypes = new Hashtable(); OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.InitialDirectory = MainV2.LogDir; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { Stream stream; if (openFileDialog1.FileName.ToLower().EndsWith(".bin")) { log.Info("before " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); // extract log - converts to assci lines var loglines = BinaryLog.ReadLog(openFileDialog1.FileName); log.Info("loglines " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); GC.Collect(); log.Info("loglines2 " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); // create temp file string tempfile = Path.GetTempFileName(); log.Info("temp file " + tempfile); stream = File.Open(tempfile, FileMode.Create, FileAccess.ReadWrite, FileShare.Delete); // save ascii lines to file foreach (string line in loglines) { stream.Write(ASCIIEncoding.ASCII.GetBytes(line), 0, line.Length); } stream.Flush(); // back to stream start stream.Seek(0, SeekOrigin.Begin); loglines.Clear(); loglines = null; // force memory reclaim after loglines clear GC.Collect(); log.Info("loglines.clear " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); } else { stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); } logdata = DFLog.ReadLog(stream); this.Text = "Log Browser - " + Path.GetFileName(openFileDialog1.FileName); log.Info("about to create DataTable " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); m_dtCSV = new DataTable(); log.Info("process to datagrid " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); bool largelog = logdata.Count > 500000 ? true : false; foreach (var item in logdata) { if (item.items != null) { while (m_dtCSV.Columns.Count < (item.items.Length + typecoloum)) { m_dtCSV.Columns.Add(); } seenmessagetypes[item.msgtype] = ""; if (largelog) { continue; } DataRow dr = m_dtCSV.NewRow(); dr[0] = item.lineno; dr[1] = item.time.ToString("yyyy-MM-dd HH:mm:ss.fff"); for (int a = 0; a < item.items.Length; a++) { dr[a + typecoloum] = item.items[a]; } m_dtCSV.Rows.Add(dr); } } log.Info("Done " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); //PopulateDataTableFromUploadedFile(stream); stream.Close(); log.Info("set dgv datasourse " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); if (MainV2.MONO) { //if (m_dtCSV.Rows.Count > 5000) // { // CustomMessageBox.Show("This log apears to be a large log, the grid view will be disabled.\nAll graphing will still work however", "Large Log"); // dataGridView1.Visible = false; // } // else { BindingSource bs = new BindingSource(); bs.DataSource = m_dtCSV; dataGridView1.DataSource = bs; } } else { dataGridView1.VirtualMode = true; dataGridView1.RowCount = logdata.Count; dataGridView1.ColumnCount = m_dtCSV.Columns.Count; } dataGridView1.Columns[0].Visible = false; log.Info("datasource set " + (GC.GetTotalMemory(false) / 1024.0 / 1024.0)); } catch (Exception ex) { CustomMessageBox.Show("Failed to read File: " + ex.ToString()); } foreach (DataGridViewColumn column in dataGridView1.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } CreateChart(zg1); ResetTreeView(seenmessagetypes); if (DFLog.logformat.Count == 0) { CustomMessageBox.Show("Log Browse will not function correctly without FMT messages in your log.\nThese appear to be missing from your log.", "Error"); this.Close(); return; } } else { this.Close(); return; } }
private void Form1_Load(object sender, EventArgs e) { rowno = 1; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.InitialDirectory = MainV2.LogDir; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { Stream stream; if (openFileDialog1.FileName.ToLower().EndsWith(".bin")) { // extract log List <string> loglines = BinaryLog.ReadLog(openFileDialog1.FileName); // convert log to memory stream; stream = new MemoryStream(); // create single string with entire log foreach (string line in loglines) { stream.Write(ASCIIEncoding.ASCII.GetBytes(line), 0, line.Length); } // back to stream start stream.Seek(0, SeekOrigin.Begin); } else { stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); } this.Text = "Log Browser - " + Path.GetFileName(openFileDialog1.FileName); PopulateDataTableFromUploadedFile(stream); stream.Close(); dataGridView1.DataSource = m_dtCSV; dataGridView1.Columns[0].Visible = false; } catch (Exception ex) { CustomMessageBox.Show("Failed to read File: " + ex.ToString()); } foreach (DataGridViewColumn column in dataGridView1.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } DrawMap(); CreateChart(zg1); } else { return; } }
private void Form1_Load(object sender, EventArgs e) { rowno = 1; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Log Files|*.log;*.bin"; openFileDialog1.FilterIndex = 2; openFileDialog1.RestoreDirectory = true; openFileDialog1.InitialDirectory = MainV2.LogDir; if (openFileDialog1.ShowDialog() == DialogResult.OK) { try { Stream stream; if (openFileDialog1.FileName.ToLower().EndsWith(".bin")) { // extract log List <string> loglines = BinaryLog.ReadLog(openFileDialog1.FileName); // convert log to memory stream; stream = new MemoryStream(); // create single string with entire log foreach (string line in loglines) { stream.Write(ASCIIEncoding.ASCII.GetBytes(line), 0, line.Length); } // back to stream start stream.Seek(0, SeekOrigin.Begin); } else { stream = File.Open(openFileDialog1.FileName, FileMode.Open, FileAccess.Read, FileShare.Read); } var logdata = DFLog.ReadLog(stream); this.Text = "Log Browser - " + Path.GetFileName(openFileDialog1.FileName); m_dtCSV = new DataTable(); log.Info("process to datagrid"); foreach (var item in logdata) { if (item.items != null) { while (m_dtCSV.Columns.Count < (item.items.Length + typecoloum)) { m_dtCSV.Columns.Add(); } DataRow dr = m_dtCSV.NewRow(); dr[0] = item.lineno; dr[1] = item.time.ToString("yyyy-MM-dd HH:mm:ss.fff"); for (int a = 0; a < item.items.Length; a++) { dr[a + typecoloum] = item.items[a]; } m_dtCSV.Rows.Add(dr); } } log.Info("Done"); //PopulateDataTableFromUploadedFile(stream); stream.Close(); log.Info("set dgv datasourse"); dataGridView1.DataSource = m_dtCSV; dataGridView1.Columns[0].Visible = false; log.Info("datasource set"); } catch (Exception ex) { CustomMessageBox.Show("Failed to read File: " + ex.ToString()); } foreach (DataGridViewColumn column in dataGridView1.Columns) { column.SortMode = DataGridViewColumnSortMode.NotSortable; } log.Info("Get map"); DrawMap(); log.Info("map done"); CreateChart(zg1); } else { this.Close(); return; } }