Beispiel #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);
        }
Beispiel #2
0
        public LogReportPack GetReportPack()
        {
            LogReportPack pack = new LogReportPack();

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

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

            LogReportPack pack = CreateFromLines(lines);

            return(pack);
        }
Beispiel #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());
        }
Beispiel #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);
        }
Beispiel #6
0
 public void SaveToFile(LogReportPack pack, string path)
 {
     string[] lines = GetAsLines(pack);
     File.WriteAllLines(path, lines);
 }