Example #1
0
        public NodeColor(Subcase subcase)
        {
            // Source https://www.w3schools.com/colors/colors_trends.asp
            var colors = new Dictionary <string, string>
            {
                { "1", "#9B2335" }, // Chili Pepper
                { "2", "#EFC050" }, // Mimosa
                { "3", "#5B5EA6" }, // Blue Izis
                { "4", "#DFCFBE" }, // Sand Dollar
            };

            Background = colors[subcase.Level];

            var borders = new Dictionary <string, string>
            {
                { "Update from Support", "#F7CAC9" }, // Rose Quartz
                { "New", "#B565A7" } // Radiand Orchid
            };

            string border = null;

            if (DateTime.UtcNow - subcase.Created > TimeSpan.FromDays(30))
            {
                Border     = "#BC243C"; // True Red
                Importance = "Long Running (30+ days)";
            }
            else if (borders.TryGetValue(subcase.Status, out border))
            {
                Border     = border;
                Importance = subcase.Status;
            }
        }
        public async Task <IEnumerable <Subcase> > GetSubcasesAsync(string product)
        {
            var url  = GetReportLink(product);
            var page = await GetReportAsync(url);

            var htmlDoc = new HtmlDocument();

            htmlDoc.LoadHtml(page);

            var htmlBody  = htmlDoc.DocumentNode;
            var tableNode = htmlBody.SelectSingleNode("//table[@class='a209']");

            if (tableNode == null)
            {
                var message = "Cannot parse HTML report, incorrect format.";
                _logger.LogError(message);
                throw new ApplicationException(message);
            }

            var rowNodes = tableNode.SelectNodes("tr");

            _logger.LogDebug("Rows: {Count}", rowNodes.Count);

            var subcases = new List <Subcase>();
            int i        = 0;

            foreach (var node in rowNodes)
            {
                i++;
                if (i <= 2)
                {
                    continue;
                }
                var cells   = node.SelectNodes("td/div");
                var subcase = new Subcase()
                {
                    Id       = cells[1].InnerText,
                    Title    = cells[2].InnerText,
                    Level    = cells[3].InnerText.Substring("Level ".Length),
                    Owner    = cells[4].InnerText,
                    Status   = cells[8].InnerText,
                    Customer = cells[9].InnerText,
                    Loaded   = DateTime.UtcNow
                };

                subcases.Add(subcase);
            }

            return(subcases);
        }