Exemplo n.º 1
0
        public bool Read()
        {
            if (this._sr == null)
            {
                return(false);
            }

            // read a line of the log
            string line = _sr.ReadLine();

            if (line == null)
            {
                return(false);
            }

            // obtain the data from each column and put the data array
            Lexer        l  = new Lexer(new StringReader(line));
            LexTokenList ll = l.Lex();
            int          ci = 0;                                        // start at first column

            if (ll.Count > 11)
            {
                ci = 0;
            }
            foreach (LexToken lt in ll)
            {
                if (ci >= _Data.Length || lt.Type == LexTokenTypes.EOF)
                {
                    break;
                }

                if (ci == DATETIME_FIELD)
                {
                    _Data[ci] = GetDateTime(lt.Value);
                }
                else if (ci == REQUEST_FIELD)
                {                       // break the request into multiple fields; command, url, http type
                    string[] reqs = lt.Value.Split(' ');

                    string req_cmd        = null;
                    string req_url        = null;
                    string req_type       = null;
                    string req_parameters = null;

                    if (reqs == null)
                    {
                    }
                    else if (reqs.Length >= 3)
                    {
                        req_cmd  = reqs[0];
                        req_url  = reqs[1];
                        req_type = reqs[2];
                    }
                    else if (reqs.Length == 2)
                    {
                        req_cmd = reqs[0];
                        req_url = reqs[1];
                    }
                    else if (reqs.Length == 1)
                    {
                        req_url = reqs[0];
                    }

                    if (req_url != null)
                    {
                        string [] up = req_url.Split('?');
                        if (up.Length > 1)
                        {
                            req_url        = up[0];
                            req_parameters = up[1];
                        }
                    }
                    _Data[ci++] = req_type;
                    _Data[ci++] = req_url;
                    _Data[ci++] = req_type == "HTTP/1.1"? "HTTP/1.1": req_type;
                    _Data[ci++] = req_parameters;

                    continue;
                }
                else if (ci == BYTES_FIELD)
                {
                    double v = 0;
                    if (lt.Value.Length == 0 || lt.Value == "-")
                    {
                    }
                    else
                    {
                        try
                        {
                            v = Convert.ToDouble(lt.Value);
                        }
                        catch
                        {
                        }
                    }
                    _Data[ci] = v;
                }
                else
                {
                    _Data[ci] = lt.Value;
                }
                ci++;                                                   // go to next column
            }

            while (ci < _Data.Length)
            {
                _Data[ci++] = null;
            }

            return(true);
        }