public void AddSearchCriteria(StackHashSearchCriteria searchCriteria) { if (searchCriteria == null) { throw new ArgumentNullException("searchCriteria"); } bool firstOption = true; m_SqlSearch.Append("("); foreach (StackHashSearchOption option in searchCriteria.SearchFieldOptions) { if (!firstOption) { m_SqlSearch.Append(" AND "); } else { firstOption = false; } AddSearchOption(option); } m_SqlSearch.Append(")"); }
public bool Search(StackHashSearchCriteria searchCriteria) { if (searchCriteria == null) { throw new ArgumentNullException("searchCriteria"); } if (!searchCriteria.ContainsObject(StackHashObjectType.Script)) { return(true); } if (m_ScriptResults == null) { return(false); } foreach (StackHashSearchOption searchOption in searchCriteria.SearchFieldOptions) { if (searchOption.ObjectType != StackHashObjectType.Script) { continue; } StringSearchOption stringSearchOption = searchOption as StringSearchOption; if (stringSearchOption == null) { continue; } // Only search the result lines. bool matchFound = false; foreach (StackHashScriptLineResult cmdOutput in m_ScriptResults) { if (cmdOutput.Search(true, stringSearchOption.Start)) { matchFound = true; } } bool optionMatched = false; if (stringSearchOption.SearchOptionType == StackHashSearchOptionType.StringContains && matchFound) { optionMatched = true; } else if (stringSearchOption.SearchOptionType == StackHashSearchOptionType.StringDoesNotContain && !matchFound) { optionMatched = true; } if (!optionMatched) { return(false); } } return(true); }
public void Contains_1Command_0Lines_NoMatch() { StackHashScriptResult scriptResult = new StackHashScriptResult(); scriptResult.ScriptResults = new StackHashScriptLineResults(); StackHashSearchCriteria criteria = new StackHashSearchCriteria(new StackHashSearchOptionCollection()); criteria.SearchFieldOptions.Add(new StringSearchOption( StackHashObjectType.Script, "Script", StackHashSearchOptionType.StringContains, "Hello", "Hello", false)); Assert.AreEqual(false, scriptResult.Search(criteria)); }
public void DontCountAllMatchesOnFirstPage() { // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 2; testIndexData.NumberOfEventInfos = 1; testIndexData.NumberOfCabs = 1; testIndexData.NumberOfScriptResults = 1; testIndexData.UseLargeCab = false; StackHashSearchCriteria criteria1 = new StackHashSearchCriteria(); criteria1.SearchFieldOptions = new StackHashSearchOptionCollection(); criteria1.SearchFieldOptions.Add(new IntSearchOption() { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.GreaterThan, Start = 0, End = 0 }); criteria1.SearchFieldOptions.Add(new StringSearchOption() { ObjectType = StackHashObjectType.Script, FieldName = "Content", SearchOptionType = StackHashSearchOptionType.StringContains, Start = "Script", End = null, CaseSensitive = false }); StackHashSearchCriteriaCollection allSearchCriteria = new StackHashSearchCriteriaCollection(); allSearchCriteria.Add(criteria1); StackHashSortOrderCollection sortOrder = new StackHashSortOrderCollection(); sortOrder.Add(new StackHashSortOrder() { ObjectType = StackHashObjectType.Event, FieldName = "Id", Ascending = true }); long startRow = 1; long numRows = 1; bool countAllMatches = false; StackHashSearchDirection direction = StackHashSearchDirection.Forwards; GetWindowedEventPackageResponse eventPackageResp = windowSearch(ErrorIndexType.SqlExpress, testIndexData, allSearchCriteria, startRow, numRows, sortOrder, direction, countAllMatches); Assert.AreEqual(1, eventPackageResp.EventPackages.Count); Assert.AreEqual(1, eventPackageResp.MinimumRowNumber); Assert.AreEqual(1, eventPackageResp.MaximumRowNumber); Assert.AreEqual(numRows, eventPackageResp.TotalRows); }
public void Contains_1Command_1Lines_Match() { StackHashScriptResult scriptResult = new StackHashScriptResult(); scriptResult.ScriptResults = new StackHashScriptLineResults(); scriptResult.ScriptResults.Add(new StackHashScriptLineResult(new StackHashScriptLine("Command1", "Comment1"), new StackHashScriptLineOutput())); scriptResult.ScriptResults[0].ScriptLineOutput.Add("Output line 1"); StackHashSearchCriteria criteria = new StackHashSearchCriteria(new StackHashSearchOptionCollection()); criteria.SearchFieldOptions.Add(new StringSearchOption( StackHashObjectType.Script, "Script", StackHashSearchOptionType.StringContains, "line", null, false)); Assert.AreEqual(true, scriptResult.Search(criteria)); }
public void SearchSecondOf2MatchesCriteriaFalse() { long sizeInBytes = 0x12345678; StackHashSearchOption fieldSearchOption1 = new LongSearchOption( StackHashObjectType.CabInfo, "SizeInBytes", StackHashSearchOptionType.RangeInclusive, sizeInBytes, sizeInBytes + 10); StackHashSearchOption fieldSearchOption2 = new IntSearchOption( StackHashObjectType.CabInfo, "Id", StackHashSearchOptionType.Equal, 22, 0); StackHashSearchOptionCollection fieldSearchOptions = new StackHashSearchOptionCollection(); fieldSearchOptions.Add(fieldSearchOption1); fieldSearchOptions.Add(fieldSearchOption2); StackHashSearchCriteria criteria1 = new StackHashSearchCriteria(fieldSearchOptions); StackHashCab cab = new StackHashCab(DateTime.Now, DateTime.Now, 10, "EventType", "Filename", 22, sizeInBytes - 1); Assert.AreEqual(false, criteria1.IsMatch(StackHashObjectType.CabInfo, cab)); }
public void DoesNotContain_2Command_1Lines_SecondCmdMatch() { StackHashScriptResult scriptResult = new StackHashScriptResult(); scriptResult.ScriptResults = new StackHashScriptLineResults(); scriptResult.ScriptResults.Add(new StackHashScriptLineResult(new StackHashScriptLine("Command1", "Comment1"), new StackHashScriptLineOutput())); scriptResult.ScriptResults[0].ScriptLineOutput.Add("Output line 1"); scriptResult.ScriptResults.Add(new StackHashScriptLineResult(new StackHashScriptLine("Command2", "Comment2"), new StackHashScriptLineOutput())); scriptResult.ScriptResults[0].ScriptLineOutput.Add("Output line 2"); StackHashSearchCriteria criteria = new StackHashSearchCriteria(new StackHashSearchOptionCollection()); criteria.SearchFieldOptions.Add(new StringSearchOption( StackHashObjectType.Script, "Script", StackHashSearchOptionType.StringDoesNotContain, "2", null, false)); Assert.AreEqual(false, scriptResult.Search(criteria)); }
public bool CabMatchesSearchCriteria(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, StackHashSearchCriteria searchCriteria) { if (product == null) { throw new ArgumentNullException("product"); } if (file == null) { throw new ArgumentNullException("file"); } if (theEvent == null) { throw new ArgumentNullException("theEvent"); } if (cab == null) { throw new ArgumentNullException("cab"); } if (searchCriteria == null) { throw new ArgumentNullException("searchCriteria"); } // Get a list of script result files for this cab. StackHashScriptResultFiles resultFiles = GetResultFiles(product, file, theEvent, cab); if ((resultFiles == null) || (resultFiles.Count == 0)) { return(false); } foreach (StackHashScriptResultFile resultFile in resultFiles) { try { StackHashScriptResult resultFileData = GetResultFileData(product, file, theEvent, cab, resultFile.ScriptName); if (resultFileData.Search(searchCriteria)) { return(true); } } catch (System.Exception ex) { // Don't allow corrupt files to stop the search. DiagnosticsHelper.LogException(DiagSeverity.Warning, "Corrupt or missing results file: " + resultFile.ScriptName + " for cab " + cab.Id.ToString(CultureInfo.InvariantCulture), ex); } } return(false); }
// // You can use the following additional attributes as you write your tests: // // Use ClassInitialize to run code before running the first test in the class // [ClassInitialize()] // public static void MyClassInitialize(TestContext testContext) { } // // Use ClassCleanup to run code after all tests in a class have run // [ClassCleanup()] // public static void MyClassCleanup() { } // // Use TestInitialize to run code before running each test // [TestInitialize()] // public void MyTestInitialize() { } // // Use TestCleanup to run code after each test has run // [TestCleanup()] // public void MyTestCleanup() { } // #endregion public void getWindowedEventsByOrder(ErrorIndexType indexType, int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, int windowSize, bool restrictSearchToParticularProduct, bool addLotsOfSearchOptions, List <int> enabledProducts, StackHashSearchDirection direction) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(indexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); // Make sure it is empty. m_Utils.ActivateContext(0); // Create a test index with one cab file. StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = numProducts; testIndexData.NumberOfFiles = numFiles; testIndexData.NumberOfEvents = numEvents; testIndexData.NumberOfEventInfos = numEventInfos; testIndexData.NumberOfCabs = numCabs; testIndexData.NumberOfScriptResults = numCabs; m_Utils.CreateTestIndex(0, testIndexData); GetProductsResponse getProductsResp = m_Utils.GetProducts(0); Assert.AreEqual(numProducts, getProductsResp.Products.Count()); StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection(); // Just get events for even numbered product ids. for (int productCount = 0; productCount < numProducts; productCount++) { if ((enabledProducts == null) || enabledProducts.Contains(productCount + 1)) { m_Utils.SetProductSynchronizationState(0, productCount + 1, true); } // This doesn't really do anything - just in here so there is at least 1 search option. StackHashSearchCriteria newCriteria = new StackHashSearchCriteria { SearchFieldOptions = new StackHashSearchOptionCollection() { new IntSearchOption { ObjectType = StackHashObjectType.Product, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.Equal, Start = productCount + 1, End = productCount + 1 }, } }; if (addLotsOfSearchOptions) { // Add some "always true" options just to complicate things. newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.RangeInclusive, Start = 0, End = Int32.MaxValue }); newCriteria.SearchFieldOptions.Add(new IntSearchOption { ObjectType = StackHashObjectType.Event, FieldName = "Id", SearchOptionType = StackHashSearchOptionType.GreaterThan, Start = 0, End = 0 }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.EventInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); newCriteria.SearchFieldOptions.Add(new DateTimeSearchOption { ObjectType = StackHashObjectType.CabInfo, FieldName = "DateCreatedLocal", SearchOptionType = StackHashSearchOptionType.RangeExclusive, Start = DateTime.Now.AddYears(-20), End = DateTime.Now.AddYears(20) }); } if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { allCriteria.Add(newCriteria); } } else { allCriteria.Add(newCriteria); } } // The events will be returned possibly in event id order from the search. // Set the sort order based on the Offset - ascending - this should return the events // in reverse event ID order as the offsets descend. StackHashSortOrderCollection allSortOrders = new StackHashSortOrderCollection() { new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "Offset", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateCreatedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "DateModifiedLocal", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "EventTypeName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "Id", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "TotalHits", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.Event, FieldName = "BugId", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ApplicationTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleName", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleVersion", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ModuleTimeStamp", Ascending = true }, new StackHashSortOrder { ObjectType = StackHashObjectType.EventSignature, FieldName = "ExceptionCode", Ascending = true }, }; int totalEventsExpected = numProducts * numFiles * numEvents; List <int> expectedEventIds = new List <int>(); int expectedEventId = 1; for (int productCount = 0; productCount < numProducts; productCount++) { for (int fileCount = 0; fileCount < numFiles; fileCount++) { for (int eventCount = 0; eventCount < numEvents; eventCount++) { // Only add product events for even numbered products. if (restrictSearchToParticularProduct) { if (((productCount + 1) % 2) == 0) { expectedEventIds.Add(expectedEventId++); } else { expectedEventId++; } } else if ((enabledProducts != null) && !enabledProducts.Contains(productCount + 1)) { expectedEventId++; } else { expectedEventIds.Add(expectedEventId++); } } } } expectedEventIds.Reverse(); for (int startRow = 1; startRow <= expectedEventIds.Count; startRow++) { DateTime startTime = DateTime.Now; // Get the next window. GetWindowedEventPackageResponse allPackages = m_Utils.GetWindowedEvents(0, allCriteria, startRow, windowSize, allSortOrders, direction, startRow == 1); TimeSpan totalTime = DateTime.Now - startTime; Console.WriteLine("Window: {0}, startRow: {1}, numRows: {2}, duration: {3}", windowSize, startRow, allPackages.EventPackages.Count, totalTime); Assert.AreNotEqual(null, allPackages.EventPackages); int expectedRowsReturned = startRow + windowSize - 1 > expectedEventIds.Count ? expectedEventIds.Count - startRow + 1 : windowSize; if (expectedRowsReturned < 0) { expectedRowsReturned = 0; } Assert.AreEqual(expectedRowsReturned, allPackages.EventPackages.Count); for (int eventIndex = 0; eventIndex < expectedRowsReturned; eventIndex++) { int nextExpectedEventId = expectedEventIds[startRow + eventIndex - 1]; StackHashEventPackage eventRetrieved = allPackages.EventPackages[eventIndex]; Assert.AreEqual(nextExpectedEventId, eventRetrieved.EventData.Id); Assert.AreEqual(numCabs, eventRetrieved.Cabs.Count); Assert.AreEqual(numEventInfos, eventRetrieved.EventInfoList.Count); foreach (StackHashCabPackage cabPackage in eventRetrieved.Cabs) { Assert.AreNotEqual(null, cabPackage.Cab); Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } // Get the event package through the other interface. StackHashProduct product = new StackHashProduct() { Id = eventRetrieved.ProductId }; StackHashFile file = new StackHashFile() { Id = eventRetrieved.EventData.FileId }; StackHashEventPackage matchedPackage = m_Utils.GetEventPackage(0, product, file, eventRetrieved.EventData).EventPackage; Assert.AreEqual(eventRetrieved.Cabs.Count, matchedPackage.Cabs.Count); foreach (StackHashCabPackage cabPackage in matchedPackage.Cabs) { Assert.AreNotEqual(null, cabPackage.CabFileContents); Assert.AreNotEqual(null, cabPackage.CabFileContents.Files); Assert.AreEqual(2, cabPackage.CabFileContents.Files.Count); Assert.AreEqual("cuckusrv.exe.mdmp", cabPackage.CabFileContents.Files[0].FileName); Assert.AreEqual(0x1a5cb, cabPackage.CabFileContents.Files[0].Length); Assert.AreEqual("version.txt", cabPackage.CabFileContents.Files[1].FileName); Assert.AreEqual(0x24, cabPackage.CabFileContents.Files[1].Length); } } } m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); }