Ejemplo n.º 1
0
        string CreateCheckSummary()
        {
            StringBuilder layout = new StringBuilder();

            layout.Append("<div id=\"overview-checks\" class=\"container\" style=\"padding-bottom: 30px;\">" +
                          "<h2>" + OverviewLocalization.CheckSummaryTitle + "</h2>" +
                          "<p>" + OverviewLocalization.CheckSummaryDescription + "</p>");

            // Parse all submissions into check related categories
            Dictionary <CheckFactory.CheckType, List <Submissions.Submission> > ChecksReference = new Dictionary <CheckFactory.CheckType, List <Submissions.Submission> >();


            foreach (KeyValuePair <Guid, Submissions.Submission> s in _submissions)
            {
                // Itterate over a submissions checks
                foreach (ICheck c in s.Value.Checks)
                {
                    // Only process check if its tripped
                    if (!c.Flagged())
                    {
                        continue;
                    }

                    // Make sure our list is there
                    if (!ChecksReference.ContainsKey(c.GetType()))
                    {
                        ChecksReference.Add(c.GetType(), new List <Submissions.Submission>());
                    }

                    // Add submission to reference to that check
                    if (!ChecksReference[c.GetType()].Contains(s.Value))
                    {
                        ChecksReference[c.GetType()].Add(s.Value);
                    }
                }
            }

            layout.Append("<p>");


            StringBuilder checkBlocks = new StringBuilder();

            foreach (KeyValuePair <CheckFactory.CheckType, List <Submissions.Submission> > c in ChecksReference)
            {
                ICheck checkInstance = c.Value[0].GetCheck(c.Key);
                if (checkInstance != null)
                {
                    // Create Menu Item
                    layout.Append("<a class=\"btn btn" + Content.GetColorCodeByWeight(checkInstance.GetWeight()) + " m-2\" data-toggle=\"collapse\" href=\"#overview-" + checkInstance.GetID() + "\" role=\"button\" aria-expanded=\"false\" data-parent=\"#overview-checks\">" + checkInstance.GetName() + " <span class=\"badge badge-light\">" + c.Value.Count + "</span></a>");

                    // Create Submission Block
                    checkBlocks.Append(
                        "<div class=\"collapse\" id=\"overview-" + checkInstance.GetID() + "\">" +
                        "<div class=\"card\">" +
                        "<h3 class=\"card-header\">" + checkInstance.GetName() + "</h3>" +
                        "<div class=\"card-body\">" +
                        "<p class=\"card-text text-muted\"><em>" + checkInstance.GetDescription() + " [<a href=\"" + checkInstance.GetKBLink() + "\" title=\"Knowledge Base Article\" target=\"_blank\">More</a>]</em></p>");


                    foreach (Submissions.Submission s in c.Value)
                    {
                        // Left Side Origin
                        // -- Robin
                        // WAS:

                        /*
                         * checkBlocks.Append(
                         * "<div class=\"card-group\" style=\"padding-bottom: 15px;\">" +
                         *  "<div class=\"card\" style=\"background-color:rgba(0,0,0,.01);\">" +
                         *      "<div class=\"card-body\">" +
                         *          "<h5 class=\"card-title\"><a href=\"#" + s.GUID.ToString() + "\">" + s.FileNameWithExtension + "</a></h5>" +
                         *          "<h6 class=\"card-subtitle mb-2 text-muted\">" + s.RelativePathNoFile + "</h6>" +
                         *          "<p class=\"card-text\"><small class=\"text-muted\">" + s.GetCheck(c.Key).GetLocalReference() + "</small></p>" +
                         *      "</div>" +
                         *  "</div>");
                         */

                        checkBlocks.Append(
                            "<div class=\"card-group\" style=\"padding-bottom: 15px;\">" +
                            "<div class=\"card\" style=\"background-color:rgba(0,0,0,.01);\">" +
                            "<div class=\"card-body\">" +
                            "<h5 class=\"card-title\"><a href=\"#" + s.GUID.ToString() + "\">" + s.FileNameWithExtension + "</a></h5>" +
                            "<h6 class=\"card-subtitle mb-2 text-muted\">" + s.ContainerPath + "</h6>" +
                            "<p class=\"card-text\"><small class=\"text-muted\">" + s.GetCheck(c.Key).GetLocalReference() + "</small></p>" +
                            "</div>" +
                            "</div>");

                        checkBlocks.Append("<div class=\"card text-right\"><div class=\"card-body\">");

                        // Right Side Matches
                        foreach (KeyValuePair <Submissions.Submission, FlagItem> entry in s.GetCheck(c.Key).GetFlag().Similar)
                        {
                            // -- Robin
                            // WAS:

                            /*
                             * checkBlocks.Append(
                             *  "<h5 class=\"card-title\"><a href=\"#" + entry.Key.GUID.ToString() + "\">" + entry.Key.FileNameWithExtension + "</a></h5>" +
                             *  "<h6 class=\"card-subtitle mb-2 text-muted\">" + entry.Key.RelativePathNoFile + "</h6>");
                             */

                            checkBlocks.Append(
                                "<h5 class=\"card-title\"><a href=\"#" + entry.Key.GUID.ToString() + "\">" + entry.Key.FileNameWithExtension + "</a></h5>" +
                                "<h6 class=\"card-subtitle mb-2 text-muted\">" + entry.Key.ContainerPath + "</h6>");

                            checkBlocks.Append("<p class=\"card-text\"><small class=\"text-muted\">");
                            if (entry.Value.Reference != "" && entry.Value.Reference != string.Empty)
                            {
                                checkBlocks.Append(entry.Value.Reference);
                            }
                            checkBlocks.Append(" [" + Compare.ToPercentage((float)entry.Value.Similarity) + "]");
                            checkBlocks.Append("</small></p>");
                        }
                        checkBlocks.Append("</div></div></div>");
                    }


                    checkBlocks.Append("</div></div></div>");
                }
            }
            if (ChecksReference.Count == 0)
            {
                layout.Append("<div class=\"alert alert-success\">" + OverviewLocalization.NoChecksNotice + "</div>");
            }

            layout.Append("</p><div class=\"accordion-group\">");
            layout.Append(checkBlocks.ToString());
            layout.Append("</div></div>");


            return(layout.ToString());
        }