예제 #1
0
        public override void read_to_end()
        {
            var entries_now = reader_.read_available_lines();

            if (entries_now == null)
            {
                return;
            }
            lock (this) {
                foreach (var entry in entries_now)
                {
                    string_.add_preparsed_line(entry.ToString());
                }
                entries_.AddRange(entries_now);

                if (column_names.Count < 1 && entries_now.Count > 0)
                {
                    column_names = entries_now[0].names;
                }
            }
        }
예제 #2
0
        public override void read_to_end()
        {
            ulong old_len = reader_.full_len;

            reader_.compute_full_length();
            ulong new_len = reader_.full_len;

            // when reader's position is zero -> it's either the first time, or file was re-rewritten
            if (old_len > new_len || reader_.pos == 0)
            {
                // file got re-written
                force_reload();
            }

            bool fully_read = old_len == new_len && reader_.is_up_to_date();

            if (!reader_.has_more_cached_text())
            {
                lock (this) {
                    up_to_date_ = fully_read;
                    if (up_to_date_)
                    {
                        // at this point, we're sure we read everything
                        was_last_line_incomplete_ = DateTime.MinValue;
                    }
                }
                return;
            }

            lock (this)
                up_to_date_ = false;

            string text = reader_.read_next_text();
            int    added_line_count = 0;
            bool   was_last_line_incomplete = false, is_last_line_incomplete = false;
            int    old_line_count = string_.line_count;

            string_.add_lines(text, ref added_line_count, ref was_last_line_incomplete, ref is_last_line_incomplete);

            if (added_line_count < 1)
            {
                return;
            }

            bool needs_reparse_last_line;

            lock (this)
                needs_reparse_last_line = lines_.Count > 0 && was_last_line_incomplete;
            int         start_idx         = old_line_count - (was_last_line_incomplete ? 1 : 0);
            int         end_idx           = string_.line_count;
            List <line> now               = new List <line>(end_idx - start_idx);
            int         merged_line_count = 0;

            for (int i = start_idx; i < end_idx; ++i)
            {
                var  cur_line          = new sub_string(string_, i - merged_line_count);
                bool is_from_prev_line = false;
                if (if_line_starts_with_tab_assume_from_prev_line)
                {
                    if (cur_line.msg.StartsWith("\t"))
                    {
                        is_from_prev_line = true;
                    }
                }
                if (i == 0)
                {
                    is_from_prev_line = false; // there's no previous line
                }
                if (!is_from_prev_line)
                {
                    now.Add(parse_line(cur_line));
                }
                else
                {
                    string_.merge_line_into_previous_line(i - merged_line_count);
                    ++merged_line_count;
                }
            }

            lock (this) {
                if (needs_reparse_last_line)
                {
                    // we re-parse the last line (which was previously incomplete)
                    logger.Debug("[line] reparsed line " + (old_line_count - 1));
                    lines_.RemoveAt(lines_.Count - 1);
                }

                int old_count = lines_.Count;
                lines_.AddRange(now);
                // in order to adjust time, we have to have at least one syntax in which we find it
                bool can_find_time = syntaxes_.FirstOrDefault(x => x.can_find(info_type.time)) != null;
                if (can_find_time)
                {
                    for (int idx = old_count; idx < lines_.Count; ++idx)
                    {
                        adjust_line_time(idx);
                    }
                }
                was_last_line_incomplete_ = was_last_line_incomplete ? DateTime.Now : DateTime.MinValue;
            }
            //Debug.Assert( lines_.Count == string_.line_count);

            update_log_lines_capacity();
        }