public void TestGetContent()
		{
			const string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find the\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"the\" context=\"Paragraph\" count=\"3\" />" +
//					  "<result match=\"the\" context=\"Paragraph\" count=\"1\" />" +
//					  "<result match=\"The\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>" +
					  "</rule>" +
					  "<rule name=\"Find that will\" level=\"Medium\">" +
					  "<results>" +
					  "<result match=\"that will\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			string testFilename = m_testPath + "TestContentAnalysisVisitor.txt";
			DocumentReader documentReader = DocumentReaderFactory.Create(testFilename);
			WsScanRules rules = new WsScanRules();
			rules.Add(new WsScanRule("Rule one", "Find the", "the", RuleLevels.High));
			rules.Add(new WsScanRule("Rule two", "Find that will", "that will", RuleLevels.Medium));
			ContentAnalysisVisitor contentAnalysisVisitor = new ContentAnalysisVisitor(rules);
			documentReader.Read(contentAnalysisVisitor);
			Assert.AreEqual(expectedContent, contentAnalysisVisitor.GetContent());
		}
Ejemplo n.º 2
0
		public void TestCreateRuleNullXmlDocument()
		{
			WsScanRules scanRules = new WsScanRules();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsScanRule findSomeRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			xmlContentBuilder.CreateRuleNode(null, findSomeRule);
		}
Ejemplo n.º 3
0
		public void TestCreateNullRule()
		{
			WsScanRules scanRules = new WsScanRules();
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			XmlElement ruleElement = xmlContentBuilder.CreateRuleNode(xmlDocument, null);
		}
Ejemplo n.º 4
0
		public IResultSet Process(string expression)
		{
            WsScanRules rules = new WsScanRules();
            rules.Add(new WsScanRule("Find", "FindIndex", expression, RuleLevels.High));
			WsDocumentScanner scanner = new WsDocumentScanner(m_filename, rules);
			return scanner.Match();
		}
Ejemplo n.º 5
0
		internal WsDocumentScanner(string filename, WsScanRules rules)
		{
			if(null == rules)
				return;

            m_contentAnalysisVisitor = new ContentAnalysisVisitor(rules);
            m_filename = filename;
		}
Ejemplo n.º 6
0
		private long ScannerHelper(string testFilename, string token)
		{
            WsScanRules scanRules = new WsScanRules();
            scanRules.Add(new WsScanRule("Find", "FindIndex", token, RuleLevels.High));
            
			WsDocumentScanner documentScanner = new WsDocumentScanner(testFilename, scanRules);
			return documentScanner.Match().TotalMatchCount;
		}
Ejemplo n.º 7
0
		public void TestCreateResultNodeNullXmlDocument()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Paragraph, findSomeIndex, new ArrayList());
			xmlContentBuilder.CreateResultNode(null, findSomeRule, result, "");
		}
Ejemplo n.º 8
0
		public void TestCreateRuleNode()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Test rule", "Find some", "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			XmlElement ruleElement = xmlContentBuilder.CreateRuleNode(xmlDocument, findSomeRule);
			Assert.IsNotNull(ruleElement);
			Assert.AreEqual("<rule name=\"Find some\" level=\"High\" />", ruleElement.OuterXml);
		}
