Ejemplo n.º 1
0
        private void worker_end(object sender, RunWorkerCompletedEventArgs e)
        {
            errlog = parser.Result;
            if (errlog != null)
            {
                listView.SetObjects(errlog.Lines);
            }
            toolProgress.Value   = 100;
            toolProgress.Visible = false;
            btnCancel.Visible    = false;
            menuStrip.Enabled    = true;

            GC.Collect();
        }
Ejemplo n.º 2
0
        public void Parse(object sender, DoWorkEventArgs e)
        {
            ReportProgress(0);
            IList <ILine> lines = new List <ILine>();

            Result = new ErrlogCpp(lines);
            if (!File.Exists(FileName))
            {
                return;
            }
            CultureInfo ptPT = new CultureInfo("pt-PT");

            DetectTextEncoding(FileName, out string t);
            IEnumerable <string> file = new List <string>(Regex.Split(t, "\r\n"));
            CppLogLine           line = null;
            StringBuilder        text = new StringBuilder();
            int count    = file.Count();
            int progress = 0;
            int percent  = 0;

            foreach (var item in file)
            {
                Match match = LogHeader.Match(item);
                if (match.Success)
                {
                    if (text.Length != 0 && line != null)
                    {
                        line.Text = text.ToString().Trim();
                    }

                    if (line != null)
                    {
                        lines.Add(line);
                    }

                    string data    = match.Groups[2].Value;
                    string hora    = match.Groups[5].Value;
                    string modulo  = match.Groups[8].Value;
                    string db      = match.Groups[11].Value;
                    string client  = match.Groups[15].Value;
                    string netuser = match.Groups[17].Value;
                    string login   = match.Groups[20].Value;
                    string level   = match.Groups[23].Value;
                    string pid     = match.Groups[26].Value;
                    string funcao  = match.Groups[29].Value;

                    DateTime.TryParseExact(data, "dd/MM/yyyy", ptPT, DateTimeStyles.None, out DateTime dataParsed);
                    if (TimeSpan.TryParse(hora, out TimeSpan horaParsed))
                    {
                        dataParsed = dataParsed.Add(horaParsed);
                    }
                    int.TryParse(level, out int levelParsed);
                    int.TryParse(pid, out int pidParsed);

                    line = new CppLogLine(modulo, client, netuser, login, levelParsed, funcao, db, dataParsed, pidParsed);
                    text = new StringBuilder();
                }
                else
                {
                    text.Append(item).Append(Environment.NewLine);
                }
                progress++;
                int tmp = progress * 100 / count;
                if (tmp != percent)
                {
                    ReportProgress(tmp);
                }

                percent = tmp;

                if (CancellationPending)
                {
                    break;
                }
            }

            if (line != null)
            {
                line.Text = text.ToString().Trim();
                lines.Add(line);
            }
        }