private void copyCabFiles(IErrorIndex sourceIndex, IErrorIndex destinationIndex, StackHashProduct product, StackHashFile file, StackHashEventPackage eventPackage, StackHashCab cab) { // Copy the actual Cab file and any results files. String sourceCabFolder = sourceIndex.GetCabFolder(product, file, eventPackage.EventData, cab); String destCabFolder = destinationIndex.GetCabFolder(product, file, eventPackage.EventData, cab); if (Directory.Exists(sourceCabFolder)) { String sourceCabFileName = sourceIndex.GetCabFileName(product, file, eventPackage.EventData, cab); if (File.Exists(sourceCabFileName)) { if (!Directory.Exists(destCabFolder)) { Directory.CreateDirectory(destCabFolder); } String destinationCabFileName = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}", destCabFolder, Path.GetFileName(sourceCabFileName)); if (!File.Exists(destinationCabFileName)) { File.Copy(sourceCabFileName, destinationCabFileName); } } // Copy the analysis data if it exists. String sourceAnalysisFolder = String.Format(CultureInfo.InvariantCulture, "{0}\\Analysis", sourceCabFolder); String destAnalysisFolder = String.Format(CultureInfo.InvariantCulture, "{0}\\Analysis", destCabFolder); if (Directory.Exists(sourceAnalysisFolder)) { String[] allFiles = Directory.GetFiles(sourceAnalysisFolder, "*.log"); if (allFiles.Length != 0) { if (!Directory.Exists(destAnalysisFolder)) { Directory.CreateDirectory(destAnalysisFolder); } foreach (String fileName in allFiles) { String destAnalysisFile = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}", destAnalysisFolder, Path.GetFileName(fileName)); if (!File.Exists(destAnalysisFile)) { File.Copy(fileName, destAnalysisFile); } } } } } }
public DisplayEventPackage(StackHashEventPackage stackHashEventPackage, Dictionary <int, DisplayMapping> workFlowLookup, ObservableCollection <DisplayMapping> workFlowList) { if (stackHashEventPackage == null) { throw new ArgumentNullException("stackHashEventPackage"); } if (workFlowLookup == null) { throw new ArgumentNullException("workFlowLookup"); } if (workFlowList == null) { throw new ArgumentNullException("workFlowList"); } if (stackHashEventPackage.EventData == null) { throw new ArgumentNullException("stackHashEventPackage", "stackHashEventPackage.EventData is null"); } if (stackHashEventPackage.EventData.EventSignature == null) { throw new ArgumentNullException("stackHashEventPackage", "stackHashEventPackage.EventData.EventSignature is null"); } _stackHashEventPackage = stackHashEventPackage; // update the exception message UpdateExceptionMessage(); // update WorkFlowDisplayMapping this.WorkFlowDisplayMapping = workFlowLookup[stackHashEventPackage.EventData.WorkFlowStatus]; this.AvailableWorkFlowDisplayMappings = workFlowList; _cabs = new ObservableCollection <DisplayCab>(); _eventInfoList = new ObservableCollection <DisplayEventInfo>(); if (_stackHashEventPackage.Cabs != null) { foreach (StackHashCabPackage cab in _stackHashEventPackage.Cabs) { _cabs.Add(new DisplayCab(cab)); } } if (_stackHashEventPackage.EventInfoList != null) { foreach (StackHashEventInfo hit in _stackHashEventPackage.EventInfoList) { _eventInfoList.Add(new DisplayEventInfo(hit)); } } }
/// <summary> /// Gets all the event data stored about a particular event. /// </summary> /// <param name="requestData">Request data.</param> /// <returns>Event package included per instance and cab data.</returns> public GetEventPackageResponse GetEventPackage(GetEventPackageRequest requestData) { if (requestData == null) { throw new ArgumentNullException("requestData"); } GetEventPackageResponse resp = new GetEventPackageResponse(); StackHashEventPackage eventPackage = StaticObjects.TheStaticObjects.TheController.GetEventPackage( requestData.ContextId, requestData.Product, requestData.File, requestData.Event); resp.EventPackage = eventPackage; resp.Product = requestData.Product; resp.File = requestData.File; resp.Event = requestData.Event; resp.ResultData = new StackHashServiceResultData( StackHashServiceResult.Success, s_OperationSuccessful, null); return(resp); }
public void runAnalyzeJustAutoScripts(ErrorIndexType indexType, int numberOfProducts, int numberOfFiles, int numberOfEvents, int numberOfCabs, int numberOfAutoUnmanagedAndManagedScripts, int numberOfManualUnmanagedAndManagedScripts, bool useUnmanagedCabs, int numberOfAutoManagedScripts, int numberOfManualManagedScripts, int numberOfAutoUnmanagedScripts, int numberOfManualUnmanagedScripts) { int numberOfEventInfos = 1; // Use the dummy winqual. StackHashTestData testData = new StackHashTestData(); testData.DummyWinQualSettings = new StackHashTestDummyWinQualSettings(); testData.DummyWinQualSettings.UseDummyWinQual = true; testData.DummyWinQualSettings.ObjectsToCreate = new StackHashTestIndexData(); testData.DummyWinQualSettings.ObjectsToCreate.UseLargeCab = false; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfProducts = numberOfProducts; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfFiles = numberOfFiles; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEvents = numberOfEvents; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEventInfos = numberOfEventInfos; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfCabs = numberOfCabs; testData.DummyWinQualSettings.ObjectsToCreate.UseUnmanagedCab = useUnmanagedCabs; m_Utils.SetTestData(testData); m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateNewContext(indexType); // Set the username and password to something valid. GetStackHashPropertiesResponse settings = m_Utils.GetContextSettings(); String testPath = "c:\\stackhashunittest\\testindex\\"; settings.Settings.ContextCollection[0].ErrorIndexSettings.Folder = testPath; settings.Settings.ContextCollection[0].ErrorIndexSettings.Name = "TestIndex"; settings.Settings.ContextCollection[0].WinQualSettings.UserName = m_UserName; settings.Settings.ContextCollection[0].WinQualSettings.Password = m_Password; m_Utils.SetContextSettings(settings.Settings.ContextCollection[0]); // Make sure the index starts off empty. m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); for (int i = 0; i < numberOfAutoUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i, true, StackHashScriptDumpType.UnmanagedAndManaged, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 100, true, StackHashScriptDumpType.UnmanagedAndManaged, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 200, true, StackHashScriptDumpType.ManagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 300, true, StackHashScriptDumpType.ManagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 400, true, StackHashScriptDumpType.UnmanagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 500, true, StackHashScriptDumpType.UnmanagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } try { // Synchronize so we have a copy of just the product list. StartSynchronizationResponse resp = m_Utils.StartSynchronization(0, 60000); StackHashClientData clientData = m_Utils.LastClientData; StackHashWinQualSyncCompleteAdminReport adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(numberOfProducts, adminReport.ErrorIndexStatistics.Products); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.EventInfos); // Enable sync for all the products. GetProductsResponse getProducts = m_Utils.GetProducts(0); foreach (StackHashProductInfo productInfo in getProducts.Products) { Assert.AreEqual(false, productInfo.SynchronizeEnabled); m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true); // Make sure there are no files for this product yet. GetFilesResponse getFiles = m_Utils.GetFiles(0, productInfo.Product); Assert.AreEqual(0, getFiles.Files.Count); } // Start the sync and wait for the sync and analyze to complete. resp = m_Utils.StartSynchronization(0, 120000, false, false, null); clientData = m_Utils.LastClientData; adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Products); // Should have already added the product. Assert.AreEqual(numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(numberOfCabs * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(numberOfEventInfos * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.EventInfos); // Make sure the task is no longer running. GetStackHashServiceStatusResponse statusResp = m_Utils.GetServiceStatus(); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.WinQualSynchronizeTask)); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.AnalyzeTask)); // Check that the scripts have been run ok. Both auto scripts should be run. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { StackHashFileCollection files = m_Utils.GetFiles(0, product.Product).Files; foreach (StackHashFile file in files) { StackHashEventCollection events = m_Utils.GetEvents(0, product.Product, file).Events; foreach (StackHashEvent currentEvent in events) { StackHashEventPackage eventPackage = m_Utils.GetEventPackage(0, product.Product, file, currentEvent).EventPackage; foreach (StackHashCabPackage cab in eventPackage.Cabs) { StackHashScriptResultFiles scriptResults = m_Utils.GetDebugResultFiles(0, product.Product, file, currentEvent, cab.Cab).ResultFiles; int numberOfAutoScripts = 2; int expectedResults = numberOfAutoScripts + numberOfAutoUnmanagedAndManagedScripts; if (!useUnmanagedCabs) { expectedResults += numberOfAutoManagedScripts; } else { expectedResults += numberOfAutoUnmanagedScripts; } Assert.AreEqual(expectedResults, scriptResults.Count); } } } } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(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); }
// // 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 /// <summary> /// Add n event notes /// </summary> public void getPackages(int numProducts, int numFiles, int numEvents, int numEventInfos, int numCabs, bool useSameLocale, bool incrementingEventId, bool randomEventIds) { int cabId = 1000; int eventId = 1320080390; int fileId = 0x12345678; int productId = 122; Random rand = new Random(100); m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); Dictionary <int, StackHashEventPackageCollection> expectedProductEvents = new Dictionary <int, StackHashEventPackageCollection>(); StackHashProductCollection allProducts = new StackHashProductCollection(); for (int productCount = 0; productCount < numProducts; productCount++) { DateTime creationDateTime = new DateTime(2010, 04, 04, 22, 9, 0, DateTimeKind.Utc); DateTime modifiedDateTime = new DateTime(2010, 05, 05, 23, 10, 0, DateTimeKind.Utc); StackHashProduct product1 = new StackHashProduct(creationDateTime, modifiedDateTime, null, productId++, "TestProduct1", 20, 30, "2.10.02123.1293"); m_Index.AddProduct(product1); allProducts.Add(product1); StackHashEventPackageCollection allAddedEvents = new StackHashEventPackageCollection(); for (int fileCount = 0; fileCount < numFiles; fileCount++) { StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, fileId++, creationDateTime, "File1.dll", "2.3.4.5"); StackHashEventSignature eventSignature = new StackHashEventSignature(); eventSignature.Parameters = new StackHashParameterCollection(); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationName, "AppName")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationVersion, "1.2.3.4")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamApplicationTimeStamp, creationDateTime.ToString())); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleName, "ModuleName")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleVersion, "2.3.4.5")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamModuleTimeStamp, creationDateTime.ToString())); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamExceptionCode, "1234")); eventSignature.Parameters.Add(new StackHashParameter(StackHashEventSignature.ParamOffset, "0x1234")); eventSignature.InterpretParameters(); m_Index.AddFile(product1, file1); for (int eventCount = 0; eventCount < numEvents; eventCount++) { StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", eventId, eventSignature, eventCount, file1.Id, "bug" + eventCount.ToString()); if (randomEventIds) { eventId = rand.Next(100, 1320080390); } else { if (incrementingEventId) { eventId++; } else { eventId--; } } m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); int hitCount = 1; int totalHits = 0; for (int i = 0; i < numEventInfos; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = 10; if (!useSameLocale) { localeId += i; } totalHits += hitCount; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i * 1), date.AddDays(i * 2), date.AddDays(i * 3), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", hitCount++); eventInfos.Add(eventInfo); } event1.TotalHits = totalHits; m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashCabCollection cabs = new StackHashCabCollection(); for (int i = 0; i < numCabs; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); StackHashCab cab = new StackHashCab(date.AddDays(i * 1), date.AddDays(i * 2), event1.Id, event1.EventTypeName, "cab12345_23232.cab", cabId++, i * 2000); cab.DumpAnalysis = new StackHashDumpAnalysis("2 days, 5 hours, 2 mins", "1 hour, 2 mins", "2.120.222.1121212", "Microsoft Windows Vista X64 6.0.212121212 (Build 2500)", "64 bit windows"); cab.CabDownloaded = false; cabs.Add(cab); m_Index.AddCab(product1, file1, event1, cab, true); } allAddedEvents.Add(new StackHashEventPackage(eventInfos, new StackHashCabPackageCollection(cabs), event1, product1.Id)); } } expectedProductEvents[product1.Id] = allAddedEvents; } foreach (StackHashProduct product in allProducts) { StackHashEventPackageCollection allEvents = m_Index.GetProductEvents(product); StackHashEventPackageCollection expectedEvents = expectedProductEvents[product.Id]; Assert.AreNotEqual(null, allEvents); Assert.AreEqual(expectedEvents.Count, allEvents.Count); foreach (StackHashEventPackage package in allEvents) { StackHashEventPackage matchedEvent = expectedEvents.FindEventPackage(package.EventData.Id, package.EventData.EventTypeName); Assert.AreNotEqual(null, matchedEvent); Assert.AreEqual(0, package.EventInfoList.CompareTo(matchedEvent.EventInfoList)); Assert.AreEqual(0, package.Cabs.CompareTo(matchedEvent.Cabs)); } } }
/// <summary> /// Processes a specific event. /// </summary> private void processEventPackage(StackHashBugReportData request, StackHashProduct product, StackHashFile file, StackHashEventPackage eventPackage) { if (this.CurrentTaskState.AbortRequested) { throw new OperationCanceledException("Reporting events to Bug Tracker plug-ins"); } StackHashEvent theEvent = eventPackage.EventData; BugTrackerProduct btProduct = new BugTrackerProduct(product.Name, product.Version, product.Id); BugTrackerFile btFile = new BugTrackerFile(file.Name, file.Version, file.Id); NameValueCollection eventSignature = new NameValueCollection(); foreach (StackHashParameter param in theEvent.EventSignature.Parameters) { eventSignature.Add(param.Name, param.Value); } BugTrackerEvent btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); if (((request.Options & StackHashReportOptions.IncludeEvents) != 0) || ((request.Options & StackHashReportOptions.IncludeAllObjects) != 0)) { String newBugId = m_TaskParameters.PlugInContext.EventAdded(m_PlugIns, m_ReportType, btProduct, btFile, btEvent); checkPlugInStatus(m_PlugIns); theEvent = setPlugInBugReference(product, file, theEvent, newBugId); // Reset this in case it has changed. btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); } if (((request.Options & StackHashReportOptions.IncludeEventNotes) != 0) || ((request.Options & StackHashReportOptions.IncludeAllObjects) != 0)) { StackHashNotes notes = m_Index.GetEventNotes(product, file, theEvent); foreach (StackHashNoteEntry note in notes) { if (this.CurrentTaskState.AbortRequested) { throw new OperationCanceledException("Reporting events to Bug Tracker plug-ins"); } BugTrackerNote btEventNote = new BugTrackerNote(note.TimeOfEntry, note.Source, note.User, note.Note); String newBugId = m_TaskParameters.PlugInContext.EventNoteAdded(m_PlugIns, m_ReportType, btProduct, btFile, btEvent, btEventNote); checkPlugInStatus(m_PlugIns); theEvent = setPlugInBugReference(product, file, theEvent, newBugId); // Reset this in case it has changed. btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); } } if (request.Cab == null) { foreach (StackHashCabPackage cab in eventPackage.Cabs) { processCab(request, product, file, theEvent, cab.Cab, btProduct, btFile, btEvent); // Reset this in case it has changed. btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); } } else { StackHashCab cab = m_Index.GetCab(product, file, theEvent, request.Cab.Id); if (cab != null) { theEvent = processCab(request, product, file, theEvent, cab, btProduct, btFile, btEvent); // Reset this in case it has changed. btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); } } // Signal the completion of this event. if (((request.Options & StackHashReportOptions.IncludeEvents) != 0) || ((request.Options & StackHashReportOptions.IncludeAllObjects) != 0)) { String newBugId = m_TaskParameters.PlugInContext.EventManualUpdateCompleted(m_PlugIns, m_ReportType, btProduct, btFile, btEvent); checkPlugInStatus(m_PlugIns); theEvent = setPlugInBugReference(product, file, theEvent, newBugId); // Reset this in case it has changed. btEvent = new BugTrackerEvent(theEvent.BugId, theEvent.PlugInBugId, theEvent.Id, theEvent.EventTypeName, theEvent.TotalHits, eventSignature); } m_CurrentEvent++; reportProgress(m_CurrentEvent, m_TotalEvents, eventPackage.EventData.Id); }
public void UpdateEventPackage(StackHashEventPackage stackHashEventPackage, Dictionary <int, DisplayMapping> workFlowLookup) { if (stackHashEventPackage == null) { throw new ArgumentNullException("stackHashEventPackage"); } if (workFlowLookup == null) { throw new ArgumentNullException("workFlowLookup"); } if (stackHashEventPackage.EventData == null) { throw new ArgumentNullException("stackHashEventPackage", "stackHashEventPackage.EventData is null"); } if (stackHashEventPackage.EventData.EventSignature == null) { throw new ArgumentNullException("stackHashEventPackage", "stackHashEventPackage.EventData.EventSignature is null"); } if (stackHashEventPackage.EventData.Id != _stackHashEventPackage.EventData.Id) { throw new InvalidOperationException("Cannot update from an event pacakge with a different ID"); } // save the new event package StackHashEventPackage oldStackHashEventPackage = _stackHashEventPackage; _stackHashEventPackage = stackHashEventPackage; // update WorkFlowDisplayMapping this.WorkFlowDisplayMapping = workFlowLookup[stackHashEventPackage.EventData.WorkFlowStatus]; // check for changes if (oldStackHashEventPackage.ProductId != _stackHashEventPackage.ProductId) { RaisePropertyChanged("ProductId"); } if (oldStackHashEventPackage.EventData.BugId != _stackHashEventPackage.EventData.BugId) { RaisePropertyChanged("BugId"); } if (oldStackHashEventPackage.EventData.DateCreatedLocal != _stackHashEventPackage.EventData.DateCreatedLocal) { RaisePropertyChanged("DateCreatedLocal"); } if (oldStackHashEventPackage.EventData.DateModifiedLocal != _stackHashEventPackage.EventData.DateModifiedLocal) { RaisePropertyChanged("DateModifiedLocal"); } if (oldStackHashEventPackage.EventData.EventTypeName != _stackHashEventPackage.EventData.EventTypeName) { RaisePropertyChanged("EventTypeName"); } if (oldStackHashEventPackage.EventData.FileId != _stackHashEventPackage.EventData.FileId) { RaisePropertyChanged("FileId"); } if (oldStackHashEventPackage.EventData.TotalHits != _stackHashEventPackage.EventData.TotalHits) { RaisePropertyChanged("TotalHits"); } if (oldStackHashEventPackage.EventData.CabCount != _stackHashEventPackage.EventData.CabCount) { RaisePropertyChanged("CabCount"); } if (oldStackHashEventPackage.EventData.PlugInBugId != _stackHashEventPackage.EventData.PlugInBugId) { RaisePropertyChanged("PlugInBugId"); } if (oldStackHashEventPackage.EventData.EventSignature.ApplicationName != _stackHashEventPackage.EventData.EventSignature.ApplicationName) { RaisePropertyChanged("ApplicationName"); } if (oldStackHashEventPackage.EventData.EventSignature.ApplicationTimeStamp != _stackHashEventPackage.EventData.EventSignature.ApplicationTimeStamp) { RaisePropertyChanged("ApplicationTimeStamp"); } if (oldStackHashEventPackage.EventData.EventSignature.ApplicationVersion != _stackHashEventPackage.EventData.EventSignature.ApplicationVersion) { RaisePropertyChanged("ApplicationVersion"); } if (oldStackHashEventPackage.EventData.EventSignature.ExceptionCode != _stackHashEventPackage.EventData.EventSignature.ExceptionCode) { RaisePropertyChanged("ExceptionCode"); } if (oldStackHashEventPackage.EventData.EventSignature.ModuleName != _stackHashEventPackage.EventData.EventSignature.ModuleName) { RaisePropertyChanged("ModuleName"); } if (oldStackHashEventPackage.EventData.EventSignature.ModuleTimeStamp != _stackHashEventPackage.EventData.EventSignature.ModuleTimeStamp) { RaisePropertyChanged("ModuleTimeStamp"); } if (oldStackHashEventPackage.EventData.EventSignature.ModuleVersion != _stackHashEventPackage.EventData.EventSignature.ModuleVersion) { RaisePropertyChanged("ModuleVersion"); } if (oldStackHashEventPackage.EventData.EventSignature.Offset != _stackHashEventPackage.EventData.EventSignature.Offset) { RaisePropertyChanged("Offset"); } // update the exception message UpdateExceptionMessage(); // update cabs if (_stackHashEventPackage.Cabs == null) { _cabs.Clear(); } else { bool cabFound = false; // update / add cabs foreach (StackHashCabPackage cab in _stackHashEventPackage.Cabs) { cabFound = false; foreach (DisplayCab displayCab in _cabs) { if (cab.Cab.Id == displayCab.Id) { cabFound = true; displayCab.UpdateCab(cab); break; } } if (!cabFound) { _cabs.Add(new DisplayCab(cab)); } } // remove cabs no longer preset List <DisplayCab> displayCabsToRemove = new List <DisplayCab>(); foreach (DisplayCab displayCab in _cabs) { cabFound = false; foreach (StackHashCabPackage cab in _stackHashEventPackage.Cabs) { if (cab.Cab.Id == displayCab.Id) { cabFound = true; break; } } if (!cabFound) { displayCabsToRemove.Add(displayCab); } } foreach (DisplayCab displayCab in displayCabsToRemove) { _cabs.Remove(displayCab); } } // update event infos if (_stackHashEventPackage.EventInfoList == null) { _eventInfoList.Clear(); } else { bool eventInfoFound = false; // update / add event infos foreach (StackHashEventInfo eventInfo in _stackHashEventPackage.EventInfoList) { eventInfoFound = false; foreach (DisplayEventInfo displayEventInfo in _eventInfoList) { if (displayEventInfo.IsMatchingEventInfo(eventInfo)) { eventInfoFound = true; displayEventInfo.UpdateEventInfo(eventInfo); break; } } if (!eventInfoFound) { _eventInfoList.Add(new DisplayEventInfo(eventInfo)); } } // remove event infos no longer present List <DisplayEventInfo> displayEventInfosToRemove = new List <DisplayEventInfo>(); foreach (DisplayEventInfo displayEventInfo in _eventInfoList) { eventInfoFound = false; foreach (StackHashEventInfo eventInfo in _stackHashEventPackage.EventInfoList) { if (displayEventInfo.IsMatchingEventInfo(eventInfo)) { eventInfoFound = true; break; } } if (!eventInfoFound) { displayEventInfosToRemove.Add(displayEventInfo); } } foreach (DisplayEventInfo displayEventInfo in displayEventInfosToRemove) { _eventInfoList.Remove(displayEventInfo); } } }