Ejemplo n.º 9
0
		internal WsScanRules LoadScanRulesFromPolicy()
		{
			XmlDocument scanPolicy = GetPolicyFromDisk();
			if(scanPolicy == null)
				scanPolicy = GetDefaultPolicy();

			XmlNodeList rulesetNodes = scanPolicy.SelectNodes("/project/ruleset");
			if(rulesetNodes == null)
				throw new WsException("Invalid policy file");

			WsScanRules scanRules = new WsScanRules();
			foreach(XmlNode rulesetNode in rulesetNodes)
			{
				foreach(XmlNode ruleNode in rulesetNode.ChildNodes)
				{
                    XmlAttribute nameAttribute = ruleNode.Attributes["name"];
                    if (nameAttribute == null)
                        continue;
                    string rulename = nameAttribute.Value;

                    XmlAttribute levelAttribute = ruleNode.Attributes["level"];
                    if (levelAttribute == null)
                        continue;
                    RuleLevels ruleLevel = RuleLevelNameToEnum(levelAttribute.Value);

					foreach(XmlNode conditionNode in ruleNode.ChildNodes)
					{
                        XmlAttribute conditionAttribute = conditionNode.Attributes["index"];
                        if (conditionAttribute == null)
                            continue;
                        string conditionIndex = conditionAttribute.Value;

                        XmlAttribute operandAttribute = conditionNode.Attributes["operand"];
                        if (operandAttribute == null)
                            continue;
                        string expression = operandAttribute.Value;

                        WsScanRule scanRule = new WsScanRule(rulename, conditionIndex, expression, ruleLevel);
						foreach(XmlNode contextNode in conditionNode.ChildNodes)
						{
                            XmlAttribute nameAttribute2 = contextNode.Attributes["name"];
                            if(nameAttribute2 == null)
                                continue;

                            scanRule.Ranges.Add(nameAttribute2.Value);
						}
						scanRules.Add(scanRule);
					}
				}
			}

			return scanRules;
		}
		public void TestResults()
		{
			string testFilename = m_testPath + "TestContentAnalysisVisitor.txt";
			DocumentReader documentReader = DocumentReaderFactory.Create(testFilename);
			WsScanRules rules = new WsScanRules();
			rules.Add(new WsScanRule("Find the", "FindTheIndex", "the", RuleLevels.High));
			rules.Add(new WsScanRule("Find that will", "FindThatIndex", "that will", RuleLevels.High));
			ContentAnalysisVisitor contentAnalysisVisitor = new ContentAnalysisVisitor(rules);
			documentReader.Read(contentAnalysisVisitor);
			Assert.AreEqual(5, contentAnalysisVisitor.Results.TotalMatchCount);
			Assert.AreEqual(3, contentAnalysisVisitor.Results.GetMatches(RangeTypes.Paragraph, "FindTheIndex").TotalMatchCount);
			Assert.AreEqual(2, contentAnalysisVisitor.Results.GetMatches(RangeTypes.Paragraph, "FindThatIndex").TotalMatchCount);
		}
Ejemplo n.º 11
0
		public IResultSet Process(string expression, params RangeTypes[] types)
		{
            WsScanRules rules = new WsScanRules();
            WsScanRule rule = new WsScanRule("Find", "FindIndex", expression, RuleLevels.High);
            
            foreach(RangeTypes type in types)
                rule.Ranges.Add(type);

            rules.Add(rule);

            WsDocumentScanner scanner = new WsDocumentScanner(m_filename, rules);			
			return scanner.Match();
		}
Ejemplo n.º 12
0
		public void TestCreateResultsNodeNoResultsName()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someData));

			string expectedResultsXml = 
					  "<results>" + 
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>";

			if (Is64Bit())
				expectedResultsXml =
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "</results>";

			
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement resultsElement = xmlContentBuilder.CreateResultsNode(xmlDocument, findSomeRule, results);
			Assert.AreEqual(expectedResultsXml, resultsElement.OuterXml);
		}
Ejemplo n.º 13
0
		public XMLContentBuilder(WsScanRules scanRules)
		{
			m_scanRules = scanRules;
		}
		public void TestTrackChangesThatSpan()
		{
			const string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find track change\" level=\"High\">" +
					  "<results>" +
//					  "<result match=\"Track change text\" context=\"TrackChange\" count=\"1\" />" +
					  "<result match=\"track change text\" context=\"TrackChange\" count=\"1\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			string testFilename = m_testPath + "TrackChangesThatSpan.doc";
			DocumentReader documentReader = DocumentReaderFactory.Create(testFilename);
			WsScanRules rules = new WsScanRules();
			rules.Add(new WsScanRule("Test rule", "Find track change", "Track change text", RuleLevels.High));
			ContentAnalysisVisitor contentAnalysisVisitor = new ContentAnalysisVisitor(rules);
			documentReader.Read(contentAnalysisVisitor);
			Assert.AreEqual(expectedContent, contentAnalysisVisitor.GetContent());
		}
Ejemplo n.º 15
0
		public void TestBuildContentNoResults()
		{
			const string expectedContent = "<DISRules />";

			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Rule 1", "Find not exist", "not exist", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(new WsMatchInRangeCollection());
			Assert.AreEqual(expectedContent, xmlContent);
		}
Ejemplo n.º 16
0
		public void TestBuildContentNoContext()
		{
			const string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Comment\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Rule 1", "Find some", "some", RuleLevels.High);
			scanRules.Add(findSomeRule);

			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			
			ArrayList someDataInParagraph = new ArrayList();
			someDataInParagraph.Add("Some");
			someDataInParagraph.Add("Some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someDataInParagraph));

			ArrayList someDataInComment = new ArrayList();
			someDataInComment.Add("some");
			someDataInComment.Add("some");
			someDataInComment.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Comment, findSomeRule.Condition, someDataInComment));

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(results);
			Assert.AreEqual(expectedContent, xmlContent);
		}
