public LogSectionCollectionPropertyDescriptor(LogSectionCollection coll, int idx) : base("#" + idx.ToString(), null) { this.collection = coll; this.index = idx; }
private LogSectionCollection AnalyseFile(string filename) { LogSectionCollection lsc = new LogSectionCollection(); DateTime _previousDateTime = DateTime.MinValue; DateTime _sectionStart = DateTime.MinValue; DateTime _sectionEnd = DateTime.MinValue; string[] alllines = File.ReadAllLines(filename); //using (StreamReader sr = new StreamReader(filename)) { //string line = string.Empty; //while ((line = sr.ReadLine()) != null) foreach (string line in alllines) { char[] sep = new char[1]; sep.SetValue('|', 0); char[] sepequals = new char[1]; sepequals.SetValue('=', 0); if (line.Length > 0) { //10/03/2009 07:33:06.187|P_Manifold10=-0.64|Lufttemp=8.00|Rpm=1660.00|Bil_hast=15.20|Ign_angle=28.50|AD_EGR=127.00|AFR=17.86|InjectorDC=2.49|Power=0.00|Torque=0.00| // fetch all values from the line including the timestamp string[] values = line.Split(sep); if (values.Length > 1) { try { string dtstring = (string)values.GetValue(0); DateTime dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2))); if (dtstring.Length > 20) { dt = new DateTime(Convert.ToInt32(dtstring.Substring(6, 4)), Convert.ToInt32(dtstring.Substring(3, 2)), Convert.ToInt32(dtstring.Substring(0, 2)), Convert.ToInt32(dtstring.Substring(11, 2)), Convert.ToInt32(dtstring.Substring(14, 2)), Convert.ToInt32(dtstring.Substring(17, 2)), Convert.ToInt32(dtstring.Substring(20, 3))); } //DateTime dt = Convert.ToDateTime(values.GetValue(0)); if (_previousDateTime == DateTime.MinValue) { _previousDateTime = dt; // sync } TimeSpan ts = new TimeSpan(dt.Ticks - _previousDateTime.Ticks); if (_sectionStart == DateTime.MinValue) { // at least one section _sectionStart = dt; _sectionEnd = dt; // initial } if (ts.TotalSeconds < 10) { _sectionEnd = dt; } else { LogSection ls = new LogSection(); ls.StartDateTime = _sectionStart; ls.EndDateTime = _sectionEnd; ls.Duration = new TimeSpan(ls.EndDateTime.Ticks - ls.StartDateTime.Ticks); lsc.Add(ls); // reset probes //_previousDateTime = _sectionEnd; _previousDateTime = DateTime.MinValue; _sectionStart = DateTime.MinValue; _sectionEnd = DateTime.MinValue; } _previousDateTime = dt; } catch (Exception E) { Console.WriteLine(E.Message); } } } } } if (_sectionStart != DateTime.MinValue && _sectionEnd != DateTime.MinValue) { LogSection ls = new LogSection(); ls.StartDateTime = _sectionStart; ls.EndDateTime = _sectionEnd; ls.Duration = new TimeSpan(ls.EndDateTime.Ticks - ls.StartDateTime.Ticks); lsc.Add(ls); } return lsc; }