Beispiel #1
0
        public bool Read()
        {
            if (this._sr == null || _Data == null)
            {
                return(false);
            }

            // Do we already have a row primed?
            if (bFirstRow)
            {                   // yes; but no more
                bFirstRow = false;
                return(true);
            }

            // read a line of the log
            LexTokenList ll = this.GetLine();

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

            // take line and fill the data
            this.FillData(ll);

            return(true);
        }
Beispiel #2
0
        void FillData(LexTokenList ll)
        {
            Type stype = "".GetType();
            int  ci    = 0;

            foreach (LexToken lt in ll)
            {
                if (ci >= _Data.Length || lt.Type == LexTokenTypes.EOF)
                {
                    break;
                }
                // Optimize for no conversion
                if (_Types[ci] == stype || lt.Value == null)
                {
                    _Data[ci++] = lt.Value;
                    continue;
                }
                // We need to do conversion
                try
                {                       // in case of conversion error
                    _Data[ci] = Convert.ChangeType(lt.Value, _Types[ci]);
                }
                catch
                {
                    _Data[ci] = null;
                }
                ci++;
            }

            while (ci < _Data.Length)
            {
                _Data[ci++] = null;
            }
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the Lexer class with the specified
        /// TextReader to lex.
        /// </summary>
        /// <param name="source">A TextReader to lex.</param>
        internal Lexer(TextReader source)
        {
            // token queue
            tokens = new LexTokenList();

            // read the file contents
            reader = new LexCharReader(source);
        }
		/// <summary>
		/// Initializes a new instance of the Lexer class with the specified
		/// TextReader to lex.
		/// </summary>
		/// <param name="source">A TextReader to lex.</param>
		internal Lexer(TextReader source)
		{
			// token queue
			tokens = new LexTokenList();

			// read the file contents
			reader = new LexCharReader(source);
		}
Beispiel #5
0
        LexTokenList GetLine()
        {
            if (_sr == null)
            {
                return(null);
            }

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

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

            // obtain the data from each column and put the data array
            Lexer l = new Lexer(new StringReader(line));

            l.SeparateDatetime = false;
            l.SeparatorChar    = _tcmd.Separator;
            LexTokenList ll = l.Lex();

            return(ll);
        }
		void FillData(LexTokenList ll)
		{
			Type stype = "".GetType();
			int ci=0;
			foreach (LexToken lt in ll)
			{
				if (ci >= _Data.Length || lt.Type == LexTokenTypes.EOF)
					break;
				// Optimize for no conversion
				if (_Types[ci] == stype || lt.Value == null)
				{
					_Data[ci++] = lt.Value;
					continue;
				}
				// We need to do conversion
				try
				{	// in case of conversion error 
					_Data[ci] = Convert.ChangeType(lt.Value, _Types[ci]);
				}
				catch
				{
					_Data[ci] = null;
				}
				ci++;
			}

			while (ci < _Data.Length)
				_Data[ci++] = null;
		}
Beispiel #7
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);
        }
Beispiel #8
0
        Type[] _Types;                                  // types of the columns

        public TxtDataReader(System.Data.CommandBehavior behavior, TxtConnection conn, TxtCommand cmd)
        {
            bFirstRow = false;
            _tconn    = conn;
            _tcmd     = cmd;
            _behavior = behavior;

            string fname     = _tcmd.Url;
            bool   header    = _tcmd.Header;
            char   separator = _tcmd.Separator;

            _sr = GetStream();                                          // get the main stream

            Type tstring = "".GetType();

            LexTokenList ll       = GetLine();
            int          colcount = ll == null? 0: ll.Count - 1; // don't count the end of line

            _Names = _tcmd.Columns;
            if (colcount == 0)
            {
                _sr.Close();
                _sr = null;
                if (_Names == null)
                {
                    return;
                }
                _Types = new Type[_Names.Length];
                for (int ci = 0; ci < _Types.Length; ci++)
                {
                    _Types[ci] = tstring;
                }
                return;
            }

            if (_Names != null && _Names.Length != colcount)
            {
                throw new Exception(string.Format("{0} column names specified but {1} columns found.", _Names.Length, colcount));
            }

            if (header)
            {
                if (_Names == null)
                {                       // uses the first row as the names of the columns
                    _Names = new string[colcount];
                    int ci = 0;
                    foreach (LexToken lt in ll)
                    {
                        if (lt.Type == LexTokenTypes.EOF)
                        {
                            break;
                        }
                        _Names[ci++] = lt.Value;
                    }
                }
                ll = GetLine();
            }
            else if (_Names == null)
            {                   // just name the columns 'column1', 'column2', ...
                _Names = new string[colcount];
                for (int ci = 0; ci < _Names.Length; ci++)
                {
                    _Names[ci] = "column" + (ci + 1).ToString();
                }
            }

            _Data  = new object[_Names.Length];         // allocate enough room for data
            _Types = new Type[_Names.Length];
            if (ll != null)                             // we have a datarow
            {
                bFirstRow = true;
                // loop thru determining the types of all data
                int ci = 0;
                foreach (LexToken lt in ll)
                {
                    if (ci >= _Types.Length || lt.Type == LexTokenTypes.EOF)
                    {
                        break;
                    }
                    _Types[ci++] = GetTypeOfString(lt.Value);
                }
                FillData(ll);
            }
            else
            {                   // no first row! assume all the column types are string
                for (int ci = 0; ci < _Types.Length; ci++)
                {
                    _Types[ci] = tstring;
                }
            }

            if (behavior == CommandBehavior.SchemaOnly)
            {
                _sr.Close();
                _sr = null;
            }
        }