Beispiel #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); }
        }
Beispiel #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);
        }
Beispiel #3
0
        /// <summary>
        /// Compute basic statistics on flight
        /// </summary>
        /// <param name="baseFlightReports">list of all flights</param>
        /// <returns>IGeneratedReport object containing basic statistics</returns>
        private IGeneratedReport ComputeFlightData(IList <Flight> baseFlightReports)
        {
            GeneratedReport generatedReport = new GeneratedReport();

            //count
            generatedReport.FlightCount = baseFlightReports.Count();

            //Max Distance
            generatedReport.MaximalDistance = baseFlightReports.Max(m => m.Distance);

            //Min Distance
            generatedReport.MinimalDistance = baseFlightReports.Min(m => m.Distance);

            //Total Travel Distance
            generatedReport.TotalTraveledDistance = baseFlightReports.Sum(d => d.Distance);

            //Total Fuel needed
            generatedReport.TotalFuelNeeded = baseFlightReports.Sum(f => f.FuelNeeded);

            //Avirage flight distance
            generatedReport.AverageDistance = generatedReport.TotalTraveledDistance / generatedReport.FlightCount;
            return(generatedReport);
        }
Beispiel #4
0
        private void btnreport_Click(object sender, EventArgs e)
        {
            GeneratedReport form = new GeneratedReport(current, revenue);

            form.Show();
        }