Ejemplo n.º 17
0
		public void TestCreateResultsNodeNoResults()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule scanRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			scanRules.Add(scanRule);
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			XmlElement resultsElement = xmlContentBuilder.CreateResultsNode(xmlDocument, scanRule, results);
			Assert.IsNull(resultsElement, "Expected a null results node for no results");
		}
Ejemplo n.º 18
0
		public void TestCreateNullResultsNode()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule scanRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			scanRules.Add(scanRule);
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			xmlContentBuilder.CreateResultsNode(xmlDocument, scanRule, null);
		}
Ejemplo n.º 19
0
		public void TestCreateResultsNodeNullScanRule()
		{
			WsScanRules scanRules = new WsScanRules();
			WsScanRule scanRule = new WsScanRule("Find some", "FindSomeIndex", "some", RuleLevels.High);
			scanRules.Add(scanRule);
			XmlDocument xmlDocument = new XmlDocument();
			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			xmlContentBuilder.CreateResultsNode(xmlDocument, null, results);
		}
Ejemplo n.º 20
0
		public void TestCreateResultNodeInContext()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");

			XmlDocument xmlDocument = new XmlDocument();
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Comment, findSomeIndex, someData);
			XmlElement resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "Some");
			Assert.IsNull(resultNode, "Expected a null instance for a key that does not match the search data that is out of context");
		}
Ejemplo n.º 21
0
		public void TestCreateResultNode()
		{
			const string findSomeIndex = "FindSomeIndex";
			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Find some", findSomeIndex, "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");

			const string expectedResult1 = "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />";
			const string expectedResult2 = "<result match=\"some\" context=\"Paragraph\" count=\"1\" />";

			XmlDocument xmlDocument = new XmlDocument();
			WsMatchInRange result = new WsMatchInRange(RangeTypes.Paragraph, findSomeIndex, someData);
			XmlElement resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "Some");
			Assert.AreEqual(expectedResult1, resultNode.OuterXml);
			resultNode = xmlContentBuilder.CreateResultNode(xmlDocument, findSomeRule, result, "some");
			Assert.AreEqual(expectedResult2, resultNode.OuterXml);
		}
Ejemplo n.º 22
0
		public ContentAnalysisVisitor(WsScanRules scanRules)
		{
			m_scanRules = scanRules;
		}
Ejemplo n.º 23
0
		public void TestBuildContent()
		{
			string expectedContent = 
					  "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "</results>" +
					  "</rule>" +
					  "<rule name=\"Find that\" level=\"Medium\">" +
					  "<results>" +
					  "<result match=\"that\" context=\"Paragraph\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";

			if (Is64Bit())
				expectedContent = "<DISRules>" +
					  "<rule name=\"Find some\" level=\"High\">" +
					  "<results>" +
					  "<result match=\"Some\" context=\"Paragraph\" count=\"2\" />" +
					  "<result match=\"some\" context=\"Paragraph\" count=\"1\" />" +
					  "</results>" +
					  "</rule>" +
					  "<rule name=\"Find that\" level=\"Medium\">" +
					  "<results>" +
					  "<result match=\"that\" context=\"Paragraph\" count=\"3\" />" +
					  "</results>" +
					  "</rule>" +
					  "</DISRules>";



			WsScanRules scanRules = new WsScanRules();
			WsScanRule findSomeRule = new WsScanRule("Rule 1", "Find some", "some", RuleLevels.High);
			findSomeRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findSomeRule);

			WsScanRule findThatRule = new WsScanRule("Rule 2", "Find that", "that", RuleLevels.Medium);
			findThatRule.Ranges.Add(RangeTypes.Paragraph);
			scanRules.Add(findThatRule);

			WsMatchInRangeCollection results = new WsMatchInRangeCollection();
			
			ArrayList someData = new ArrayList();
			someData.Add("Some");
			someData.Add("Some");
			someData.Add("some");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findSomeRule.Condition, someData));

			ArrayList thatData = new ArrayList();
			thatData.Add("that");
			thatData.Add("that");
			thatData.Add("that");
			results.Add(new WsMatchInRange(RangeTypes.Paragraph, findThatRule.Condition, thatData));

			XMLContentBuilder xmlContentBuilder = new XMLContentBuilder(scanRules);
			string xmlContent = xmlContentBuilder.BuildContent(results);
			Assert.AreEqual(expectedContent, xmlContent);
		}