示例#1
0
 /// <summary>
 /// Constructor for the xml file, that is stored in the .xls file
 /// </summary>
 /// <param name="element">The root XElement of the xml</param>
 /// <param name="workbook">The current workbook</param>
 public Violation(XElement element, Workbook workbook)
 {
     load = true;
     this.workbook = workbook;
     CausingElement = element.Attribute(XName.Get("causingelement")).Value;
     Description = element.Attribute(XName.Get("description")).Value;
     FirstOccurrence = DateTime.Parse(element.Attribute(XName.Get("firstoccurrence")).Value);
     ViolationState = (ViolationType)Enum.Parse(typeof(ViolationType), element.Attribute(XName.Get("violationstate")).Value);
     SolvedTime = DateTime.Parse(element.Attribute(XName.Get("solvedtime")).Value);
     isRead = Convert.ToBoolean(element.Attribute(XName.Get("isread")).Value);
     isSelected = Convert.ToBoolean(element.Attribute(XName.Get("isselected")).Value);
     severity = Decimal.Parse(element.Attribute(XName.Get("severity")).Value);
     Rule = new Rule(element.Element(XName.Get("rule")));
     FindCellLocation(element.Attribute(XName.Get("cell")).Value);
     load = false;
     IsCellSelected = false;
 }
示例#2
0
        /// <summary>
        /// Constructor of a violation
        /// </summary>
        /// <param name="root">the root XML element</param>
        /// <param name="workbook">the current workbook</param>
        /// <param name="scanTime">the time when this violation has been occurred</param>
        /// <param name="rule">the rule of this violation</param>
        public Violation(XElement root, Workbook workbook, DateTime scanTime, Rule rule)
        {
            CausingElement = root.Attribute(XName.Get("causingelement")).Value;
            Description = root.Attribute(XName.Get("description")).Value;
            Severity = decimal.Parse(root.Attribute(XName.Get("severity")).Value.Replace(".0", String.Empty));

            this.workbook = workbook;

            firstOccurrence = scanTime;
            this.rule = rule;
            foundAgain = true;
            FindCellLocation(root.Attribute(XName.Get("location")).Value);
            //Before there was the following Code written here:
            //this.violationState = ViolationType.OPEN;
            // It got commented out because like this any finding marked with later got overriten
            // with violationtype open.
        }
示例#3
0
        /// <summary>
        /// Constructor of a violation
        /// </summary>
        /// <param name="root">the root XML element</param>
        /// <param name="workbook">the current workbook</param>
        /// <param name="scanTime">the time when this violation has been occurred</param>
        /// <param name="rule">the rule of this violation</param>
        public Violation(XElement root, Workbook workbook, DateTime scanTime, Rule rule)
        {
            //this.Id = Convert.ToInt32(root.Attribute(XName.Get("number")).Value);
            this.CausingElement = root.Attribute(XName.Get("causingelement")).Value;
            this.Description = root.Attribute(XName.Get("description")).Value;

            var location = root.Attribute(XName.Get("location")).Value;
            if (!string.IsNullOrWhiteSpace(location))
            {
                // Split the location string into its components
                // Input might be: [example.xlsx]Sheet1!B12
                location = location.Substring(location.IndexOf(']') + 1);
                this.Cell = new CellLocation(workbook, location);
            }

            this.firstOccurrence = scanTime;
            this.rule = rule;
            this.foundAgain = true;
            this.violationState = ViolationType.NEW;
            this.isVisible = true;
        }
示例#4
0
 /// <summary>
 /// Constructor for the xml file from SIF
 /// </summary>
 /// <param name="root">The root XElement</param>
 /// <param name="workbook">The current workbook</param>
 /// <param name="scanTime">The time of the scan</param>
 /// <param name="rule">The rule of this violation</param>
 public SingleViolation(XElement root, Workbook workbook, DateTime scanTime, Rule rule, bool groupedViolation)
     : base(root, workbook, scanTime, rule)
 {
     this.Severity = decimal.Parse(root.Attribute(XName.Get("severity")).Value.Replace(".0", ""));
     this.groupedViolation = groupedViolation;
 }
