示例#1
0
文件: Form1.cs 项目: fanjc320/TestAll
        private void parseLog_Click(object sender, EventArgs e)
        {
            DateTime begin   = DateTime.Now;
            Array    tbNames = m_AllxmlTables.Keys.ToArray <TBName>();

            if (tbNames.Length == 0)
            {
                MessageBox.Show("loadXml error!");
                return;
            }

            try
            {
                fs = new FileStream(logPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                sr = new StreamReader(fs, System.Text.Encoding.Default);
                if (fs.CanSeek)
                {
                    //fs.Seek(0, SeekOrigin.Begin);
                }
            }
            catch (Exception)
            {
                if (sr != null)
                {
                    sr.Close();
                }
                MessageBox.Show("无法打开文件,请检查此文件是否被其他程序占用!");
                return;
            }

            string str = "";
            TBName tb  = "";

            //while ((str = sr.ReadLine()) != null)
            bool b_parsed = false;
            int  alllines = 0;

            while (true)
            {
                str = sr.ReadLine();
                if (str == null)
                {
                    if (!b_parsed)
                    {
                        Parselog();
                        AlllogTables.Clear();
                        if (!m_Parsed)
                        {
                            TimeSpan span = DateTime.Now - begin;
                            Console.WriteLine(string.Format("###################### parseLog_End 耗时:{0}秒", span.Seconds));
                        }
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        m_Parsed = true;
                    }

                    b_parsed = true;
                    continue;
                }
                b_parsed = false;

                string[] fields = str.Split('|');
                Debug.Assert(fields.Length > 2);
                tb = fields[0];
                fieldVList fvls = new fieldVList();

                for (int i = 1; i < fields.Length; ++i)
                {
                    fvls.Add(fields[i]);
                }
                if (AlllogTables.ContainsKey(tb))
                {
                    AlllogTables[tb].Add(fvls);
                }
                else
                {
                    AlllogTables[tb] = new List <fieldVList>();
                    AlllogTables[tb].Add(fvls);
                }
                ++alllines;

                //Console.WriteLine(string.Format("alllines:{0} count:{1}",alllines,AlllogTables.Count));
            }
        }
示例#2
0
文件: Form1.cs 项目: fanjc320/TestAll
        void Parselog()
        {
            //m_AlldtTables.Clear();
            foreach (var item in AlllogTables)
            {
                TBName    tbname = item.Key;
                DataTable dt     = new DataTable(tbname);
                for (int i = 0; i < m_AllxmlTables[tbname].Count; ++i)
                {
                    string columname = m_AllxmlTables[tbname][i].name;
                    dt.Columns.Add(m_AllxmlTables[tbname][i].name);
                    dt.Columns[i].ColumnName = m_AllxmlTables[tbname][i].name;
                }
                int bupipei = 0;
                for (int i = 0; i < AlllogTables[tbname].Count; ++i)
                {
                    fieldVList         ls = AlllogTables[tbname][i];
                    List <stEntryNode> st = m_AllxmlTables[tbname];
                    if (st.Count != ls.Count && bupipei == 0)
                    {
                        ++bupipei;
                        //textBoxSql.AppendText(string.Format("~~~~不匹配error:{0} xml字段个数:{1} log字段个数:{2}\n", tbname, st.Count, ls.Count));
                    }

                    StringBuilder s_out = new StringBuilder();

                    DataRow dr;
                    dr = dt.NewRow();
                    for (int j = 0; j < ls.Count && j < dr.ItemArray.Length; ++j)
                    {
                        dr[j] = ls[j];
                        if (m_Parsed)
                        {
                            s_out.AppendFormat("{0}:{1}|", dt.Columns[j].ColumnName, ls[j]);
                        }
                    }
                    dt.Rows.Add(dr);

                    ++m_CurLine;

                    if (m_Parsed)
                    {
                        Console.WriteLine(string.Format("{0}:{1}", dt.TableName, ParseOutStr(s_out.ToString())));
                        //richTextBox1.AppendTextColorful(string.Format("{0}:{1}\n", dt.TableName, ParseOutStr(s_out.ToString())),Color.Red);
                        //AppendTextColorful(string.Format("{0}:{1}\n", dt.TableName, ParseOutStr(s_out.ToString())),Color.Olive);
                    }
                }
                if (tbname.Contains("sec") || tbname.Contains("Sec"))
                {
                }
                else
                {
                    //m_AlldtTables.Add(tbname, dt);

                    if (dt != null)
                    {
                        MySqlDbHelper helper = new MySqlDbHelper();
                        helper.InsertByDataTable(ref dt);

                        //textBoxSql.AppendText(string.Format("{0}导入行数:{1}\n", dt.TableName, dt.Rows.Count));
                        //Console.WriteLine(string.Format("{0}导入行数:{1}", dt.TableName, dt.Rows.Count));
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(string.Format("**当前行数:{0}", m_CurLine));
                        //richTextBox1.AppendTextColorful(string.Format("{0}导入行数:{1}", dt.TableName, dt.Rows.Count),Color.Green);
                    }
                }
            }
        }
示例#3
0
文件: Form1.cs 项目: fanjc320/TestAll
        /*
         * void InstanceMgr::ReloadTLog(bool aupdateline)
         * {
         *  cout << "ReloadTLog" << endl;
         *  string data;
         *  //ifstream map("game.log.0629");
         *  ifstream map("qqq.txt");
         *  if (!map.is_open())
         *  {
         *      sLog.outError("LoadJsonFile", "LoadJsonFile no find (%s)", "game.log");
         *      return;
         *  }
         *  char buffer[4096];
         *  uint32 nub = 1;
         *  while (!map.eof())
         *  {
         *      map.getline(buffer, 4096);
         *      data = buffer;
         *      std::vector < std::string> datelist = StrSplit(data, "|");
         *      if (datelist.size() <= 8)
         *          continue;
         *      RLogData ldata;
         *      ldata.CmdStr = datelist[0];
         *      ldata.OpenId = datelist[7];
         *      for (uint32 i = 9; i < datelist.size(); i++)
         *      {
         *          ldata.datalist.push_back(datelist[i]);
         *      }
         *      m_LogMap[ldata.OpenId][ldata.CmdStr].push_back(ldata);
         *      nub++;
         *      //	if (nub > 10000) break;
         *  }
         *  cout << "ReloadTLog end" << endl;
         * }*/
        private void parseLog_Click(object sender, EventArgs e)
        {
            Array tbNames = m_AllxmlTables.Keys.ToArray <TBName>();

            if (tbNames.Length == 0)
            {
                MessageBox.Show("请先点击loadXml!");
                return;
            }
            Dictionary <TBName, List <fieldVList> > AlllogTables = new Dictionary <TBName, List <fieldVList> >();

            //初始化key值
            for (int i = 0; i < tbNames.Length; ++i)
            {
                AlllogTables[(TBName)tbNames.GetValue(i)] = new List <fieldVList>();
            }
            //Debug.Assert(xmlTables.Count>0,"请先loadXml!");
            int alllines = 0;

            //for (int k=0;k<7;++k)
            //{
            StreamReader sr = null;

            try
            {
                //logPath = string.Format("E:/xa{0}",'a');
                FileStream fs = new FileStream(logPath, FileMode.Open, FileAccess.ReadWrite);
                sr = new StreamReader(fs, System.Text.Encoding.GetEncoding(936));
            }
            catch (Exception)
            {
                if (sr != null)
                {
                    sr.Close();
                }
                MessageBox.Show("无法打开文件,请检查此文件是否被其他程序占用!");
                return;
            }

            string str = "";
            //string s = Console.ReadLine();
            TBName tb = "";

            int lines = 0;

            while ((str = sr.ReadLine()) != null)
            {
                fieldVList fvls = new fieldVList();

                ++lines;
                if (lines > 1000000)
                {
                    //sr.DiscardBufferedData();//会出错
                    lines = 0;
                }
                ++alllines;
                //fvls.Clear();
                string[] fields = str.Split('|');
                Debug.Assert(fields.Length > 2);
                tb = fields[0];

                for (int i = 1; i < fields.Length; ++i)
                {
                    fvls.Add(fields[i]);
                }
                if (AlllogTables.ContainsKey(tb))
                {
                    AlllogTables[tb].Add(fvls);
                }
                else
                {
                    AlllogTables[tb] = new List <fieldVList>();
                    AlllogTables[tb].Add(fvls);
                }
            }
            textBoxSql.AppendText(string.Format("-----------------已将log文件解析为字典!-共{0}个table-{1}行-\n", AlllogTables.Count, alllines));

            sr.Close();
            //}

            m_AlldtTables.Clear();
            //int alllines = 0;
            foreach (var item in AlllogTables)
            {
                TBName    tbname = item.Key;
                DataTable dt     = new DataTable(tbname);
                for (int i = 0; i < m_AllxmlTables[tbname].Count; ++i)
                {
                    string columname = m_AllxmlTables[tbname][i].name;
                    dt.Columns.Add(m_AllxmlTables[tbname][i].name);
                    dt.Columns[i].ColumnName = m_AllxmlTables[tbname][i].name;
                }
                int bupipei = 0;
                for (int i = 0; i < AlllogTables[tbname].Count; ++i)
                {
                    ++alllines;
                    fieldVList         ls = AlllogTables[tbname][i];
                    List <stEntryNode> st = m_AllxmlTables[tbname];
                    if (st.Count != ls.Count && bupipei == 0)
                    {
                        ++bupipei;
                        textBoxSql.AppendText(string.Format("{0} xml字段个数:{1} log字段个数:{2}\n", tbname, st.Count, ls.Count));
                        //MessageBox.Show(string.Format("{0}表字段个数xml与log不匹配 bupipei{1}", tbname,bupipei));
                    }
                    //Console.WriteLine(ls.Count);
                    DataRow dr;
                    dr = dt.NewRow();
                    for (int j = 0; j < ls.Count && j < dr.ItemArray.Length; ++j)
                    {
                        dr[j] = ls[j];
                    }
                    dt.Rows.Add(dr);
                }
                if (tbname.Contains("sec") || tbname.Contains("Sec"))
                {
                }
                else
                {
                    m_AlldtTables.Add(tbname, dt);
                }
            }

            textBoxSql.AppendText(string.Format("-----------------已将字典解析为DataTable!-共{0}条记录,{1}个table-\n", alllines, m_AlldtTables.Count));
        }