public void NormalizeListDuplicatesSameDifferentTimeZone() { DateTime testTime1 = new DateTime(2010, 10, 24, 16, 0, 0, DateTimeKind.Utc); DateTime expectedTime1 = new DateTime(2010, 10, 25, 0, 0, 0, DateTimeKind.Utc); StackHashEventInfo eventInfo1 = new StackHashEventInfo(testTime1, testTime1, testTime1, "English", 123, "EN-US", "Vista", "6.0.0.0", 10); DateTime testTime2 = new DateTime(2010, 10, 24, 15, 0, 0, DateTimeKind.Utc); DateTime expectedTime2 = new DateTime(2010, 10, 25, 0, 0, 0, DateTimeKind.Utc); StackHashEventInfo eventInfo2 = new StackHashEventInfo(testTime2, testTime2, testTime2, "English", 123, "EN-US", "Vista", "6.0.0.0", 10); DateTime testTime3 = new DateTime(2010, 10, 24, 23, 0, 0, DateTimeKind.Utc); DateTime expectedTime3 = new DateTime(2010, 10, 25, 0, 0, 0, DateTimeKind.Utc); StackHashEventInfo eventInfo3 = new StackHashEventInfo(testTime3, testTime3, testTime3, "English", 123, "EN-US", "Vista", "6.0.0.0", 10); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); eventInfos.Add(eventInfo1); eventInfos.Add(eventInfo2); eventInfos.Add(eventInfo3); StackHashEventInfoCollection normalizedEventInfos = eventInfos.Normalize(); Assert.AreEqual(1, normalizedEventInfos.Count); eventInfo1.HitDateLocal = expectedTime1; eventInfo1.TotalHits += eventInfo2.TotalHits + eventInfo3.TotalHits; Assert.AreEqual(0, eventInfos[0].CompareTo(normalizedEventInfos[0])); }
public static StackHashEventInfoCollection GetEventInfoApi(ref Login login, Event theEvent) { EventInfoCollection eventInfos = theEvent.GetEventDetails(ref login); StackHashEventInfoCollection apiStackHashEventInfos = new StackHashEventInfoCollection(); foreach (EventInfo eventInfo in eventInfos) { StackHashEventInfo stackHashEventInfo = ObjectConversion.ConvertEventInfo(eventInfo); apiStackHashEventInfos.Add(stackHashEventInfo); } return(apiStackHashEventInfos); }
public void NormalizeListNoDuplicates() { DateTime testTime1 = new DateTime(2010, 10, 24, 16, 0, 0, DateTimeKind.Utc); DateTime expectedTime1 = new DateTime(2010, 10, 25, 0, 0, 0, DateTimeKind.Utc); StackHashEventInfo eventInfo1 = new StackHashEventInfo(testTime1, testTime1, testTime1, "English", 123, "EN-US", "Vista", "6.0.0.0", 10); DateTime testTime2 = new DateTime(2010, 10, 25, 16, 0, 0, DateTimeKind.Utc); DateTime expectedTime2 = new DateTime(2010, 10, 26, 0, 0, 0, DateTimeKind.Utc); StackHashEventInfo eventInfo2 = new StackHashEventInfo(testTime2, testTime2, testTime2, "English", 123, "EN-US", "Vista", "6.0.0.0", 10); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); eventInfos.Add(eventInfo1); eventInfos.Add(eventInfo2); StackHashEventInfoCollection normalizedEventInfos = eventInfos.Normalize(); eventInfo1.HitDateLocal = expectedTime1; eventInfo2.HitDateLocal = expectedTime2; Assert.AreEqual(0, eventInfos.CompareTo(normalizedEventInfos)); }
public static StackHashEventInfoCollection GetEventInfoAtom(AtomFeed feed, AtomEvent theEvent, int days) { // Get the list of events. AtomEventInfoCollection atomEventInfos = feed.GetEventDetails(theEvent, days); // Convert to a StackHashEventInfoCollection. StackHashEventInfoCollection atomStackHashEventInfos = new StackHashEventInfoCollection(); foreach (AtomEventInfo atomEventInfo in atomEventInfos) { atomStackHashEventInfos.Add(atomEventInfo.EventInfo); } return(atomStackHashEventInfos); }
private void testAddNEventInfo(IErrorIndex index, int numEventInfos) { index.Activate(); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4"); StackHashParameterCollection parameters = new StackHashParameterCollection(); parameters.Add(new StackHashParameter("param1", "param1value")); parameters.Add(new StackHashParameter("param2", "param2value")); StackHashEventSignature signature = new StackHashEventSignature(parameters); StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, -1, 2); index.AddProduct(product); index.AddFile(product, file); index.AddEvent(product, file, theEvent); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); int totalHits = 0; for (int i = 0; i < numEventInfos; i++) { int hitsForThisEvent = (i + 1); totalHits += hitsForThisEvent; StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(i).ToUniversalTime(), DateTime.Now.AddDays(i + 1).ToUniversalTime(), DateTime.Now.AddDays(i + 2).ToUniversalTime(), "English" + i.ToString(), i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), hitsForThisEvent); eventInfoCollection.Add(eventInfo); } index.AddEventInfoCollection(product, file, theEvent, eventInfoCollection); // Now get all the event info and make sure it all matches. StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent); Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2)); StackHashEventPackageCollection eventPackages = index.GetProductEvents(product); Assert.AreEqual(1, eventPackages.Count); Assert.AreEqual(totalHits, eventPackages[0].EventData.TotalHits); }
private void testAddNEventInfoReloadCache(IErrorIndex realIndex, int numEventInfos) { ErrorIndexCache index = new ErrorIndexCache(realIndex); index.Activate(); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4"); StackHashParameterCollection parameters = new StackHashParameterCollection(); parameters.Add(new StackHashParameter("param1", "param1value")); parameters.Add(new StackHashParameter("param2", "param2value")); StackHashEventSignature signature = new StackHashEventSignature(parameters); StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, 99, 2); index.AddProduct(product); index.AddFile(product, file); index.AddEvent(product, file, theEvent); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int i = 0; i < numEventInfos; i++) { StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(i), DateTime.Now.AddDays(i + 1), DateTime.Now.AddDays(i + 2), "English" + i.ToString(), i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), i * 10); eventInfoCollection.Add(eventInfo); } index.AddEventInfoCollection(product, file, theEvent, eventInfoCollection); // Now reconnect a cache to make sure that the data has been stored ok. index = new ErrorIndexCache(realIndex); index.Activate(); // Now get all the event info and make sure it all matches. StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent); Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2)); }
/// <summary> /// Starts a sync to download products, files, events, event infos and cabs. /// Data is added to the specified error index according to the directions specified /// in the testdata passed into the constructor. /// </summary> /// <param name="errorIndex">The index to add the new data to.</param> /// <param name="forceResynchronize">True - forces a resync of every event that is available. False - sync new events only.</param> /// <param name="lastProgress">Point at which the last sync attempt reached.</param> public void SynchronizeWithWinQualOnline(StackHashErrorIndex.IErrorIndex errorIndex, bool forceResynchronize, StackHashSyncProgress lastProgress) { if (errorIndex == null) { throw new ArgumentNullException("errorIndex"); } int fileId = 1; int eventId = 1; int cabId = 1; m_SyncProgress = new StackHashSyncProgress(); m_AbortRequested = false; onProgress(WinQualProgressType.DownloadingProductList, null); m_SyncProgress.SyncPhase = StackHashSyncPhase.ProductsOnly; errorIndex.SetLastSyncTimeLocal(-2, DateTime.Now.AddDays(-14)); for (int i = 0; i < m_TestSettings.ObjectsToCreate.NumberOfProducts; i++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } StackHashProduct product = new StackHashProduct(); product.DateCreatedLocal = DateTime.Now.ToUniversalTime(); product.DateModifiedLocal = product.DateCreatedLocal; product.FilesLink = "http://www.cucku.com"; product.Id = i + 1; product.Name = "Product" + (i + 1).ToString(CultureInfo.InvariantCulture); product.TotalEvents = i; product.TotalResponses = i; product.Version = "1.2.3." + i.ToString(CultureInfo.InvariantCulture); if (!errorIndex.ProductExists(product)) { if (m_EnableNewProductsAutomatically) { m_ProductsToSynchronize.Add(new StackHashProductSyncData(product.Id)); } errorIndex.AddProduct(product); } } onProgress(WinQualProgressType.ProductListUpdated, null); DateTime eventInfoDate = DateTime.Now.Date; if (m_TestSettings.FailSync) { throw new StackHashException("Test sync failure", StackHashServiceErrorCode.SqlConnectionError); } m_SyncProgress.SyncPhase = StackHashSyncPhase.EventInfosAndCabs; for (int i = 0; i < m_TestSettings.ObjectsToCreate.NumberOfProducts; i++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } DateTime productSyncStartTime = DateTime.Now; StackHashProduct product = new StackHashProduct(); product.DateCreatedLocal = DateTime.Now.ToUniversalTime(); product.DateModifiedLocal = product.DateCreatedLocal; product.FilesLink = "http://www.cucku.com"; product.Id = i + 1; product.Name = "Product" + (i + 1).ToString(CultureInfo.InvariantCulture); product.TotalEvents = i; product.TotalResponses = i; product.Version = "1.2.3." + i.ToString(CultureInfo.InvariantCulture); m_SyncProgress.ProductId = product.Id; errorIndex.AddProduct(product); if (isExcludedProduct(product.Id)) { continue; } if (m_TestSettings.ObjectsToCreate.DuplicateFileIdsAcrossProducts) { eventId = 1; cabId = 1; } for (int j = 0; j < m_TestSettings.ObjectsToCreate.NumberOfFiles; j++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } StackHashFile file = new StackHashFile(); file.DateCreatedLocal = DateTime.Now.ToUniversalTime(); file.DateModifiedLocal = DateTime.Now.ToUniversalTime(); file.Id = fileId; file.LinkDateLocal = DateTime.Now.ToUniversalTime(); file.Name = "File" + fileId.ToString(CultureInfo.InvariantCulture); file.Version = "1.2.3." + fileId.ToString(CultureInfo.InvariantCulture); m_SyncProgress.FileId = file.Id; errorIndex.AddFile(product, file); fileId++; onProgress(WinQualProgressType.DownloadingProductEvents, product, null, null, null, 0, 0, productSyncStartTime, new DateTime(0), errorIndex.GetLastSyncTimeLocal(product.Id)); onProgress(WinQualProgressType.DownloadingProductCabs, product, null, null, null, 0, 0, productSyncStartTime, new DateTime(0), errorIndex.GetLastSyncTimeLocal(product.Id)); for (int k = 0; k < m_TestSettings.ObjectsToCreate.NumberOfEvents; k++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } if (errorIndex.TotalStoredEvents >= m_MaxEvents) { break; } StackHashEvent theEvent = new StackHashEvent(); theEvent.DateCreatedLocal = DateTime.Now.ToUniversalTime(); theEvent.DateModifiedLocal = theEvent.DateCreatedLocal; theEvent.EventTypeName = "CLR"; theEvent.FileId = fileId; theEvent.Id = eventId++; theEvent.EventSignature = new StackHashEventSignature(); theEvent.EventSignature.ApplicationName = "AppName"; theEvent.EventSignature.ApplicationTimeStamp = DateTime.Now.ToUniversalTime(); theEvent.EventSignature.ApplicationVersion = "1.2.3.4"; theEvent.EventSignature.ExceptionCode = 123; theEvent.EventSignature.ModuleName = "ModuleName"; theEvent.EventSignature.ModuleTimeStamp = DateTime.Now.ToUniversalTime(); theEvent.EventSignature.ModuleVersion = "4.3.2.1"; theEvent.EventSignature.Offset = 12; theEvent.EventSignature.Parameters = new StackHashParameterCollection(); theEvent.EventSignature.Parameters.Add(new StackHashParameter("Param", "Value")); if (m_TestSettings.ObjectsToCreate.SetBugId) { theEvent.BugId = "BugId" + theEvent.Id.ToString(CultureInfo.InvariantCulture); theEvent.PlugInBugId = "PlugInOriginalId" + theEvent.Id.ToString(CultureInfo.InvariantCulture); } errorIndex.AddEvent(product, file, theEvent); m_SyncProgress.EventId = theEvent.Id; m_SyncProgress.EventTypeName = theEvent.EventTypeName; StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int l = 0; l < m_TestSettings.ObjectsToCreate.NumberOfEventInfos; l++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } StackHashEventInfo eventInfo = new StackHashEventInfo(); eventInfo.DateCreatedLocal = DateTime.Now.ToUniversalTime(); eventInfo.DateModifiedLocal = DateTime.Now.ToUniversalTime(); eventInfo.HitDateLocal = eventInfoDate; eventInfo.Language = "lang"; eventInfo.Lcid = 234; eventInfo.Locale = "locale"; eventInfo.OperatingSystemName = "XP"; eventInfo.OperatingSystemVersion = "SP2"; eventInfo.TotalHits = l; eventInfoCollection.Add(eventInfo); eventInfoDate.AddDays(1); } errorIndex.AddEventInfoCollection(product, file, theEvent, eventInfoCollection); for (int m = 0; m < m_TestSettings.ObjectsToCreate.NumberOfCabs; m++) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } StackHashCab cab = new StackHashCab(); cab.DateCreatedLocal = DateTime.Now.ToUniversalTime(); cab.DateModifiedLocal = DateTime.Now.ToUniversalTime(); cab.EventId = theEvent.Id; cab.EventTypeName = theEvent.EventTypeName; cab.FileName = "cab" + cabId.ToString(CultureInfo.InvariantCulture) + ".cab"; cab.Id = cabId++; cab.SizeInBytes = 100; errorIndex.AddCab(product, file, theEvent, cab, false); m_SyncProgress.CabId = cab.Id; // Copy in a test cab file. String cabFolder = errorIndex.GetCabFolder(product, file, theEvent, cab); if (!Directory.Exists(cabFolder)) { Directory.CreateDirectory(cabFolder); } String cabFileName = errorIndex.GetCabFileName(product, file, theEvent, cab); if (!File.Exists(cabFileName)) { if (m_TestSettings.ObjectsToCreate.UseUnmanagedCab) { File.Copy(TestSettings.TestDataFolder + @"Cabs\1629290733-SpecialException-1073810027.cab", cabFileName); } else if (m_TestSettings.ObjectsToCreate.UseLargeCab) { File.Copy(TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName); } else { File.Copy(TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName); } } // Make sure the file is not read only. FileAttributes attributes = File.GetAttributes(cabFileName); attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(cabFileName, attributes); } } onProgress(WinQualProgressType.ProductCabsUpdated, product, null, null, null, 0, 0, productSyncStartTime, DateTime.Now, errorIndex.GetLastSyncTimeLocal(product.Id)); onProgress(WinQualProgressType.ProductEventsUpdated, product, null, null, null, 0, 0, productSyncStartTime, DateTime.Now, errorIndex.GetLastSyncTimeLocal(product.Id)); } errorIndex.UpdateProductStatistics(product); errorIndex.SetLastSyncTimeLocal(product.Id, productSyncStartTime); errorIndex.SetLastSyncCompletedTimeLocal(product.Id, DateTime.Now); } onProgress(WinQualProgressType.Complete); }
// // 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)); } } }
public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData, bool includeDuplicates) { if (testData.EventsToAssignCabs == 0) { testData.EventsToAssignCabs = 1; } Random rand = new Random(1); Random scriptRand = new Random(1); if (index == null) { throw new ArgumentNullException("index"); } if (testData == null) { throw new ArgumentNullException("testData"); } DateTime now = DateTime.Now; int fileId = 1; int eventId = 1; int cabId = 1; int productId = 1; int offset = 10000; if (!s_IsTestMode) { productId = 26214; fileId = 1035620; eventId = 1099309964; cabId = 939529168; } int initialFileId = fileId; int initialEventId = eventId; int initialCabId = cabId; int initialOffset = offset; int totalEventsPerProduct = testData.NumberOfFiles * testData.NumberOfEvents; index.SetLastSyncTimeLocal(-2, DateTime.Now.AddDays(-14)); for (int i = 0; i < testData.NumberOfProducts; i++) { StackHashProduct product = new StackHashProduct(); product.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); product.DateModifiedLocal = product.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); product.FilesLink = "http://www.cucku.com"; product.Id = productId; product.Name = "StackHash" + productId.ToString(CultureInfo.InvariantCulture); product.TotalEvents = totalEventsPerProduct; product.TotalResponses = 1; product.Version = "1.2.3." + productId.ToString(CultureInfo.InvariantCulture); index.AddProduct(product); productId++; if (includeDuplicates) { fileId = initialFileId; eventId = initialEventId; cabId = initialCabId; offset = initialOffset; rand = new Random(1); } for (int j = 0; j < testData.NumberOfFiles; j++) { StackHashFile file = new StackHashFile(); file.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); file.DateModifiedLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); file.Id = fileId++; file.LinkDateLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); int fileIndex = rand.Next() % s_FileNames.Length; file.Name = String.Format(CultureInfo.InvariantCulture, "{0}.{1}", s_FileNames[fileIndex], "dll"); file.Version = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", fileId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (j + 1) * 1237); index.AddFile(product, file); for (int k = 0; k < testData.NumberOfEvents; k++) { int totalHits = 0; Random hitsRand = new Random(k); for (int l = 0; l < testData.NumberOfEventInfos; l++) { if (s_IsTestMode) { totalHits += (l + k); } else { totalHits += hitsRand.Next(0, 50); } } StackHashEvent theEvent = new StackHashEvent(); theEvent.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); theEvent.DateModifiedLocal = theEvent.DateCreatedLocal.AddDays(rand.Next(-10, 10)).RoundToPreviousMinute(); theEvent.EventTypeName = s_EventTypes[rand.Next(0, s_EventTypes.Length)]; theEvent.FileId = file.Id; theEvent.Id = eventId; theEvent.BugId = "Bug" + eventId.ToString(CultureInfo.InvariantCulture); theEvent.TotalHits = totalHits; theEvent.EventSignature = new StackHashEventSignature(); theEvent.EventSignature.ApplicationName = "StackHash.exe"; theEvent.EventSignature.ApplicationTimeStamp = now.ToUniversalTime().AddDays(rand.Next(-180, 0)); theEvent.EventSignature.ApplicationVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234); theEvent.EventSignature.ExceptionCode = 0xc0000000 + rand.Next(0, 16); theEvent.EventSignature.ModuleName = "Module" + k.ToString(CultureInfo.InvariantCulture); theEvent.EventSignature.ModuleTimeStamp = now.ToUniversalTime().AddDays(-1 * ((rand.Next() % 200))); theEvent.EventSignature.ModuleVersion = String.Format(CultureInfo.InvariantCulture, "{0}.{1}.{2}{3}.{4}", eventId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (Math.Abs(eventId) + 1) * 1234); if (s_IsTestMode) { theEvent.EventSignature.Offset = offset--; // Make these go backwards. } else { theEvent.EventSignature.Offset = rand.Next(0, 0xfffff); } theEvent.EventSignature.Parameters = new StackHashParameterCollection(); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationName", theEvent.EventSignature.ApplicationName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationTimeStamp", theEvent.EventSignature.ApplicationTimeStamp.ToString(CultureInfo.InvariantCulture))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationVersion", theEvent.EventSignature.ApplicationVersion)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("exceptionCode", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.ExceptionCode))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleName", theEvent.EventSignature.ModuleName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleTimeStamp", theEvent.EventSignature.ModuleTimeStamp.ToString(CultureInfo.InvariantCulture))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleVersion", theEvent.EventSignature.ModuleVersion.ToString())); theEvent.EventSignature.Parameters.Add(new StackHashParameter("offset", String.Format(CultureInfo.InvariantCulture, "{0:X}", theEvent.EventSignature.Offset))); theEvent.EventSignature.InterpretParameters(); index.AddEvent(product, file, theEvent); // Allow for some duplicate event ids. if (!s_IsTestMode) { eventId++; //if (rand.Next(0, 100) > 5) // eventId++; //if (rand.Next(0, 100) > 50) // eventId = -1 * eventId; } else { eventId++; } hitsRand = new Random(k); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int l = 0; l < testData.NumberOfEventInfos; l++) { int languageIndex = rand.Next() % s_Languages.Length; if (s_IsTestMode) { languageIndex = l % s_Languages.Length; } StackHashEventInfo eventInfo = new StackHashEventInfo(); eventInfo.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); eventInfo.DateModifiedLocal = eventInfo.DateCreatedLocal.AddDays(l).RoundToPreviousMinute(); if (s_IsTestMode) { eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(-1 * l).RoundToPreviousMinute(); } else { eventInfo.HitDateLocal = now.ToUniversalTime().AddDays(rand.Next(-180, 0)).RoundToPreviousMinute(); } eventInfo.Language = s_Languages[languageIndex].Name; eventInfo.Lcid = s_Languages[languageIndex].Lcid; eventInfo.Locale = s_Languages[languageIndex].LocaleCode; int osIndex = rand.Next(0, s_OperatingSystems.Length); if (s_IsTestMode) { osIndex = l % s_OperatingSystems.Length; } eventInfo.OperatingSystemName = s_OperatingSystems[osIndex]; if (s_IsTestMode) { eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex] + l.ToString(CultureInfo.InvariantCulture); } else { eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex]; } if (s_IsTestMode) { eventInfo.TotalHits = l + k; } else { eventInfo.TotalHits = hitsRand.Next(0, 50); } if (eventInfoCollection.FindEventInfo(eventInfo) == null) { eventInfoCollection.Add(eventInfo); } } index.MergeEventInfoCollection(product, file, theEvent, eventInfoCollection); for (int m = 0; m < testData.NumberOfCabs; m++) { if ((k % testData.EventsToAssignCabs) != 0) { break; } StackHashCab cab = new StackHashCab(); if (IsTestMode) { cab.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * m).RoundToPreviousMinute(); cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute(); } else { cab.DateCreatedLocal = now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)).RoundToPreviousMinute(); cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m).RoundToPreviousMinute(); } cab.EventId = theEvent.Id; cab.EventTypeName = theEvent.EventTypeName; cab.FileName = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}.cab", cab.EventId, cab.EventTypeName, cab.Id); cab.Id = cabId++; cab.SizeInBytes = 64123 + rand.Next(-4000, 4000); // Some random value - corrected later if a real file exists. cab.CabDownloaded = true; // Get the size of the cab file. String sourceCabFile; if (testData.CabFileName != null) { sourceCabFile = Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName); } else if (testData.UseLargeCab) { sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab"; } else { sourceCabFile = TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab"; } if (File.Exists(sourceCabFile)) { FileInfo sourceCabFileInfo = new FileInfo(sourceCabFile); cab.SizeInBytes = sourceCabFileInfo.Length; } index.AddCab(product, file, theEvent, cab, false); // Copy in a test cab file. String cabFolder = index.GetCabFolder(product, file, theEvent, cab); if (!Directory.Exists(cabFolder)) { Directory.CreateDirectory(cabFolder); } String cabFileName = index.GetCabFileName(product, file, theEvent, cab); if (!File.Exists(cabFileName)) { if (testData.CabFileName != null) { File.Copy(Path.Combine(TestSettings.TestDataFolder + @"Cabs\", testData.CabFileName), cabFileName); } else if (testData.UseLargeCab) { File.Copy(TestSettings.TestDataFolder + @"Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName); } else { File.Copy(TestSettings.TestDataFolder + @"Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName); } } // Make sure the file is not read only. FileAttributes attributes = File.GetAttributes(cabFileName); attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(cabFileName, attributes); // Unwrap the cab. if (testData.UnwrapCabs) { Cabs.ExtractCab(cabFileName, cabFolder); } if (testData.NumberOfScriptResults > 0) { String analysisFolder = index.GetCabFolder(product, file, theEvent, cab) + "\\analysis"; if (!Directory.Exists(analysisFolder)) { Directory.CreateDirectory(analysisFolder); } for (int scriptCount = 0; scriptCount < testData.NumberOfScriptResults; scriptCount++) { CreateScriptFile(scriptCount, cab.Id, analysisFolder, scriptRand.Next(5), CultureInfo.InvariantCulture, 2, testData.ScriptFileSize); } } StackHashNotes cabNotes = index.GetCabNotes(product, file, theEvent, cab); for (int q = 0; q < testData.NumberOfCabNotes; q++) { StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is a cab note" + q.ToString(CultureInfo.InvariantCulture)); // Don't add duplicate cab notes in the SQL index. The XML index may contain duplicates. if (index.IndexType == ErrorIndexType.Xml || !cabNotes.ContainsNote(note)) { index.AddCabNote(product, file, theEvent, cab, note); } } } StackHashNotes eventNotes = index.GetEventNotes(product, file, theEvent); for (int p = 0; p < testData.NumberOfEventNotes; p++) { StackHashNoteEntry note = new StackHashNoteEntry(now.ToUniversalTime().RoundToPreviousSecond(), "User", "MarkJ", "This is an event note" + p.ToString(CultureInfo.InvariantCulture)); // Don't add duplicate event notes in the SQL index. The XML index may contain duplicates. if (index.IndexType == ErrorIndexType.Xml || !eventNotes.ContainsNote(note)) { index.AddEventNote(product, file, theEvent, note); } } } } index.UpdateProductStatistics(product); } }
/// <summary> /// Create the index. /// </summary> /// <param name="index">Sql or xml index.</param> /// <param name="testData">Defines size and type of entries.</param> public static void CreateTestIndex(IErrorIndex index, StackHashTestIndexData testData) { int productId = 26214; int fileId = 1035620; int eventId = 1099309964; int cabId = 939529168; // Randomize some selections. Random rand = new Random(1); int totalEventsPerProduct = testData.NumberOfFiles * testData.NumberOfEvents; for (int i = 0; i < testData.NumberOfProducts; i++) { StackHashProduct product = new StackHashProduct(); product.DateCreatedLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)); product.DateModifiedLocal = product.DateCreatedLocal.AddDays(rand.Next(-10, 10)); product.FilesLink = "http://www.cucku.com"; product.Id = productId++; product.Name = "StackHash"; product.TotalEvents = totalEventsPerProduct; product.TotalResponses = 1; product.Version = String.Format("{0}.{1}.{2}{3}.{4}", i.ToString(CultureInfo.InvariantCulture), rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (i + 1) * 1237); index.AddProduct(product); Console.WriteLine(String.Format("Adding product {0} of {1}", i, testData.NumberOfProducts)); for (int j = 0; j < testData.NumberOfFiles; j++) { StackHashFile file = new StackHashFile(); file.DateCreatedLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)); file.DateModifiedLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)); file.Id = fileId++; file.LinkDateLocal = file.DateCreatedLocal.AddDays(rand.Next(-10, 10)); int fileIndex = rand.Next() % s_FileNames.Length; file.Name = String.Format("{0}.{1}", s_FileNames[fileIndex], "dll"); file.Version = String.Format("{0}.{1}.{2}{3}.{4}", fileId, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (i + 1) * 1237); index.AddFile(product, file); Console.WriteLine(String.Format("Adding File {0} of {1}", j, testData.NumberOfFiles)); for (int k = 0; k < testData.NumberOfEvents; k++) { StackHashEvent theEvent = new StackHashEvent(); theEvent.DateCreatedLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)); theEvent.DateModifiedLocal = theEvent.DateCreatedLocal.AddDays(rand.Next(-10, 10)); // Select a random event type. theEvent.EventTypeName = s_EventTypes[rand.Next(0, s_EventTypes.Length)]; theEvent.FileId = file.Id; theEvent.Id = eventId++; theEvent.EventSignature = new StackHashEventSignature(); theEvent.EventSignature.ApplicationName = "StackHash.exe"; theEvent.EventSignature.ApplicationTimeStamp = DateTime.Now.ToUniversalTime().AddDays(-180); theEvent.EventSignature.ApplicationVersion = String.Format("{0}.{1}.{2}{3}.{4}", rand.Next() % 99, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (eventId + 1) * 1234); theEvent.EventSignature.ExceptionCode = 0xc0000000 + rand.Next(0, 16); theEvent.EventSignature.ModuleName = s_ModuleNames[rand.Next() % s_ModuleNames.Length]; theEvent.EventSignature.ModuleTimeStamp = DateTime.Now.ToUniversalTime().AddDays(-1 * ((rand.Next() % 200))); theEvent.EventSignature.ModuleVersion = String.Format("{0}.{1}.{2}{3}.{4}", rand.Next() % 99, rand.Next() % 99, rand.Next() % 366, rand.Next() % 5 + 2005, (eventId + 1) * 1234); theEvent.EventSignature.Offset = rand.Next(0, 0xfffff); theEvent.EventSignature.Parameters = new StackHashParameterCollection(); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationName", theEvent.EventSignature.ApplicationName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationTimeStamp", theEvent.EventSignature.ApplicationTimeStamp.ToString())); theEvent.EventSignature.Parameters.Add(new StackHashParameter("applicationVersion", theEvent.EventSignature.ApplicationVersion)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("exceptionCode", String.Format("{0:X}", theEvent.EventSignature.ExceptionCode))); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleName", theEvent.EventSignature.ModuleName)); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleTimeStamp", theEvent.EventSignature.ModuleTimeStamp.ToString())); theEvent.EventSignature.Parameters.Add(new StackHashParameter("moduleVersion", theEvent.EventSignature.ModuleVersion.ToString())); theEvent.EventSignature.Parameters.Add(new StackHashParameter("offset", String.Format("{0:X}", theEvent.EventSignature.Offset.ToString()))); index.AddEvent(product, file, theEvent); DateTime startTime = DateTime.Now; Console.WriteLine(String.Format("P:{0} F:{1} Ev {2} of {3}", i, j, k, testData.NumberOfEvents)); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); for (int l = 0; l < testData.NumberOfEventInfos; l++) { int languageIndex = rand.Next() % s_Languages.Length; StackHashEventInfo eventInfo = new StackHashEventInfo(); eventInfo.DateCreatedLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)); eventInfo.DateModifiedLocal = eventInfo.DateCreatedLocal.AddDays(l); eventInfo.HitDateLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * l); eventInfo.Language = s_Languages[languageIndex]; eventInfo.Lcid = s_Lcids[languageIndex]; eventInfo.Locale = "locale"; int osIndex = rand.Next(0, s_OperatingSystems.Length); eventInfo.OperatingSystemName = s_OperatingSystems[osIndex]; eventInfo.OperatingSystemVersion = s_OperatingSystemVersions[osIndex]; eventInfo.TotalHits = l + 1; eventInfoCollection.Add(eventInfo); } index.AddEventInfoCollection(product, file, theEvent, eventInfoCollection); for (int m = 0; m < testData.NumberOfCabs; m++) { StackHashCab cab = new StackHashCab(); cab.DateCreatedLocal = DateTime.Now.ToUniversalTime().AddDays(-1 * (rand.Next() % 180)); cab.DateModifiedLocal = cab.DateCreatedLocal.AddDays(m); cab.EventId = theEvent.Id; cab.EventTypeName = theEvent.EventTypeName; cab.FileName = String.Format(CultureInfo.InvariantCulture, "{0}-{1}-{2}.cab", cab.EventId, cab.EventTypeName, cab.Id); cab.Id = cabId++; cab.SizeInBytes = 64123 + rand.Next(-4000, 4000); index.AddCab(product, file, theEvent, cab, false); // Copy in a test cab file. String cabFolder = index.GetCabFolder(product, file, theEvent, cab); if (!Directory.Exists(cabFolder)) { Directory.CreateDirectory(cabFolder); } String cabFileName = index.GetCabFileName(product, file, theEvent, cab); if (!File.Exists(cabFileName)) { if (testData.CabFileName != null) { File.Copy(Path.Combine(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\Cabs\", testData.CabFileName), cabFileName); } else if (testData.UseLargeCab) { File.Copy(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\Cabs\1630796338-Crash32bit-0760025228.cab", cabFileName); } else { File.Copy(@"R:\stackhash\BusinessLogic\BusinessLogic\TestData\Cabs\1641909485-Crash32bit-0773522646.cab", cabFileName); } } // Make sure the file is not read only. FileAttributes attributes = File.GetAttributes(cabFileName); attributes &= ~FileAttributes.ReadOnly; File.SetAttributes(cabFileName, attributes); } Console.WriteLine(String.Format("Added Event {0} of {1} - Duration: {2}", k, testData.NumberOfEvents, (DateTime.Now - startTime).TotalMilliseconds)); } } } }
public void GetMostRecentHitDateDuplicateEventIds() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); StackHashEvent event2 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName2", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); m_Index.AddEvent(product1, file1, event2); StackHashEventInfoCollection eventInfos1 = new StackHashEventInfoCollection(); int numEventInfos = 3; 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 = i; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i + 2), date.AddDays(i + 1), date.AddDays(i), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", event1.Id); eventInfos1.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos1); StackHashEventInfoCollection eventInfos2 = new StackHashEventInfoCollection(); // Add some other event infos for a different event. 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 = i; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i + 2), date.AddDays(i + 1), date.AddDays(i * 2), "US", localeId, "English", "Windows Vista" + i.ToString(), "1.2.3.4 build 7", event2.Id); eventInfos2.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event2, eventInfos2); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(numEventInfos, eventInfosRetrieved.Count); for (int i = 0; i < numEventInfos; i++) { StackHashEventInfo eventInfo = eventInfosRetrieved.FindEventInfo(eventInfos1[i]); Assert.AreEqual(0, eventInfos1[i].CompareTo(eventInfo)); } DateTime mostRecentHitDate = m_Index.GetMostRecentHitDate(product1, file1, event1); Assert.AreEqual(eventInfos1[numEventInfos - 1].HitDateLocal, mostRecentHitDate); Assert.AreNotEqual(eventInfos1[0].HitDateLocal, mostRecentHitDate); Assert.AreNotEqual(eventInfos1[1].HitDateLocal, mostRecentHitDate); DateTime mostRecentHitDate2 = m_Index.GetMostRecentHitDate(product1, file1, event2); Assert.AreEqual(eventInfos2[numEventInfos - 1].HitDateLocal, mostRecentHitDate2); Assert.AreNotEqual(eventInfos2[0].HitDateLocal, mostRecentHitDate2); Assert.AreNotEqual(eventInfos2[1].HitDateLocal, mostRecentHitDate2); }
private void UpdateEvents(DateTime lastPullDate, IErrorIndex errorIndex, StackHashProduct stackHashProduct, bool getCabs, ApplicationFile file, StackHashFile stackHashFile) { // Get the events for the file with the start date as last pull date + 1. // Only stores the last 90 days worth - this will exception if you specify a date // before that time. In the case of the last pulldown date being close to 90 days ago // just get ALL the events. DateTime startTime = lastPullDate; // This is a local time. EventPageReader eventPageReader; TimeSpan timeSinceLastSync = (DateTime.UtcNow - lastPullDate.ToUniversalTime()); if (timeSinceLastSync.Days >= 89) { StackHashUtilities.DiagnosticsHelper.LogMessage(DiagSeverity.Information, String.Format(CultureInfo.InvariantCulture, "Updating Events for {0} {1} ALL", stackHashProduct.Name, stackHashFile.Name)); eventPageReader = file.GetEvents(); // Get all events. } else { StackHashUtilities.DiagnosticsHelper.LogMessage(DiagSeverity.Information, String.Format(CultureInfo.InvariantCulture, "Updating Events for {0} {1} since {2} {3}", stackHashProduct.Name, stackHashFile.Name, startTime, startTime.Kind)); eventPageReader = file.GetEvents(startTime); } // Read each page of new events. while (eventPageReader.Read(ref m_Login) == true) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } // Get the events for the page. EventReader events = eventPageReader.Events; while (events.Read() == true) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } // Get the event Event dpEvent = events.Event; StackHashEvent stackHashEvent = ObjectConversion.ConvertEvent(dpEvent, stackHashFile.Id); m_SyncProgress.EventId = stackHashEvent.Id; m_SyncProgress.EventTypeName = stackHashEvent.EventTypeName; // Check the date created. If it is greater than the last // pull date then this is a new event and hence insert. if (dpEvent.DateCreatedLocal > lastPullDate) { errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent); } else if (dpEvent.DateModifiedLocal > lastPullDate) { // update the event information if event modified // date is greater than the last pull date errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent); } else { // Check if the event exists. If not then add it. if (!errorIndex.EventExists(stackHashProduct, stackHashFile, stackHashEvent)) { errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent); } } // Get the details for the event. EventInfoCollection infoCollection = dpEvent.GetEventDetails(ref m_Login); // Loop through the event info. StackHashEventInfo stackHashEventInfo = null; StackHashEventInfoCollection stackHashEventInfoCollection = new StackHashEventInfoCollection(); foreach (EventInfo info in infoCollection) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } stackHashEventInfo = ObjectConversion.ConvertEventInfo(info); stackHashEventInfoCollection.Add(stackHashEventInfo); } errorIndex.MergeEventInfoCollection(stackHashProduct, stackHashFile, stackHashEvent, stackHashEventInfoCollection); // Now get the total hits. StackHashEventInfoCollection newEventInfos = errorIndex.LoadEventInfoList(stackHashProduct, stackHashFile, stackHashEvent); int hits = 0; foreach (StackHashEventInfo theEvent in newEventInfos) { hits += theEvent.TotalHits; } // Update the hits count. stackHashEvent.TotalHits = hits; errorIndex.AddEvent(stackHashProduct, stackHashFile, stackHashEvent); if (getCabs) { UpdateCabs(lastPullDate, errorIndex, stackHashProduct, dpEvent, stackHashFile, stackHashEvent); } } } }
private void testMergeOneNewEventInfoWithOverlap(IErrorIndex index, int numEventInfos, int overlap) { // Add event info - then add another new one. index.Activate(); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "http://www.cucku.com", 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file = new StackHashFile(new DateTime(100), new DateTime(101), 39, new DateTime(102), "filename.dll", "1.2.3.4"); StackHashParameterCollection parameters = new StackHashParameterCollection(); parameters.Add(new StackHashParameter("param1", "param1value")); parameters.Add(new StackHashParameter("param2", "param2value")); StackHashEventSignature signature = new StackHashEventSignature(parameters); StackHashEvent theEvent = new StackHashEvent(new DateTime(102), new DateTime(103), "EventType1", 20000, signature, -1, 2); index.AddProduct(product); index.AddFile(product, file); index.AddEvent(product, file, theEvent); StackHashEventInfoCollection eventInfoCollection = new StackHashEventInfoCollection(); int totalHits = 0; for (int i = 0; i < numEventInfos; i++) { if (i < numEventInfos - overlap) { totalHits += i + 1; } StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(-3 * i).Date, DateTime.Now.AddDays(-2 * i).Date, DateTime.Now.AddDays(-1 * i).Date, "English" + i.ToString(), i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), i + 1); eventInfoCollection.Add(eventInfo); } index.MergeEventInfoCollection(product, file, theEvent, eventInfoCollection); StackHashEventInfoCollection eventInfoCollectionNew = new StackHashEventInfoCollection(); for (int i = numEventInfos - overlap; i < numEventInfos * 2 - overlap; i++) { StackHashEventInfo eventInfo = new StackHashEventInfo(DateTime.Now.AddDays(-3 * i).Date, DateTime.Now.AddDays(-2 * i).Date, DateTime.Now.AddDays(-1 * i).Date, "English" + i.ToString(), i, "locale" + i.ToString(), "OS" + i.ToString(), "OSVersion" + i.ToString(), overlap + i + 1); if (i >= numEventInfos - overlap) { totalHits += overlap + i + 1; } StackHashEventInfo foundEventInfo = eventInfoCollection.FindEventInfoByHitDate(eventInfo); if (foundEventInfo != null) { foundEventInfo.SetWinQualFields(eventInfo); } else { eventInfoCollection.Add(eventInfo); } eventInfoCollectionNew.Add(eventInfo); } index.MergeEventInfoCollection(product, file, theEvent, eventInfoCollectionNew); // Now get all the event info and make sure it all matches. StackHashEventInfoCollection eventInfoCollection2 = index.LoadEventInfoList(product, file, theEvent); Assert.AreEqual(0, eventInfoCollection.CompareTo(eventInfoCollection2)); StackHashEventPackageCollection eventPackages = index.GetProductEvents(product); Assert.AreEqual(1, eventPackages.Count); Assert.AreEqual(totalHits, eventPackages[0].EventData.TotalHits); }
// // 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 addGetNEventInfos(int numEventInfos, bool useSameLocale) { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); 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); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(numEventInfos, eventInfos.Count); for (int i = 0; i < numEventInfos; i++) { Assert.AreEqual(0, eventInfos[i].CompareTo(eventInfosRetrieved[i])); } int totalHitsRetrieved = m_Index.GetHitCount(product1, file1, event1); Assert.AreEqual(totalHits, totalHitsRetrieved); }
// // 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> /// Gets the rollup of locales. /// </summary> public void getLocaleRollup(int numEventInfos, int localeIdModulo) { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); int hitCount = 1; int totalHits = 0; String localeCodeBase = "US"; String languageNameBase = "ENGLISH"; for (int i = 1; i <= numEventInfos; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = (i % localeIdModulo) + 1; totalHits += hitCount; StackHashEventInfo eventInfo = new StackHashEventInfo(date.AddDays(i * 1), date.AddDays(i * 2), date.AddDays(i * 3), languageNameBase + localeId.ToString(), localeId, localeCodeBase + localeId.ToString(), "Windows Vista" + i.ToString(), "1.2.3.4 build 7", localeId); eventInfos.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashProductLocaleSummaryCollection localeSummary = m_Index.GetLocaleSummary(product1.Id); StackHashProductLocaleSummaryCollection localeSummaryFresh = m_Index.GetLocaleSummaryFresh(product1.Id); Assert.AreEqual(0, localeSummary.CompareTo(localeSummaryFresh)); Dictionary <int, StackHashProductLocaleSummary> localeCheckList = new Dictionary <int, StackHashProductLocaleSummary>(); if (localeIdModulo < numEventInfos) { Assert.AreEqual(localeIdModulo, localeSummary.Count); } else { Assert.AreEqual(numEventInfos, localeSummary.Count); } foreach (StackHashProductLocaleSummary localeData in localeSummary) { if (localeIdModulo >= numEventInfos) { Assert.AreEqual(localeData.Lcid, localeData.TotalHits); } else { Assert.AreEqual(localeData.Lcid * ((numEventInfos / localeIdModulo)), localeData.TotalHits); } Assert.AreEqual(localeCodeBase + localeData.Lcid.ToString(), localeData.Locale); Assert.AreEqual(languageNameBase + localeData.Lcid.ToString(), localeData.Language); Assert.AreEqual(false, localeCheckList.ContainsKey(localeData.Lcid)); localeCheckList.Add(localeData.Lcid, localeData); } m_Index.UpdateProductStatistics(product1.Id); StackHashProductLocaleSummaryCollection localeSummary2 = m_Index.GetLocaleSummary(product1.Id); Assert.AreEqual(0, localeSummary.CompareTo(localeSummary2)); }
public void MergeOneInCommon() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos1 = new StackHashEventInfoCollection(); StackHashEventInfoCollection eventInfos2 = new StackHashEventInfoCollection(); for (int i = 0; i < 3; i++) { DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = i; 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", 100); if (i < 2) { eventInfos1.Add(eventInfo); } if (i > 0) { eventInfos2.Add(eventInfo); } } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos1); m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos2); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(3, eventInfosRetrieved.Count); int realListIndex = 0; for (int i = 0; i < 2; i++) { Assert.AreEqual(0, eventInfos1[i].CompareTo(eventInfosRetrieved[realListIndex])); realListIndex++; } for (int i = 1; i < 3; i++) { Assert.AreEqual(0, eventInfos2[i - 1].CompareTo(eventInfosRetrieved[realListIndex - 1])); realListIndex++; } }
/// <summary> /// Gets the rollup of hit dates. /// </summary> public void getHitDateRollup(int numEventInfos, int hitDateModulo) { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos = new StackHashEventInfoCollection(); int hitCount = 1; int totalHits = 0; String localeCodeBase = "US"; String languageNameBase = "ENGLISH"; String osBase = "Vista"; DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); for (int i = 0; i < numEventInfos; i++) { DateTime hitDate = date.AddDays(i % hitDateModulo); totalHits += hitCount; int localeId = i; int osId = i; int hits = (i % hitDateModulo); StackHashEventInfo eventInfo = new StackHashEventInfo(creationDateTime, modifiedDateTime, hitDate, languageNameBase + localeId.ToString(), localeId, localeCodeBase + localeId.ToString(), osBase + osId.ToString(), osId.ToString(), hits); eventInfos.Add(eventInfo); } m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos); StackHashProductHitDateSummaryCollection hitDateSummary = m_Index.GetHitDateSummary(product1.Id); StackHashProductHitDateSummaryCollection hitDateSummaryFresh = m_Index.GetHitDateSummaryFresh(product1.Id); Assert.AreEqual(0, hitDateSummary.CompareTo(hitDateSummaryFresh)); Dictionary <DateTime, StackHashProductHitDateSummary> hitDateCheckList = new Dictionary <DateTime, StackHashProductHitDateSummary>(); if (hitDateModulo < numEventInfos) { Assert.AreEqual(hitDateModulo, hitDateSummary.Count); } else { Assert.AreEqual(numEventInfos, hitDateSummary.Count); } int dateCount = 0; foreach (StackHashProductHitDateSummary hitData in hitDateSummary) { int expectedDateAdjust = dateCount % hitDateModulo; if (hitDateModulo >= numEventInfos) { Assert.AreEqual(dateCount, hitData.TotalHits); } else { Assert.AreEqual(expectedDateAdjust * ((numEventInfos / hitDateModulo)), hitData.TotalHits); } Assert.AreEqual(false, hitDateCheckList.ContainsKey(hitData.HitDate)); hitDateCheckList.Add(hitData.HitDate, hitData); dateCount++; } // Update the stats fresh. m_Index.UpdateProductStatistics(product1.Id); StackHashProductHitDateSummaryCollection hitDateSummary2 = m_Index.GetHitDateSummary(product1.Id); Assert.AreEqual(0, hitDateSummary.CompareTo(hitDateSummary2)); }
public void MergeWithDuplicatesInNewList() { m_Index = new SqlErrorIndex(StackHashSqlConfiguration.Default, SqlUtils.UnitTestDatabase, m_RootCabFolder); m_Index.DeleteIndex(); m_Index.Activate(); 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, 1, "TestProduct1", 20, 30, "2.10.02123.1293"); StackHashFile file1 = new StackHashFile(creationDateTime, modifiedDateTime, 20, 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(); StackHashEvent event1 = new StackHashEvent(creationDateTime, modifiedDateTime, "EventTypeName1", 100, eventSignature, 20, file1.Id, "bug"); m_Index.AddProduct(product1); m_Index.AddFile(product1, file1); m_Index.AddEvent(product1, file1, event1); StackHashEventInfoCollection eventInfos1 = new StackHashEventInfoCollection(); StackHashEventInfoCollection eventInfos2 = new StackHashEventInfoCollection(); DateTime nowTime = DateTime.Now; DateTime date = new DateTime(nowTime.Year, nowTime.Month, nowTime.Day, nowTime.Hour, nowTime.Minute, 0); int localeId = 123; // These events just different by num hits. StackHashEventInfo eventInfo1 = new StackHashEventInfo(date, date, date, "US", localeId, "English", "Windows Vista", "1.2.3.4 build 7", 100); StackHashEventInfo eventInfo2 = new StackHashEventInfo(date, date, date, "US", localeId, "English", "Windows Vista", "1.2.3.4 build 7", 101); StackHashEventInfo expectedEventInfo = (StackHashEventInfo)eventInfo1.Clone(); expectedEventInfo.TotalHits = eventInfo1.TotalHits + eventInfo2.TotalHits; eventInfos1.Add(eventInfo1); eventInfos1.Add(eventInfo2); m_Index.AddEventInfoCollection(product1, file1, event1, eventInfos1); StackHashEventInfoCollection eventInfosRetrieved = m_Index.LoadEventInfoList(product1, file1, event1); Assert.AreEqual(1, eventInfosRetrieved.Count); Assert.AreEqual(0, expectedEventInfo.CompareTo(eventInfosRetrieved[0])); }
static void Go(ProgramArguments programArguments) { LogManager logger = new LogManager(); logger.StartLogging(); bool noCabs = false; try { StackHashUtilities.SystemInformation.DisableSleep(); AtomFeed atomFeed = new AtomFeed(programArguments.ProxySettings, 5, 300000, programArguments.LogXml, true, programArguments.IPAddress, 11); if (!atomFeed.Login(programArguments.UserName, programArguments.Password)) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Failed to logon - check your username and password"); return; } else { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Logged on successfully."); } // ATOM GetProducts. AtomProductCollection atomProducts = atomFeed.GetProducts(); foreach (AtomProduct atomProduct in atomProducts) { } foreach (AtomProduct atomProduct in atomProducts) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomProduct.Product.ToString()); // ATOM GetFiles. AtomFileCollection atomFiles = atomFeed.GetFiles(atomProduct); int totalEvents = 0; foreach (AtomFile atomFile in atomFiles) { // String eventsLink = @"https://winqual.microsoft.com/Services/wer/user/events.aspx?fileid=" + fileId.ToString(); // AtomFile atomFile = new AtomFile(new StackHashFile(), eventsLink); DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomFile.File.ToString()); // ATOM GetEvents. AtomEventCollection atomEvents = atomFeed.GetEvents(atomFile); foreach (AtomEvent atomEvent in atomEvents) { totalEvents++; DiagnosticsHelper.LogMessage(DiagSeverity.Information, atomEvent.Event.ToString()); // ATOM events. StackHashEventInfoCollection eventInfos = GetEventInfoAtom(atomFeed, atomEvent, 90); StackHashEventInfoCollection normalizedEventInfos = new StackHashEventInfoCollection(); bool stop = false; foreach (StackHashEventInfo eventInfo in eventInfos) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, eventInfo.ToString()); if (eventInfos.GetEventInfoMatchCount(eventInfo) != 1) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "*** DUPLICATE HIT"); DiagnosticsHelper.LogMessage(DiagSeverity.Information, eventInfo.ToString()); stop = true; } StackHashEventInfo normalizedEventInfo = eventInfo.Normalize(); DiagnosticsHelper.LogMessage(DiagSeverity.Information, "N: " + normalizedEventInfo.ToString()); normalizedEventInfos.Add(normalizedEventInfo); if (normalizedEventInfos.GetEventInfoMatchCount(normalizedEventInfo) != 1) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "*** NORMALIZATION ERROR"); DiagnosticsHelper.LogMessage(DiagSeverity.Information, normalizedEventInfo.ToString()); stop = true; } } if (stop) { return; } if (!noCabs) { // ATOM GetCabs. StackHashCabCollection atomCabs = GetCabInfoAtom(atomFeed, atomEvent); foreach (StackHashCab cab in atomCabs) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, cab.ToString()); } } } } DiagnosticsHelper.LogMessage(DiagSeverity.Information, String.Format("TOTAL EVENTS: {0}", totalEvents)); } } catch (System.Exception ex) { DiagnosticsHelper.LogMessage(DiagSeverity.Information, "Error: " + ex.ToString()); } finally { StackHashUtilities.SystemInformation.EnableSleep(); logger.StopLogging(); } }