Exemple #1
0
        public static ReportRegistry Load(string file)
        {
            if (!File.Exists(file))
            {
                return(null);
            }
            var content = File.ReadAllBytes(file);
            var reader  = new Utf8JsonReader(content,
                                             new JsonReaderOptions
            {
                AllowTrailingCommas = true,
                CommentHandling     = JsonCommentHandling.Skip
            });

            if (!JsonDocument.TryParseValue(ref reader, out JsonDocument document))
            {
                return(null);
            }
            try
            {
                var registry = new ReportRegistry();
                registry.Protos.AddRange(document.RootElement
                                         .GetProperty("proto").EnumerateArray()
                                         .Select(x => ProtoReport.Load(ref x)));
                registry.Generateds.AddRange(document.RootElement
                                             .GetProperty("generated").EnumerateArray()
                                             .Select(x => GeneratedReport.Load(ref x)));
                return(registry);
            }
            catch { return(null); }
        }
Exemple #2
0
        public static (ProtoReport, GeneratedReport) ReadReport(string file, string source)
        {
            _ = file ?? throw new ArgumentNullException(nameof(file));
            var info = new FileInfo(file);

            if (!info.Exists)
            {
                return(null, null);
            }
            var regex = new Regex(@"(?<file>.+): ((?<dep>[^\\$]+)[\\\s]*)+");

            using var reader = info.OpenText();
            var match = regex.Match(reader.ReadToEnd());

            if (!match.Success)
            {
                return(null, null);
            }
            var report = new ProtoReport
            {
                File       = source,
                LastChange = info.LastWriteTimeUtc,
            };

            report.Dependencies.AddRange(match.Groups["dep"].Captures.Select(x => x.Value));
            var gen = new GeneratedReport
            {
                File      = match.Groups["file"].Value,
                Source    = source,
                LastBuild = new FileInfo(match.Groups["file"].Value).LastWriteTimeUtc,
                Srpc      = false,
            };

            return(report, gen);
        }
Exemple #3
0
        public static ProtoReport Load(ref JsonElement json)
        {
            var report = new ProtoReport
            {
                File       = json.GetProperty("file").GetString(),
                LastChange = json.GetProperty("last-change").GetDateTime(),
            };

            report.Dependencies.AddRange(
                json.GetProperty("deps").EnumerateArray().Select(x => x.GetString()));
            return(report);
        }