Ejemplo n.º 1
0
        public static bool TryParse(string value, out DivisionWithCategory divCat)
        {
            // null strings don't parse
            if (value == null)
            {
                divCat = default(DivisionWithCategory);
                return(false);
            }

            // just division
            if (TypeReaders.DivisionTypeReader.TryParseFriendly(value, out Division div))
            {
                divCat = new DivisionWithCategory(div, null);
                return(true);
            }

            // division and category, colon-separated
            string[] components = value.Split(':');
            if (components.Length != 2)
            {
                divCat = default(DivisionWithCategory);
                return(false);
            }

            if (TypeReaders.DivisionTypeReader.TryParseFriendly(components[0], out div) && ServiceCategoryExtensions.TryParseAliasName(components[1], out ServiceCategory cat))
            {
                divCat = new DivisionWithCategory(div, cat);
                return(true);
            }

            divCat = default(DivisionWithCategory);
            return(false);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            string jsonPath;

            if (args.Length < 1)
            {
                Console.Error.WriteLine("Enter path to JSON file:");
                jsonPath = Console.ReadLine();
            }
            else
            {
                jsonPath = args[0];
            }
            Console.Error.WriteLine($"Got {jsonPath} as JSON path");

            string categoryPath;

            if (args.Length < 2)
            {
                Console.Error.WriteLine("Enter path to category map file:");
                categoryPath = Console.ReadLine();
            }
            else
            {
                categoryPath = args[1];
            }
            Console.Error.WriteLine($"Got {categoryPath} as category mapfile path");

            var input = JsonConvert.DeserializeObject <Output>(File.ReadAllText(jsonPath));
            var teamCategoryDictionary = File.ReadAllLines(categoryPath).Select(l => l.Trim().Split(new[] { ':' }, 2)).Where(l => TeamId.TryParse(l[0], out TeamId _)).ToDictionary(l => TeamId.Parse(l[0]), l => ServiceCategoryExtensions.ParseCanonicalName(l[1]));

            // fix summary data
            foreach (var teamSummary in input.summary.TeamList)
            {
                if (teamSummary.Category == null && teamCategoryDictionary.TryGetValue(teamSummary.TeamId, out ServiceCategory newCategory))
                {
                    teamSummary.Category = newCategory;
                }
            }
            // fix details
            foreach (var knownCategory in teamCategoryDictionary)
            {
                if (input.teams.TryGetValue(knownCategory.Key, out var teamDetails) && teamDetails.Summary.Category == null)
                {
                    teamDetails.Summary.Category = knownCategory.Value;
                }
            }
            Console.Write(JsonConvert.SerializeObject(input));
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Enter path to CSV file:");
            string path = Console.ReadLine();

            Console.WriteLine("Enter timestamp:");
            string timestamp = Console.ReadLine();

            Console.WriteLine("Enter path to all service category map file (or empty string):");
            string servicePath = Console.ReadLine();

            Console.WriteLine("Enter round number:");
            int roundNumber = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter origin URI:");
            string originUri = Console.ReadLine();

            var categories = new Dictionary <TeamId, ServiceCategory>();

            if (servicePath != "")
            {
                categories = File.ReadAllLines(servicePath).Select(x => x.Split(':')).Where(x => TeamId.TryParse(x[0], out TeamId _)).ToDictionary(x => TeamId.Parse(x[0]), x => ServiceCategoryExtensions.ParseCanonicalName(x[1]));
            }

            var lines = File.ReadAllLines(path);

            CompleteScoreboardSummary summary = new CompleteScoreboardSummary();

            summary.TeamList          = new List <ScoreboardSummaryEntry>();
            summary.SnapshotTimestamp = DateTimeOffset.Parse(timestamp);
            summary.OriginUri         = string.IsNullOrEmpty(originUri) ? null : new Uri(originUri);

            Console.WriteLine("Loading score data");

            foreach (string[] data in lines.Skip(1).Select(line => line.Split(',')))
            {
                ScoreboardSummaryEntry entry = new ScoreboardSummaryEntry
                {
                    TeamId     = TeamId.Parse(data[0]),
                    Division   = Enum.Parse <Division>(data[1].Replace(" ", ""), true),
                    Category   = string.IsNullOrEmpty(data[2]) ? categories.TryGetValue(TeamId.Parse(data[0]), out ServiceCategory c) ? (ServiceCategory?)c : null : ServiceCategoryExtensions.ParseAliasName(data[2].Trim()),
                    Location   = data[3],
                    Tier       = Enum.TryParse <Tier>(data[4], true, out Tier t) ? t : (Tier?)null,
                    ImageCount = int.Parse(data[5]),
                    PlayTime   = ParseTimeSpan(data[6]),
                    TotalScore = double.Parse(data[7]),
                    Warnings   = (data[8].Contains("M") ? ScoreWarnings.MultiImage : 0) | (data[8].Contains("T") ? ScoreWarnings.TimeOver : 0)
                };
                summary.TeamList.Add(entry);
            }

            Console.WriteLine("Generating output data");

            var o = new Output
            {
                round   = roundNumber,
                summary = summary,
                teams   = summary.TeamList.Select(x => new ScoreboardDetails
                {
                    Images = new List <ScoreboardImageDetails>
                    {
                        new ScoreboardImageDetails
                        {
                            ImageName                = "All Points",
                            Penalties                = 0,
                            PlayTime                 = x.PlayTime,
                            PointsPossible           = x.ImageCount * 100,
                            Score                    = x.TotalScore,
                            VulnerabilitiesFound     = 0,
                            VulnerabilitiesRemaining = 0,
                            Warnings                 = x.Warnings
                        }
                    },
                    ImageScoresOverTime = null,
                    OriginUri           = null,
                    ScoreTime           = x.PlayTime,
                    SnapshotTimestamp   = DateTimeOffset.Parse(timestamp),
                    Summary             = x
                }).ToDictionary(x => x.TeamId, x => x)
            };

            File.WriteAllText("scores.json", JsonConvert.SerializeObject(o));
            Console.WriteLine("Done");

            Console.ReadKey();
        }