예제 #1
0
파일: Parser.cs 프로젝트: Premx/Snip_GUI
 private void registerlinelist(SortableBindingList <Line> ltemp, int threadid)
 {
     ListofLinelist.Add(ltemp);
 }
예제 #2
0
파일: Parser.cs 프로젝트: Premx/Snip_GUI
        private void parse(int totalline, StreamReader sr, int threadid)
        {
            Console.WriteLine("Thread {0} started!", Thread.CurrentThread.ManagedThreadId);

            String line = "";

            SortableBindingList <Line> linelist = new SortableBindingList <Line>();

            Dictionary <String, int>[] cache = new Dictionary <string, int> [6];


            while ((line = readStreamLine(sr)) != null)
            {
                Match regexMatch = Regex.Match(line, logEntryPattern);

                if (regexMatch.Groups.Count < 10)
                {
                    return;
                }

                //Progressbar
                //if ((currentLine % progressbarPara) == 0)
                //{
                //    Progressbar(currentLine, tillLine, Thread.CurrentThread.ToString());
                //}

                //using keys from listbox1
                if (useKeys)
                {
                    bool foundsomething = false;
                    bool exit           = false;
                    foreach (String key in keys)
                    {
                        if (line.Contains(key))
                        {
                            //|| or mode
                            //At least one key must be found
                            foundsomething = true;
                            if (keymode == 0)
                            {
                                break;
                            }
                        }
                        else
                        {
                            //&& and mode
                            //Every key must be found
                            if (keymode == 1)
                            {
                                exit = true;
                                break;
                            }
                        }
                    }
                    //go back
                    if ((!foundsomething) || exit)
                    {
                        continue;
                    }
                }


                //Extracting Data from Regex Match
                DateTime d = DateTime.MinValue;
                try{
                    d = DateTime.ParseExact(regexMatch.Groups[INDEXdate].Value, (datePattern + " K"), System.Globalization.CultureInfo.InvariantCulture);
                }
                catch (System.FormatException e)
                {
                }


                String hostname = getItem(regexMatch, INDEXip);

                String request = getItem(regexMatch, INDEXrequest);


                String trafficstr = getItem(regexMatch, INDEXtraffic);

                //Log Syntax traffic 0 = '-'
                if (trafficstr == "-")
                {
                    trafficstr = "0";
                }
                int traffic = int.Parse(trafficstr);


                String agent = getItem(regexMatch, INDEXagent);

                //Filter
                if (agent.Length > 3)
                {
                    if (agent.Substring(0, 3) == "\" \"")
                    {
                        agent = agent.Substring(3, agent.Length - 3);
                    }
                    if (agent[0] == '<')
                    {
                        agent = "";
                    }
                }

                Match  mBrowser = Regex.Match(agent, browserPattern);
                String browser  = "";
                if (mBrowser.Success && mBrowser.Groups[0].Value[0] != '<')
                {
                    browser = mBrowser.Groups[0].Value;
                }


                Line l = new Line(hostname, d, request, short.Parse(getItem(regexMatch, INDEXhttpcode)), traffic, browser);//,agent);
                linelist.Add(l);


                dicchecker(cache, 0, hostname);
                dicchecker(cache, 1, d.ToString());
                dicchecker(cache, 2, request);
                dicchecker(cache, 3, l.httpcode.ToString());
                dicchecker(cache, 4, traffic.ToString());
                dicchecker(cache, 5, browser);


                //dicchecker(cache, 6 , agent);
            }
            //Progressbar(tillLine, tillLine, Thread.CurrentThread.ToString());



            //form1instance.setGridDataView(linelist,cache);

            //UpdateStatus(String.Format("Complete: {0} Entries", linelist.Count));
            registerlinelist(linelist, threadid);
            registercachelist(cache);
            if (threads - threadcontrolI == 1)
            {
                t2 = DateTime.Now;
            }

            threadcontrolI++;
            Console.WriteLine("Thread {0} stopped!", threadid);
        }