示例#5
0
        /// <summary>
        /// This method loads the violations of the xml report
        /// </summary>
        private void LoadViolations(XElement rootElement)
        {
            DateTime scanTime = DateTime.Now;
            XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
            var findings = rootElement.Element(XName.Get("findings"));
            var violations = new List<Violation>();
            foreach (var ruleXML in findings.Elements(XName.Get("testedRule")))
            {
                Rule rule = new Rule(ruleXML.Element(XName.Get("testedPolicy")));

                // Parse violations
                var xmlVio = ruleXML.Elements(XName.Get("violations"));
                foreach (XElement vio in xmlVio)
                {
                    var x = vio.Attribute(ns + "type");
                    if (x.Value.Equals("singleviolation"))
                    {
                        violations.Add(new SingleViolation(vio, workbook, scanTime, rule, false));
                    }
                    else if (x.Value.Equals("violationgroup"))
                    {
                        violations.Add(new GroupViolation(vio, workbook, scanTime, rule));
                    }
                }

            }

            // Add only new violations
            foreach (Violation violation in violations)
            {
                if (this.Violations.Contains(violation))
                {
                    this.Violations.ElementAt(this.Violations.IndexOf(violation)).FoundAgain = true;
                }
                else if (this.FalsePositives.Contains(violation) || this.SolvedViolations.Contains(violation))
                {
                    // nothing to do here
                }
                else if (this.LaterViolations.Contains(violation))
                {
                    this.LaterViolations.ElementAt(this.LaterViolations.IndexOf(violation)).FoundAgain = true;
                }
                else
                {
                    this.Violations.Add(violation);
                }
            }

            // mark all solved violations
            for (int i = this.Violations.Count - 1; i >= 0; i--)
            {
                if (this.Violations.ElementAt(i).FoundAgain == true)
                {
                    this.Violations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.Violations.ElementAt(i).SolvedTime = scanTime;
                    this.Violations.ElementAt(i).ViolationState = Violation.ViolationType.SOLVED;
                }
            }
            for (int i = this.LaterViolations.Count - 1; i >= 0; i--)
            {
                if (this.LaterViolations.ElementAt(i).FoundAgain == true)
                {
                    this.LaterViolations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.LaterViolations.ElementAt(i).SolvedTime = scanTime;
                    this.LaterViolations.ElementAt(i).ViolationState = Violation.ViolationType.SOLVED;
                }
            }
            // refresh UI
            foreach (var violation in this.Violations)
            {
                violation.CreateControls();
            }
        }
示例#6
0
        /// <summary>
        /// This method loads the violations of the xml report
        /// </summary>
        private void LoadViolations(XElement rootElement)
        {
            DateTime   scanTime   = DateTime.Now;
            XNamespace ns         = "http://www.w3.org/2001/XMLSchema-instance";
            var        findings   = rootElement.Element(XName.Get("findings"));
            var        violations = new List <Violation>();

            foreach (var ruleXML in findings.Elements(XName.Get("testedRule")))
            {
                Rule rule = new Rule(ruleXML.Element(XName.Get("testedPolicy")));

                // Parse violations
                var xmlVio = ruleXML.Elements(XName.Get("violations"));
                foreach (XElement vio in xmlVio)
                {
                    var x = vio.Attribute(ns + "type");
                    if (x.Value.Equals("singleviolation"))
                    {
                        violations.Add(new Violation(vio, workbook, scanTime, rule));
                    }
                    else if (x.Value.Equals("violationgroup"))
                    {
                        (from p in vio.Elements(XName.Get("singleviolation"))
                         select new Violation(p, workbook, scanTime, rule)).ToList().ForEach(p => violations.Add(p));
                    }
                }
            }

            // Add only new violations
            foreach (Violation violation in violations)
            {
                if (this.Violations.Contains(violation))
                {
                    this.Violations.ElementAt(this.Violations.IndexOf(violation)).FoundAgain = true;
                }

                else if ((from vi in this.IgnoredViolations
                          where (vi.Cell.Letter.Equals(violation.Cell.Letter) && vi.Cell.Number.Equals(violation.Cell.Number))
                          select vi).Count() > 0)
                {
                    // nothing to do here
                }
                else if (this.LaterViolations.Contains(violation))
                {
                    this.LaterViolations.ElementAt(this.LaterViolations.IndexOf(violation)).FoundAgain = true;
                }
                else
                {
                    violation.PersistCellLocation();
                    this.Violations.Add(violation);
                }
            }

            // mark all solved violations
            for (int i = this.Violations.Count - 1; i >= 0; i--)
            {
                if (this.Violations.ElementAt(i).FoundAgain == true)
                {
                    this.Violations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.Violations.ElementAt(i).SolvedTime     = scanTime;
                    this.Violations.ElementAt(i).ViolationState = ViolationType.SOLVED;
                }
            }
            for (int i = this.LaterViolations.Count - 1; i >= 0; i--)
            {
                if (this.LaterViolations.ElementAt(i).FoundAgain == true)
                {
                    this.LaterViolations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.LaterViolations.ElementAt(i).SolvedTime     = scanTime;
                    this.LaterViolations.ElementAt(i).ViolationState = ViolationType.SOLVED;
                }
            }
        }
示例#7
0
 /// <summary>
 /// Constructor for the xml file from SIF
 /// </summary>
 /// <param name="root">The root XElement</param>
 /// <param name="workbook">The current workbook</param>
 /// <param name="scanTime">The time of the scan</param>
 /// <param name="rule">The rule of this violation</param>
 public GroupViolation(XElement root, Workbook workbook, DateTime scanTime, Rule rule)
     : base(root, workbook, scanTime, rule)
 {
     (from p in root.Elements(XName.Get("singleviolation"))
      select new SingleViolation(p, workbook, scanTime, rule, true)).ToList().ForEach(p => this.Violations.Add(p));
 }
