Ejemplo n.º 1
0
        /// <summary>
        /// Add a text line to the viewer.
        /// </summary>
        /// <param name="lineno">Line number to add.</param>
        /// <param name="text">Text of the line.</param>
        /// <param name="file">File that the information comes from.</param>
        public void AddLine(string file, long lineno, string text)
        {
            if (this.canceled || this.IsDisposed)
            {
                return;
            }

            if (this.InvokeRequired)
            {
                var action = new Action <LogViewer, string, long, string>((lv, f, l, t) => lv.AddLine(f, l, t));
                this.Invoke(action, this, file, lineno, text);
            }
            else
            {
                if (this.shownText != null)
                {
                    TextFileLine tfl = new TextFileLine(lineno, text);
                    this.shownText.AddItem(tfl);
                }
                else
                {
                    PositionedDryadLogEntry cle = new PositionedDryadLogEntry(file, lineno, text);
                    if (cle.Malformed)
                    {
                        return;
                    }
                    this.shownLogLines.AddItem(cle);
                }
                return;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// User wants to the the location of the message.
        /// </summary>
        /// <param name="sender">Unused.</param>
        /// <param name="e">Row selected.</param>
        private void locationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string position = "";
            var    rows     = this.filteredDataGridView.DataGridView.SelectedRows;

            for (int i = 0; i < rows.Count; i++)
            {
                PositionedDryadLogEntry entry = ((PositionedDryadLogEntry)rows[i].DataBoundItem);
                position += entry.File + ":" + entry.LineNo + Environment.NewLine;
            }
            MessageBox.Show(position, "File containing log entries");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Load a specified file.
        /// </summary>
        /// <param name="file">File to load.</param>
        public void LoadFile(IClusterResidentObject file)
        {
            string filename = file.Name;

            bool   text         = true;
            string basefilename = Path.GetFileName(filename);

            if (basefilename != null && (basefilename.EndsWith(".log") && basefilename.StartsWith("cosmos")))
            {
                text = false;
            }

            long len = file.Size;

            this.Initialize(text, basefilename);
            //ISharedStreamReader sr = new FileSharedStreamReader(filename);
            ISharedStreamReader sr = file.GetStream(false);
            long lineno            = 0;
            long bytes             = 0;

            List <TextFileLine>            toAddText = new List <TextFileLine>();
            List <PositionedDryadLogEntry> toAddLog  = new List <PositionedDryadLogEntry>();

            while (!sr.EndOfStream)
            {
                string line = sr.ReadLine();
                bytes += line.Length;
                if (this.shownText != null)
                {
                    toAddText.Add(new TextFileLine(lineno, line));
                }
                else
                {
                    PositionedDryadLogEntry cle = new PositionedDryadLogEntry(filename, lineno, line);
                    if (cle.Malformed)
                    {
                        Trace.TraceInformation("Malformed log entry: " + cle.OriginalLogLine);
                    }
                    else
                    {
                        toAddLog.Add(cle);
                    }
                }
                if (lineno++ % 100 == 0 && len > 0)
                {
                    this.UpdateProgress((int)(bytes * 100 / len));
                }
            }

            if (this.shownText != null)
            {
                this.shownText.SetItems(toAddText);
            }
            else
            {
                this.shownLogLines.SetItems(toAddLog);
            }
            this.Status("Loaded " + lineno + " lines.", StatusKind.OK);
            this.UpdateProgress(100);
            sr.Close();
            this.filteredDataGridView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCellsExceptHeader);
        }