Exemplo n.º 1
0
        public LogReportPack CreateFromLines(string[] lines)
        {
            LogReportPack pack          = new LogReportPack();
            LogReport     parsedReport  = null;
            LogReport     currentReport = null;

            LogReportItem item = null;

            foreach (string line in lines)
            {
                if (LogReport.TryCreateFromHeader(line, out parsedReport))
                {
                    currentReport = parsedReport;
                    pack.Reports.Add(currentReport);
                    continue;
                }

                if (LogReportItem.TryCreateFromString(line, out item))
                {
                    if (null != currentReport)
                    {
                        currentReport.Items.Add(item);
                    }
                }
            }

            return(pack);
        }
Exemplo n.º 2
0
        public LogReportPack GetReportPack()
        {
            LogReportPack pack = new LogReportPack();

            pack.Reports = Reports;
            return(pack);
        }
Exemplo n.º 3
0
        public LogReportPack CreateFromFile(string path)
        {
            if (!File.Exists(path))
            {
                return(null);
            }

            string[] lines = File.ReadAllLines(path);

            LogReportPack pack = CreateFromLines(lines);

            return(pack);
        }
Exemplo n.º 4
0
        public string[] GetAsLines(LogReportPack reportPack)
        {
            List <string> lines = new List <string>();

            foreach (LogReport report in reportPack.Reports)
            {
                lines.Add(report.GetHeader());
                foreach (LogReportItem item in report.Items)
                {
                    lines.Add(item.GetAsLine());
                }
            }

            return(lines.ToArray());
        }
Exemplo n.º 5
0
        public static bool TryCreateFromHeader(string header, out LogReportPack report)
        {
            report = null;
            Match match     = Regex.Match(header, PATTERN);
            Group nameGroup = match.Groups["name"];

            if (!(nameGroup.Success))
            {
                return(false);
            }

            string nameStr = nameGroup.Value;

            report = new LogReportPack {
                Name = nameStr
            };

            return(true);
        }
Exemplo n.º 6
0
 public void SaveToFile(LogReportPack pack, string path)
 {
     string[] lines = GetAsLines(pack);
     File.WriteAllLines(path, lines);
 }