示例#8
0
        /// <summary>
        /// This method loads the violations of the xml report
        /// </summary>
        private void LoadViolations(XElement rootElement)
        {
            DateTime scanTime = DateTime.Now;
            XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
            var findings = rootElement.Element(XName.Get("findings"));
            var violations = new List<Violation>();
            foreach (var ruleXML in findings.Elements(XName.Get("testedRule")))
            {
                Rule rule = new Rule(ruleXML.Element(XName.Get("testedPolicy")));

                // Parse violations
                var xmlVio = ruleXML.Elements(XName.Get("violations"));
                foreach (XElement vio in xmlVio)
                {
                    var x = vio.Attribute(ns + "type");
                    if (x.Value.Equals("singleviolation"))
                    {
                        violations.Add(new Violation(vio, workbook, scanTime, rule));
                    }
                    else if (x.Value.Equals("violationgroup"))
                    {
                        (from p in vio.Elements(XName.Get("singleviolation"))
                         select new Violation(p, workbook, scanTime, rule)).ToList().ForEach(p => violations.Add(p));
                    }
                }

            }

            // Add only new violations
            foreach (Violation violation in violations)
            {
                if (this.Violations.Contains(violation))
                {
                    this.Violations.ElementAt(this.Violations.IndexOf(violation)).FoundAgain = true;
                }

                else if ((from vi in this.IgnoredViolations 
                          where (vi.Cell.Letter.Equals(violation.Cell.Letter) && vi.Cell.Number.Equals(violation.Cell.Number)) 
                          select vi).Count() > 0)
                {
                    // nothing to do here
                }
                else if (this.LaterViolations.Contains(violation))
                {
                    this.LaterViolations.ElementAt(this.LaterViolations.IndexOf(violation)).FoundAgain = true;
                }
                else
                {
                    violation.PersistCellLocation();
                    this.Violations.Add(violation);
                }
            }

            // mark all solved violations
            for (int i = this.Violations.Count - 1; i >= 0; i--)
            {
                if (this.Violations.ElementAt(i).FoundAgain == true)
                {
                    this.Violations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.Violations.ElementAt(i).SolvedTime = scanTime;
                    this.Violations.ElementAt(i).ViolationState = ViolationType.SOLVED;
                }
            }
            for (int i = this.LaterViolations.Count - 1; i >= 0; i--)
            {
                if (this.LaterViolations.ElementAt(i).FoundAgain == true)
                {
                    this.LaterViolations.ElementAt(i).FoundAgain = false;
                }
                else
                {
                    this.LaterViolations.ElementAt(i).SolvedTime = scanTime;
                    this.LaterViolations.ElementAt(i).ViolationState = ViolationType.SOLVED;
                }
            }
        }
示例#9
0
        /// <summary>
        /// Constructor of a violation
        /// </summary>
        /// <param name="root">the root XML element</param>
        /// <param name="workbook">the current workbook</param>
        /// <param name="scanTime">the time when this violation has been occurred</param>
        /// <param name="rule">the rule of this violation</param>
        public Violation(XElement root, Workbook workbook, DateTime scanTime, Rule rule)
        {
            //this.Id = Convert.ToInt32(root.Attribute(XName.Get("number")).Value);
            this.CausingElement = root.Attribute(XName.Get("causingelement")).Value;
            this.Description = root.Attribute(XName.Get("description")).Value;
            this.Severity = decimal.Parse(root.Attribute(XName.Get("severity")).Value.Replace(".0", ""));

            this.workbook = workbook;

            this.firstOccurrence = scanTime;
            this.rule = rule;
            this.foundAgain = true;
            FindCellLocation(root.Attribute(XName.Get("location")).Value);
            this.violationState = ViolationType.OPEN;
        }
示例#10
0
        /// <summary>
        /// This method loads the violations of the xml report
        /// </summary>
        private void LoadViolations(XElement rootElement)
        {
            try
            {
                DateTime scanTime = DateTime.Now;
                XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
                var findings = rootElement.Element(XName.Get("findings"));
                var violations = new List<Violation>();
                foreach (var ruleXml in findings.Elements(XName.Get("testedRule")))
                {
                    Rule rule = new Rule(ruleXml.Element(XName.Get("testedPolicy")));

                    // Parse violations
                    var xmlVio = ruleXml.Elements(XName.Get("violations"));
                    foreach (XElement vio in xmlVio)
                    {
                        var x = vio.Attribute(ns + "type");
                        if (x.Value.Equals("singleviolation"))
                        {
                            violations.Add(new Violation(vio, _workbook, scanTime, rule));
                        }
                        else if (x.Value.Equals("violationgroup"))
                        {
                            (from p in vio.Elements(XName.Get("singleviolation"))
                                select new Violation(p, _workbook, scanTime, rule)).ToList()
                                .ForEach(p => violations.Add(p));
                        }
                    }
                }
                // Add only new violations
                AddNewViolations(violations);
                // mark all solved violations from the Open Category
                MarkSolvedViolations(scanTime, Violations);
                // mark all solved violations from the Later Category
                MarkSolvedViolations(scanTime, LaterViolations);
                // mark all solved violations
                tries = 0;
            }
            catch (Exception ex)
            {
                if (tries <= 3)
                {
                    tries++;
                    LoadViolations(rootElement);
                }
                else
                {
                    ScanHelper.ScanUnsuccessful();
                    tries = 0;
                }
            }
        }