public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
            {
                if (destType == typeof(string) && value is LogSection)
                {
                    // Cast the value to an Employee type
                    LogSection pp = (LogSection)value;

                    return(pp.StartDateTime.ToString() + ", " + pp.EndDateTime.ToString());
                }
                return(base.ConvertTo(context, culture, value, destType));
            }
Example #2
0
 private void CloseAndReturnLogSection()
 {
     if (listBoxControl1.SelectedItem != null)
     {
         if (listBoxControl1.SelectedItem is LogSection)
         {
             LogSection ls = (LogSection)listBoxControl1.SelectedItem;
             _selectedStart = ls.StartDateTime;
             _selectedEnd   = ls.EndDateTime;
             _valid         = true;
             DialogResult   = DialogResult.OK;
             Close();
         }
     }
 }
 public bool Contains(LogSection value)
 {
     // If value is not of type Int16, this will return false.
     return(List.Contains(value));
 }
 public void Remove(LogSection value)
 {
     List.Remove(value);
 }
 public void Insert(int index, LogSection value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(LogSection value)
 {
     return(List.IndexOf(value));
 }
 public int Add(LogSection value)
 {
     return(List.Add(value));
 }
 public bool Contains(LogSection value)
 {
     // If value is not of type Int16, this will return false.
     return (List.Contains(value));
 }
 public int Add(LogSection value)
 {
     return (List.Add(value));
 }
 public void Remove(LogSection value)
 {
     List.Remove(value);
 }
 public void Insert(int index, LogSection value)
 {
     List.Insert(index, value);
 }
 public int IndexOf(LogSection value)
 {
     return (List.IndexOf(value));
 }
        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;
        }