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); }
// // 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); }
/// <summary> /// Copy all events associated with the specified product file. /// Events are copied in blocks to avoid using too much memory. /// </summary> /// <param name="product">The product that owns the file.</param> /// <param name="file">The file that owns the events to copy.</param> private void copyEvents(StackHashProduct product, StackHashFile file) { // Define the search criteria for the events. StackHashSearchCriteriaCollection searchCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria( new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, product.Id, 0), new IntSearchOption(StackHashObjectType.File, "Id", StackHashSearchOptionType.Equal, file.Id, 0), }) }; // Order by the event id and EventTypeName. Need to do both in case there is more than 1 event with the same // event type name. SQL server doesn't guarantee the order in which they would be returned back so one might be // missed if the event type name is not also specified here. StackHashSortOrderCollection sortOrder = new StackHashSortOrderCollection() { new StackHashSortOrder(StackHashObjectType.Event, "Id", true), new StackHashSortOrder(StackHashObjectType.Event, "EventTypeName", true) }; // Copy 100 events at a time. int startRow = 1; int numberOfRows = m_TaskParameters.EventsPerBlock; StackHashEventPackageCollection events; if (m_SourceIndex.IndexType == ErrorIndexType.SqlExpress) { events = m_SourceIndex.GetEvents(searchCriteria, startRow, numberOfRows, sortOrder, null); } else { events = m_SourceIndex.GetFileEvents(product.Id, file.Id, startRow, numberOfRows); } while ((events != null) && (events.Count > 0)) { if (this.CurrentTaskState.AbortRequested) { throw new StackHashException("Index event block copy aborted", StackHashServiceErrorCode.Aborted); } copyEventBlock(product, file, events); startRow += numberOfRows; // Get the next block of events. if (events.Count >= numberOfRows) { if (m_SourceIndex.IndexType == ErrorIndexType.SqlExpress) { events = m_SourceIndex.GetEvents(searchCriteria, startRow, numberOfRows, sortOrder, null); } else { events = m_SourceIndex.GetFileEvents(product.Id, file.Id, startRow, numberOfRows); } } else { events.Clear(); } } }
/// <summary> /// Processes a specific file. /// </summary> private void processFile(StackHashBugReportData request, StackHashProduct product, StackHashFile file) { if (this.CurrentTaskState.AbortRequested) { throw new OperationCanceledException("Reporting events to Bug Tracker plug-ins"); } BugTrackerProduct btProduct = new BugTrackerProduct(product.Name, product.Version, product.Id); BugTrackerFile btFile = new BugTrackerFile(file.Name, file.Version, file.Id); if (((request.Options & StackHashReportOptions.IncludeFiles) != 0) || ((request.Options & StackHashReportOptions.IncludeAllObjects) != 0)) { m_TaskParameters.PlugInContext.FileAdded(m_PlugIns, m_ReportType, btProduct, btFile); checkPlugInStatus(m_PlugIns); } if (request.TheEvent == null) { // Parse the events. StackHashSortOrderCollection sortOrder = new StackHashSortOrderCollection() { new StackHashSortOrder(StackHashObjectType.Event, "Id", true), new StackHashSortOrder(StackHashObjectType.Event, "EventTypeName", true) }; StackHashSearchOptionCollection searchOptions = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, product.Id, 0), new IntSearchOption(StackHashObjectType.File, "Id", StackHashSearchOptionType.Equal, file.Id, 0), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(searchOptions) }; int startRow = 1; int numberOfRows = 100; StackHashEventPackageCollection allPackages = null; do { allPackages = m_Index.GetEvents(allCriteria, startRow, numberOfRows, sortOrder, null); foreach (StackHashEventPackage eventPackage in allPackages) { processEventPackage(request, product, file, eventPackage); } startRow += numberOfRows; } while (allPackages.Count > 0); } else { StackHashSearchOptionCollection searchOptions = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, product.Id, 0), new IntSearchOption(StackHashObjectType.File, "Id", StackHashSearchOptionType.Equal, file.Id, 0), new IntSearchOption(StackHashObjectType.Event, "Id", StackHashSearchOptionType.Equal, request.TheEvent.Id, 0), new StringSearchOption(StackHashObjectType.Event, "EventTypeName", StackHashSearchOptionType.Equal, request.TheEvent.EventTypeName, request.TheEvent.EventTypeName, false), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(searchOptions) }; StackHashEventPackageCollection eventPackages = m_Index.GetEvents(allCriteria, null); if ((eventPackages != null) && (eventPackages.Count == 1)) { processEventPackage(request, product, file, eventPackages[0]); } } }
private void listViewEventsHeader_Click(object sender, RoutedEventArgs e) { GridViewColumnHeader header = e.OriginalSource as GridViewColumnHeader; if (header != null) { // can only sort columns with an associated tag string tagName = header.Tag as string; if (!string.IsNullOrEmpty(tagName)) { // remove previous sort adorner if ((_lastSortColumn != null) && (_lastSortAdorner != null)) { AdornerLayer.GetAdornerLayer(_lastSortColumn).Remove(_lastSortAdorner); } _lastSortAdorner = null; ListSortDirection direction = ListSortDirection.Descending; if (header == _lastSortColumn) { if (_lastSortDirection == ListSortDirection.Ascending) { direction = ListSortDirection.Descending; } else { direction = ListSortDirection.Ascending; } } // to be applied after the event packages are fetched _nextSortAdorner = new SortDirectionAdorner(header, direction); _lastSortDirection = direction; _lastSortColumn = header; StackHashSortOrder sortOrder = new StackHashSortOrder(); sortOrder.Ascending = (direction == ListSortDirection.Ascending); sortOrder.FieldName = tagName; switch (tagName) { case "Id": case "TotalHits": case "CabCount": case "BugId": case "PlugInBugId": case "EventTypeName": case "DateCreatedLocal": case "DateModifiedLocal": case "WorkFlowStatusName": // these fields are from the event sortOrder.ObjectType = StackHashObjectType.Event; break; default: // all other tags are from the event signature sortOrder.ObjectType = StackHashObjectType.EventSignature; break; } StackHashSortOrderCollection sort = new StackHashSortOrderCollection(); sort.Add(sortOrder); ClientLogic clientLogic = this.DataContext as ClientLogic; Debug.Assert(clientLogic != null); // run the sort, returning to the first page clientLogic.PopulateEventPackages(clientLogic.CurrentProduct, clientLogic.LastEventsSearch, sort, 1, UserSettings.Settings.EventPageSize, clientLogic.CurrentProduct == null ? UserSettings.Settings.GetDisplayHitThreshold(UserSettings.InvalidContextId) : UserSettings.Settings.GetDisplayHitThreshold(clientLogic.CurrentProduct.Id), ClientLogicView.EventList, PageIntention.First, UserSettings.Settings.ShowEventsWithoutCabs); } } }
// // 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 GetWindowedEventPackageResponse windowSearch(ErrorIndexType errorIndexType, StackHashTestIndexData testIndexData, StackHashSearchCriteriaCollection allSearchCriteria, long startRow, long numRows, StackHashSortOrderCollection sortOrder, StackHashSearchDirection direction, bool countAllMatches) { // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(errorIndexType); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = errorIndexType; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { m_Utils.SetProductSynchronizationState(0, product.Product.Id, true); } GetWindowedEventPackageResponse eventPackages = m_Utils.GetWindowedEvents(0, allSearchCriteria, startRow, numRows, sortOrder, direction, countAllMatches); return(eventPackages); } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
public StackHashEventPackageCollection GetEvents(StackHashSearchCriteriaCollection searchCriteriaCollection, long startRow, long numberOfRows, StackHashSortOrderCollection sortOptions, StackHashProductSyncDataCollection enabledProducts) { return(null); }