示例#1
0
 void difgen_onExportProgress(object sender, CSVGenerator.ProgressEventArgs e)
 {
     frmProgressLogWorks.SetProgressPercentage(e.Percentage);
 }
示例#2
0
        private void ConvertFileToCSV(string filename, bool AutoExport)
        {
            System.Windows.Forms.Application.DoEvents();
            DateTime startDate = DateTime.MaxValue;
            DateTime endDate = DateTime.MinValue;
            try
            {
                SymbolCollection sc = new SymbolCollection();
                string[] alllines = File.ReadAllLines(filename);
                //using (StreamReader sr = new StreamReader(filename))
                {
                    //string line = string.Empty;
                    char[] sep = new char[1];
                    char[] sep2 = new char[1];
                    //int linecount = 0;
                    sep.SetValue('|', 0);
                    sep2.SetValue('=', 0);
                    //while ((line = sr.ReadLine()) != null)

                    foreach (string line in alllines)
                    {
                        string[] values = line.Split(sep);
                        if (values.Length > 0)
                        {
                            try
                            {
                                //dd/MM/yyyy HH:mm:ss
                                //string logline = DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss") + "|";

                                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 (dt > endDate) endDate = dt;
                                if (dt < startDate) startDate = dt;
                                for (int t = 1; t < values.Length; t++)
                                {
                                    string subvalue = (string)values.GetValue(t);
                                    string[] subvals = subvalue.Split(sep2);
                                    if (subvals.Length == 2)
                                    {
                                        string varname = (string)subvals.GetValue(0);
                                        bool sfound = false;
                                        foreach (SymbolHelper sh in sc)
                                        {
                                            if (sh.Varname == varname || sh.Userdescription == varname)
                                            {
                                                sfound = true;
                                            }
                                        }
                                        SymbolHelper nsh = new SymbolHelper();
                                        nsh.Varname = varname;
                                        if (!sfound) sc.Add(nsh);
                                    }
                                }
                            }
                            catch (Exception pE)
                            {
                                logger.Debug(pE.Message);
                            }
                        }
                    }
                }

                if (AutoExport)
                {
                    foreach (SymbolHelper sh in sc)
                    {
                        sh.Color = GetColorFromRegistry(sh.Varname);
                    }
                    CSVGenerator csvgen = new CSVGenerator();
                    csvgen.AppSettings = m_appSettings;

                    //csvgen.LowAFR = m_appSettings.WidebandLowAFR;
                    //csvgen.HighAFR = m_appSettings.WidebandHighAFR;
                    //csvgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                    //csvgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                    csvgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                    //csvgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                    csvgen.UseWidebandInput = false;

                    csvgen.onExportProgress += new CSVGenerator.ExportProgress(difgen_onExportProgress);
                    frmProgressLogWorks = new frmProgress();
                    frmProgressLogWorks.SetProgress("Exporting to CSV");
                    frmProgressLogWorks.Show();
                    System.Windows.Forms.Application.DoEvents();
                    try
                    {
                        csvgen.ConvertFileToCSV(filename, sc, startDate, endDate);
                    }
                    catch (Exception expE1)
                    {
                        logger.Debug(expE1.Message);
                    }
                    frmProgressLogWorks.Close();
                }
                else
                {

                    // show selection screen
                    frmPlotSelection plotsel = new frmPlotSelection(suiteRegistry);
                    foreach (SymbolHelper sh in sc)
                    {
                        plotsel.AddItemToList(sh.Varname);
                    }
                    plotsel.Startdate = startDate;
                    plotsel.Enddate = endDate;
                    plotsel.SelectAllSymbols();
                    if (plotsel.ShowDialog() == DialogResult.OK)
                    {
                        sc = plotsel.Sc;
                        endDate = plotsel.Enddate;
                        startDate = plotsel.Startdate;
                        CSVGenerator csvgen = new CSVGenerator();
                        LogFilters filterhelper = new LogFilters(suiteRegistry);
                        csvgen.SetFilters(filterhelper.GetFiltersFromRegistry());
                        csvgen.AppSettings = m_appSettings;
                        //csvgen.LowAFR = m_appSettings.WidebandLowAFR;
                        //csvgen.HighAFR = m_appSettings.WidebandHighAFR;
                        //csvgen.MaximumVoltageWideband = m_appSettings.WidebandHighVoltage;
                        //csvgen.MinimumVoltageWideband = m_appSettings.WidebandLowVoltage;
                        csvgen.WidebandSymbol = m_appSettings.WideBandSymbol;
                        //csvgen.UseWidebandInput = m_appSettings.UseWidebandLambdaThroughSymbol;
                        csvgen.UseWidebandInput = false;

                        csvgen.onExportProgress += new CSVGenerator.ExportProgress(difgen_onExportProgress);
                        frmProgressLogWorks = new frmProgress();
                        frmProgressLogWorks.SetProgress("Exporting to CSV");
                        frmProgressLogWorks.Show();
                        System.Windows.Forms.Application.DoEvents();
                        try
                        {
                            if (!csvgen.ConvertFileToCSV(filename, sc, startDate, endDate))
                            {
                                frmInfoBox info = new frmInfoBox("No data was found to export!");
                            }
                        }
                        catch (Exception expE2)
                        {
                            logger.Debug(expE2.Message);
                        }
                        frmProgressLogWorks.Close();
                    }
                    TimeSpan ts = new TimeSpan(endDate.Ticks - startDate.Ticks);
                    //MessageBox.Show("LogFile should be " + ts.ToString());
                }
            }
            catch (Exception E)
            {
                logger.Debug(E.Message);
            }
        }