Ejemplo n.º 1
0
        /// <summary>
        /// Generates the filled SVG for a round robin category.
        /// </summary>
        /// <param name="category">The category to generate it for.</param>
        /// <param name="templateFileName">The filename of the template located in the SVG folder, without the extention.</param>
        public RoundRobinBase(Category category, string templateFileName)
        {
            XElement sheet = XElement.Load($"SVG/{templateFileName}.svg");

            bool hasFirstContest = category.TryGet(1, out ContestSheetData _contest);
            RoundRobinSheetDataDto calculated = default;

            if (hasFirstContest)
            {
                calculated = _contest.ToRoundRobinDto(category);
            }

            foreach (var contest in category.SheetData)
            {
                if (!string.IsNullOrEmpty(contest.CompeditorWhite))
                {
                    var sheetdescendants = sheet.Descendants();
                    var score            = sheet.Descendants().Where(o => (string)o.Attribute("id") == (contest.Contest.ToString() + "W")).First();
                    score.SetValue(contest.ScoreWhite());
                }
                if (!string.IsNullOrEmpty(contest.CompeditorBlue))
                {
                    var score = sheet.Descendants().Where(o => (string)o.Attribute("id") == (contest.Contest.ToString() + "B")).First();
                    score.SetValue(contest.ScoreBlue());
                }
            }

            if (calculated != default)
            {
                for (int i = 0; i < calculated.Competitors.Count(); i++)
                {
                    var competitor = sheet.Descendants().Where(o => (string)o.Attribute("id") == ($"Competitor{i + 1}")).First();
                    competitor.SetValue(calculated.Competitors[i].Name);

                    var wins = sheet.Descendants().Where(o => (string)o.Attribute("id") == ($"WinComp{i + 1}")).First();
                    wins.SetValue(calculated.Competitors[i].Won);

                    var points = sheet.Descendants().Where(o => (string)o.Attribute("id") == ($"PuntComp{i + 1}")).First();
                    points.SetValue(calculated.Competitors[i].Score);

                    if (calculated.Competitors[i].Position != 0)
                    {
                        var position = sheet.Descendants().Where(o => (string)o.Attribute("id") == ($"ResComp{i + 1}")).First();
                        position.SetValue(calculated.Competitors[i].Position);
                    }
                }
            }

            XmlSerializer serializer = new XmlSerializer(typeof(XElement));

            using (StringWriter stringWriter = new StringWriter())
            {
                serializer.Serialize(stringWriter, sheet);
                _Image = stringWriter.ToString();
            }
        }
Ejemplo n.º 2
0
 public static RedisRoundRobinContestSheetDataDto ToRedisDTO(this RoundRobinSheetDataDto contest, ContestType type)
 {
     return(new RedisRoundRobinContestSheetDataDto
     {
         Contest = contest.Contest,
         CompetitorWhite = contest.CompetitorWhite,
         CompetitorBlue = contest.CompetitorBlue,
         IponWhite = contest.IponWhite,
         WazaariWhite = contest.WazaariWhite,
         IponBlue = contest.IponBlue,
         WazaariBlue = contest.WazaariBlue,
         Competitors = contest.Competitors,
         ContestType = type,
     });
 }