public void ToSqlStringTwoCriteriaAndTwoOptions() { int productId = 20; String productName = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.GreaterThan, productId, 0), new StringSearchOption(StackHashObjectType.Product, "Name", StackHashSearchOptionType.StringContains, productName, null, false) }; StackHashSearchOptionCollection options2 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.RangeInclusive, productId, productId + 5), new StringSearchOption(StackHashObjectType.Product, "Name", StackHashSearchOptionType.StringStartsWith, productName, null, false) }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), new StackHashSearchCriteria(options2), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("(((P.ProductId>{0}) AND (P.ProductName LIKE N'%{1}%')) OR ((P.ProductId BETWEEN {0} AND {2}) AND (P.ProductName LIKE N'{1}%')))", productId, productName, productId + 5); Assert.AreEqual(expected, result); }
public void AddSearchCriteria(StackHashSearchCriteriaCollection searchCriteria) { if (searchCriteria == null) { throw new ArgumentNullException("searchCriteria"); } bool firstCriteria = true; m_SqlSearch.Append("("); foreach (StackHashSearchCriteria criteria in searchCriteria) { if (!firstCriteria) { m_SqlSearch.Append(" OR "); } else { firstCriteria = false; } // These conditions should be connected with an OR. AddSearchCriteria(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 ToSqlStringProduct_ProductId() { int productId = 20; StackHashSearchOptionCollection options = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.Equal, productId, 0) }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options) }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("(P.ProductId={0})", productId); Assert.AreEqual(expected, result); }
public void ToSqlStringNoMatches() { int productId = 20; StackHashSearchOptionCollection options = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "ProductId", StackHashSearchOptionType.Equal, productId, 0) }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options) }; String result = allCriteria.ToSqlString(StackHashObjectType.File, "F"); String expected = String.Empty; Assert.AreEqual(expected, result); }
public void ToSqlStringStringWildcardOnProduct() { String searchString = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new StringSearchOption(StackHashObjectType.Product, "*", StackHashSearchOptionType.StringStartsWith, searchString, searchString, false), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("((P.ProductName LIKE N'{0}%') OR (P.Version LIKE N'{0}%'))", searchString); Assert.AreEqual(expected, result); }
public void ToSqlStringLongWildcardOnProduct() { long searchLong = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new LongSearchOption(StackHashObjectType.Product, "*", StackHashSearchOptionType.GreaterThan, searchLong, searchLong), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = ""; // No long fields. Assert.AreEqual(expected, result); }
public void ToSqlStringLongWildcardOnEventSignature() { long searchLong = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new LongSearchOption(StackHashObjectType.EventSignature, "*", StackHashSearchOptionType.RangeInclusive, searchLong, searchLong + 1), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventSignature, "ES"); String expected = "((ES.Offset BETWEEN 20 AND 21) OR (ES.ExceptionCode BETWEEN 20 AND 21))"; // No long fields. Assert.AreEqual(expected, result); }
public void ToSqlStringIntegerWildcardOnProduct() { int productId = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "*", StackHashSearchOptionType.GreaterThan, productId, 0), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("((P.ProductId>{0}) OR (P.TotalEvents>{0}) OR (P.TotalResponses>{0}) OR (P.TotalStoredEvents>{0}))", productId); Assert.AreEqual(expected, result); }
public void ToSqlStringLongWildcardOnEventInfo() { long searchLong = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new LongSearchOption(StackHashObjectType.EventInfo, "*", StackHashSearchOptionType.RangeInclusive, searchLong, searchLong + 1), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventInfo, "EI"); String expected = ""; Assert.AreEqual(expected, result); }
public void ToSqlStringLongWildcardOnCabInfo() { long searchLong = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new LongSearchOption(StackHashObjectType.CabInfo, "*", StackHashSearchOptionType.RangeInclusive, searchLong, searchLong + 1), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.CabInfo, "C"); String expected = "(C.SizeInBytes BETWEEN 20 AND 21)"; Assert.AreEqual(expected, result); }
public void ToSqlStringDateTimeWildcardOnProduct() { DateTime searchDateTime = new DateTime(2010, 11, 12); StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new DateTimeSearchOption(StackHashObjectType.Product, "*", StackHashSearchOptionType.RangeExclusive, searchDateTime, searchDateTime), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("((P.DateCreatedLocal>'2010-11-12T00:00:00' AND P.DateCreatedLocal<'2010-11-12T00:00:00') OR (P.DateModifiedLocal>'2010-11-12T00:00:00' AND P.DateModifiedLocal<'2010-11-12T00:00:00'))"); Assert.AreEqual(expected, result); }
public void ToSqlStringStringDoesNotContain() { int productId = 20; String productName = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new StringSearchOption(StackHashObjectType.Product, "Name", StackHashSearchOptionType.StringDoesNotContain, productName, null, false) }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("(P.ProductName NOT LIKE N'%MyProduct%' OR P.ProductName IS NULL)", productId, productName); Assert.AreEqual(expected, result); }
public void ToSqlStringIntegerWildcardOnEvent() { int searchInt = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Event, "*", StackHashSearchOptionType.GreaterThan, searchInt, 0), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Event, "E"); String expected = String.Format("((E.EventId>20) OR (E.TotalHits>20) OR (E.WorkFlowStatus>20) OR (CABCOUNTER.CabCount>20))"); Assert.AreEqual(expected, result); }
public void ToSqlStringStringWildcardOnCabInfo() { String searchString = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new StringSearchOption(StackHashObjectType.CabInfo, "*", StackHashSearchOptionType.RangeInclusive, searchString, searchString, false), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.CabInfo, "C"); String expected = "((CET.EventTypeName BETWEEN N'MyProduct' AND N'MyProduct') OR (C.CabFileName BETWEEN N'MyProduct' AND N'MyProduct'))"; Assert.AreEqual(expected, result); }
public void ToSqlStringIntegerWildcardOnEventSignature() { int searchInt = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.EventSignature, "*", StackHashSearchOptionType.GreaterThan, searchInt, 0), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventSignature, "ES"); String expected = ""; Assert.AreEqual(expected, result); }
public void ToSqlStringIntegerWildcardOnCabInfo() { int searchInt = 20; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.CabInfo, "*", StackHashSearchOptionType.GreaterThan, searchInt, 0), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.CabInfo, "C"); String expected = "((C.EventId>20) OR (C.CabId>20))"; Assert.AreEqual(expected, result); }
public void ToSqlStringDateTimeWildcardOnEventSignature() { DateTime searchDateTime = new DateTime(2010, 11, 12); StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new DateTimeSearchOption(StackHashObjectType.EventSignature, "*", StackHashSearchOptionType.RangeExclusive, searchDateTime, searchDateTime.AddDays(2)), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventSignature, "ES"); String expected = "((ES.ApplicationTimeStamp>'2010-11-12T00:00:00' AND ES.ApplicationTimeStamp<'2010-11-14T00:00:00') OR (ES.ModuleTimeStamp>'2010-11-12T00:00:00' AND ES.ModuleTimeStamp<'2010-11-14T00:00:00'))"; Assert.AreEqual(expected, result); }
public void ToSqlStringStringWildcardOnEventInfo() { String searchString = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new StringSearchOption(StackHashObjectType.EventInfo, "*", StackHashSearchOptionType.RangeInclusive, searchString, searchString, false), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventInfo, "EI"); String expected = "((l.LocaleName BETWEEN N'MyProduct' AND N'MyProduct') OR (l.LocaleCode BETWEEN N'MyProduct' AND N'MyProduct') OR (O.OperatingSystemName BETWEEN N'MyProduct' AND N'MyProduct') OR (O.OperatingSystemVersion BETWEEN N'MyProduct' AND N'MyProduct'))"; Assert.AreEqual(expected, result); }
public void ToSqlStringStringWildcardOnEventSignature() { String searchString = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new StringSearchOption(StackHashObjectType.EventSignature, "*", StackHashSearchOptionType.RangeInclusive, searchString, searchString, false), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.EventSignature, "ES"); String expected = "((ES.ApplicationName BETWEEN N'MyProduct' AND N'MyProduct') OR (ES.ApplicationVersion BETWEEN N'MyProduct' AND N'MyProduct') OR (ES.ModuleName BETWEEN N'MyProduct' AND N'MyProduct') OR (ES.ModuleVersion BETWEEN N'MyProduct' AND N'MyProduct'))"; Assert.AreEqual(expected, result); }
public void ToSqlStringDateTimeWildcardOnCabInfo() { DateTime searchDateTime = new DateTime(2010, 11, 12); StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new DateTimeSearchOption(StackHashObjectType.CabInfo, "*", StackHashSearchOptionType.RangeExclusive, searchDateTime, searchDateTime.AddDays(2)), }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.CabInfo, "C"); String expected = "((C.DateCreatedLocal>'2010-11-12T00:00:00' AND C.DateCreatedLocal<'2010-11-14T00:00:00') OR (C.DateModifiedLocal>'2010-11-12T00:00:00' AND C.DateModifiedLocal<'2010-11-14T00:00:00'))"; Assert.AreEqual(expected, result); }
/// <summary> /// Detects if a search contains a script search element /// </summary> /// <param name="search">StackHashSearchCriteriaCollection</param> /// <returns>True if a script search is included</returns> public static bool SearchContainsScriptSearch(StackHashSearchCriteriaCollection search) { bool script = false; if (search != null) { foreach (StackHashSearchCriteria criteria in search) { foreach (StackHashSearchOption option in criteria.SearchFieldOptions) { if (option.ObjectType == StackHashObjectType.Script) { script = true; break; } } } } return(script); }
public void ToSqlStringOneOfTwoOptionsBothMatch() { int productId = 20; String productName = "MyProduct"; StackHashSearchOptionCollection options1 = new StackHashSearchOptionCollection() { new IntSearchOption(StackHashObjectType.Product, "Id", StackHashSearchOptionType.GreaterThan, productId, 0), new StringSearchOption(StackHashObjectType.Product, "Name", StackHashSearchOptionType.StringContains, productName, null, false) }; StackHashSearchCriteriaCollection allCriteria = new StackHashSearchCriteriaCollection() { new StackHashSearchCriteria(options1), }; String result = allCriteria.ToSqlString(StackHashObjectType.Product, "P"); String expected = String.Format("((P.ProductId>{0}) AND (P.ProductName LIKE N'%{1}%'))", productId, productName); Assert.AreEqual(expected, result); }
// // 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); } }
/// <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]); } } }
// // 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); }
public StackHashEventPackageCollection GetEvents(StackHashSearchCriteriaCollection searchCriteriaCollection, long startRow, long numberOfRows, StackHashSortOrderCollection sortOptions, StackHashProductSyncDataCollection enabledProducts) { return(null); }
public StackHashEventPackageCollection GetEvents(StackHashSearchCriteriaCollection searchCriteriaCollection, StackHashProductSyncDataCollection enabledProducts) { return(null); }
/// <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(); } } }