private void UpdateCabs(DateTime lastPullDate, IErrorIndex errorIndex, StackHashProduct stackHashProduct, Event dpEvent, StackHashFile stackHashFile, StackHashEvent stackHashEvent) { // Get the cabs for the event. CabCollection cabs = dpEvent.GetCabs(ref m_Login); // Work out how many cabs should be downloaded. // int cabsDownloaded = errorIndex.GetCabCount(stackHashProduct, stackHashFile, stackHashEvent); // int maxCabsToDownload = m_ProductsToSynchronize.GetMaxCabs(stackHashProduct.Id); // Loop through the cab collection foreach (Cab cab in cabs) { if (m_AbortRequested) { throw new OperationCanceledException("Abort requested during Win Qual synchronize"); } // Disabled till beta 5. // if (cabsDownloaded >= maxCabsToDownload) // break; StackHashCab stackHashCab = ObjectConversion.ConvertCab(cab); m_SyncProgress.EventId = stackHashEvent.Id; String cabFileName = errorIndex.GetCabFileName(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab); // Add the cab if not already in the database. if (!errorIndex.CabExists(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab) || !File.Exists(cabFileName)) { if (cab.DateModifiedLocal <= lastPullDate) { // This shouldn't happen so log it. DiagnosticsHelper.LogMessage(DiagSeverity.Warning, "Cab date older than last pull date but didn't exist in database - adding anyway: " + cab.ID.ToString(CultureInfo.InvariantCulture)); } // Save the cab to a folder. string cabFolder = errorIndex.GetCabFolder(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab); if (!Directory.Exists(cabFolder)) { Directory.CreateDirectory(cabFolder); } int retryCount = 0; do { cab.SaveCab(cabFolder, false, ref m_Login); retryCount++; if (File.Exists(cabFileName)) { FileInfo fileInfo = new FileInfo(cabFileName); if (fileInfo.Length != cab.SizeInBytes) { // File was only partially downloaded so delete it and retry. File.Delete(cabFileName); } else { // All appears ok so add the cab to the database. errorIndex.AddCab(stackHashProduct, stackHashFile, stackHashEvent, stackHashCab, false); // Done. break; } } } while (retryCount < s_TotalCabDownloadRetries); } } }
/// <summary> /// Downloads a specific cab and stores in the specified index. /// </summary> /// <param name="errorIndex">Error index to store the cab.</param> /// <param name="product">Product to which the cab belongs.</param> /// <param name="file">File to which the cab belongs</param> /// <param name="theEvent">Event to which the cab belongs.</param> /// <param name="cab">The cab to download.</param> /// <returns>Cab file name.</returns> public String GetCab(IErrorIndex errorIndex, StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab) { throw new NotImplementedException("Get Cab"); }
} // Needed to serialize; public AtomCab(StackHashCab cab, String cabLink) { m_StackHashCab = cab; m_CabLink = cabLink; }
// // 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 addRemoveCabNotes(int numberOfNotes) { StackHashTestIndexData testIndexData = new StackHashTestIndexData(); testIndexData.NumberOfProducts = 1; testIndexData.NumberOfFiles = 1; testIndexData.NumberOfEvents = 1; testIndexData.NumberOfEventInfos = 0; testIndexData.NumberOfCabs = 1; // Add a context. CreateNewStackHashContextResponse resp = m_Utils.CreateNewContext(ErrorIndexType.SqlExpress); String testPath = "c:\\stackhashunittests\\testindex\\"; resp.Settings.ErrorIndexSettings.Folder = testPath; resp.Settings.ErrorIndexSettings.Name = "TestIndex"; resp.Settings.ErrorIndexSettings.Type = ErrorIndexType.SqlExpress; m_Utils.SetContextSettings(resp.Settings); m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); m_Utils.CreateTestIndex(0, testIndexData); try { // Enable all products so that they appear in searchs. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; StackHashProduct product = products[0].Product; StackHashFileCollection files = m_Utils.GetFiles(0, product).Files; StackHashEventPackageCollection events = m_Utils.GetProductEventPackages(0, product).EventPackages; StackHashCab cab = events[0].Cabs[0].Cab; // Add the specified number of event notes. for (int cabCount = 0; cabCount < numberOfNotes; cabCount++) { StackHashNoteEntry note = new StackHashNoteEntry(); note.Note = "Note" + (cabCount + 1).ToString(); note.Source = "USER"; note.User = "******"; note.TimeOfEntry = DateTime.Now.AddDays(-1); m_Utils.AddCabNote(0, product, files[0], events[0].EventData, cab, note); StackHashNotes notes = m_Utils.GetCabNotes(0, product, files[0], events[0].EventData, cab).Notes; Assert.AreEqual(cabCount + 1, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == cabCount + 1) { Assert.AreEqual(note.Note, noteEntry.Note); Assert.AreEqual(note.Source, noteEntry.Source); Assert.AreEqual(note.User, noteEntry.User); Assert.AreEqual(DateTime.UtcNow.Date, noteEntry.TimeOfEntry.Date); found = true; break; } } Assert.AreEqual(true, found); } // Now delete the event notes. int expectedEventNotes = numberOfNotes; for (int eventCount = 0; eventCount < numberOfNotes; eventCount++) { m_Utils.DeleteCabNote(0, product, files[0], events[0].EventData, cab, eventCount + 1); expectedEventNotes--; StackHashNotes notes = m_Utils.GetCabNotes(0, product, files[0], events[0].EventData, cab).Notes; Assert.AreEqual(expectedEventNotes, notes.Count); bool found = false; foreach (StackHashNoteEntry noteEntry in notes) { if (noteEntry.NoteId == eventCount + 1) { found = true; break; } } Assert.AreEqual(false, found); } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
/// <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)); } } } }
/// <summary> /// Constructor. /// </summary> /// <param name="progressType">Progress type - e.g. downloading cabs.</param> /// <param name="product">The owning product.</param> /// <param name="file">The owning file.</param> /// <param name="theEvent">The owning event.</param> /// <param name="cab">The cab being downloaded.</param> /// <param name="currentPage">The current page being downloaded.</param> /// <param name="totalPages">Total pages to download.</param> public WinQualProgressEventArgs(WinQualProgressType progressType, StackHashProductInfo product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, int currentPage, int totalPages) { m_ProgressType = progressType; m_Product = product; m_File = file; m_Event = theEvent; m_Cab = cab; m_TotalPages = totalPages; m_CurrentPage = currentPage; }
public StackHashNotes GetCabNotes(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab) { return(null); }
public bool CabFileExists(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab) { return(false); }
public int AddCabNote(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, StackHashNoteEntry note) { return(0); }
public void DeleteCabNote(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, int noteId) { return; }
public string GetCabFileName(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab) { return(null); }
// Cabs. public StackHashCab AddCab(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, bool setDiagnostics) { return(null); }
public void DownloadCabIdInvalid() { String errorIndexFolder = Path.GetTempPath() + "StackHashCabDownloadTests"; String errorIndexName = "CabDownloads"; String scriptFolder = errorIndexFolder + "\\Scripts"; if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } Directory.CreateDirectory(errorIndexFolder); Directory.CreateDirectory(scriptFolder); try { // Create a settings manager and a new context. SettingsManager settingsManager = new SettingsManager(errorIndexFolder + "\\ServiceSettings.XML"); StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings(); contextSettings.WinQualSettings = new WinQualSettings(TestSettings.WinQualUserName, TestSettings.WinQualPassword, "Company", 10, new StackHashProductSyncDataCollection(), false, 0, 1, WinQualSettings.DefaultSyncsBeforeResync, false); contextSettings.ErrorIndexSettings = new ErrorIndexSettings(); contextSettings.ErrorIndexSettings.Folder = errorIndexFolder; contextSettings.ErrorIndexSettings.Name = errorIndexName; ScriptManager scriptManager = new ScriptManager(scriptFolder); string licenseFileName = string.Format("{0}\\License.bin", errorIndexFolder); LicenseManager licenseManager = new LicenseManager(licenseFileName, s_TestServiceGuid); licenseManager.SetLicense(s_LicenseId); ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(), settingsManager, false, null, licenseManager); // Activate the context and the associated index. controllerContext.Activate(); // Hook up to receive admin reports. controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); // Run the download task. Guid guid = new Guid(); StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1); // Most of these params are real taking from Crashy. StackHashProduct product = new StackHashProduct(DateTime.Parse("2010-04-16T22:31:02Z"), DateTime.Parse("2010-07-07T08:20:58Z"), @"https://winqual.microsoft.com/Services/wer/user/files.aspx?productid=25299", 25299, "Crashy", 10, 0, "1.2.3.4"); StackHashFile file = new StackHashFile(DateTime.Parse("2010-04-19T00:15:00Z"), DateTime.Parse("2010-04-19T00:15:00Z"), 4232330, DateTime.Parse("2010-04-17T05:21:32Z"), "Crashy.exe", "1.2.3.4"); StackHashEvent theEvent = new StackHashEvent(DateTime.Parse("2010-04-19T10:20:00Z"), DateTime.Parse("2010-04-19T10:20:00Z"), "CLR20 Managed Crash", 1099299922, new StackHashEventSignature(), 13, 4232330); StackHashCab cab = new StackHashCab(DateTime.Parse("2010-04-21T16:49:00Z"), DateTime.Parse("2010-04-21T16:49:00Z"), 1099299922, "CLR20 Managed Crash", "1099299922-CLR20ManagedCrash-0837914903.cab", 0x12345678, 9313620); controllerContext.ErrorIndex.AddProduct(product); controllerContext.ErrorIndex.AddFile(product, file); controllerContext.ErrorIndex.AddEvent(product, file, theEvent); controllerContext.ErrorIndex.AddCab(product, file, theEvent, cab, true); controllerContext.RunDownloadCabTask(clientData, product, file, theEvent, cab, false); // Wait for the download task to complete - could take 5 mins to download. waitForDownloadCompleted(5 * 60000); Assert.AreEqual(2, m_AdminReports.Count); Assert.AreEqual(null, m_AdminReports[0].Report.LastException); Assert.AreEqual(0, m_AdminReports[0].Report.ContextId); Assert.AreEqual(StackHashAdminOperation.DownloadCabStarted, m_AdminReports[0].Report.Operation); Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[0].Report.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, m_AdminReports[0].Report.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, m_AdminReports[0].Report.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[0].Report.ClientData.ClientRequestId); Assert.AreEqual(StackHashAsyncOperationResult.Success, m_AdminReports[0].Report.ResultData); Assert.AreEqual(0, m_AdminReports[1].Report.ContextId); Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, m_AdminReports[1].Report.Operation); Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[1].Report.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, m_AdminReports[1].Report.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, m_AdminReports[1].Report.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[1].Report.ClientData.ClientRequestId); Assert.AreEqual(StackHashAsyncOperationResult.Failed, m_AdminReports[1].Report.ResultData); Assert.AreNotEqual(null, m_AdminReports[1].Report.LastException); Assert.AreEqual(StackHashServiceErrorCode.CabDoesNotExist, m_AdminReports[1].Report.ServiceErrorCode); controllerContext.Deactivate(); controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport); } finally { if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } } }
public void DownloadCabAllOkDummy() { String errorIndexFolder = Path.GetTempPath() + "StackHashCabDownloadTests"; String errorIndexName = "CabDownloads"; String scriptFolder = errorIndexFolder + "\\Scripts"; if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } Directory.CreateDirectory(errorIndexFolder); Directory.CreateDirectory(scriptFolder); try { // Create a settings manager and a new context. SettingsManager settingsManager = new SettingsManager(errorIndexFolder + "\\ServiceSettings.XML"); StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings(); contextSettings.WinQualSettings = new WinQualSettings("UserName", "Password", "Company", 10, new StackHashProductSyncDataCollection(), false, 0, 1, WinQualSettings.DefaultSyncsBeforeResync, false); contextSettings.ErrorIndexSettings = new ErrorIndexSettings(); contextSettings.ErrorIndexSettings.Folder = errorIndexFolder; contextSettings.ErrorIndexSettings.Name = errorIndexName; ScriptManager scriptManager = new ScriptManager(scriptFolder); string licenseFileName = string.Format("{0}\\License.bin", errorIndexFolder); LicenseManager licenseManager = new LicenseManager(licenseFileName, s_TestServiceGuid); licenseManager.SetLicense(s_LicenseId); ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(), settingsManager, true, StackHashTestData.Default, licenseManager); // Activate the context and the associated index. controllerContext.Activate(); // Hook up to receive admin reports. controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); // Run the download task. Guid guid = new Guid(); StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "www.files.com", 12345678, "CuckuBackup", 10, 1, "1.2.3.4"); StackHashFile file = new StackHashFile(DateTime.Now, DateTime.Now, 23, DateTime.Now, "FileName", "2.3.4.5"); StackHashEvent theEvent = new StackHashEvent(DateTime.Now, DateTime.Now, "EventTypeName", 10, new StackHashEventSignature(), 1, 23); StackHashCab cab = new StackHashCab(DateTime.Now, DateTime.Now, 10, "EventTypeName", "this.cab", 100, 10000); controllerContext.ErrorIndex.AddProduct(product); controllerContext.ErrorIndex.AddFile(product, file); controllerContext.ErrorIndex.AddEvent(product, file, theEvent); cab.DumpAnalysis = new StackHashDumpAnalysis(); cab.DumpAnalysis.DotNetVersion = "xxx"; controllerContext.ErrorIndex.AddCab(product, file, theEvent, cab, false); controllerContext.RunDownloadCabTask(clientData, product, file, theEvent, cab, false); // Wait for the download task to complete. waitForDownloadCompleted(30000); Assert.AreEqual(2, m_AdminReports.Count); Assert.AreEqual(null, m_AdminReports[0].Report.LastException); Assert.AreEqual(0, m_AdminReports[0].Report.ContextId); Assert.AreEqual(StackHashAdminOperation.DownloadCabStarted, m_AdminReports[0].Report.Operation); Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[0].Report.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, m_AdminReports[0].Report.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, m_AdminReports[0].Report.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[0].Report.ClientData.ClientRequestId); Assert.AreEqual(null, m_AdminReports[1].Report.LastException); Assert.AreEqual(0, m_AdminReports[1].Report.ContextId); Assert.AreEqual(StackHashAdminOperation.DownloadCabCompleted, m_AdminReports[1].Report.Operation); Assert.AreEqual(clientData.ApplicationGuid, m_AdminReports[1].Report.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, m_AdminReports[1].Report.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, m_AdminReports[1].Report.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, m_AdminReports[1].Report.ClientData.ClientRequestId); // Get the cab data to ensure that it is set to downloaded. StackHashCabCollection cabs = controllerContext.ErrorIndex.LoadCabList(product, file, theEvent); Assert.AreEqual(true, cabs[0].CabDownloaded); Assert.AreEqual("xxx", cabs[0].DumpAnalysis.DotNetVersion); controllerContext.Deactivate(); controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport); } finally { if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } } }
public void DownloadCabProductDoesNotExist() { String errorIndexFolder = Path.GetTempPath() + "StackHashCabDownloadTests"; String errorIndexName = "CabDownloads"; String scriptFolder = errorIndexFolder + "\\Scripts"; if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } Directory.CreateDirectory(errorIndexFolder); Directory.CreateDirectory(scriptFolder); try { // Create a settings manager and a new context. SettingsManager settingsManager = new SettingsManager(errorIndexFolder + "\\ServiceSettings.XML"); StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings(); contextSettings.WinQualSettings = new WinQualSettings("UserName", "Password", "Company", 10, new StackHashProductSyncDataCollection(), false, 0, 1, WinQualSettings.DefaultSyncsBeforeResync, false); contextSettings.ErrorIndexSettings = new ErrorIndexSettings(); contextSettings.ErrorIndexSettings.Folder = errorIndexFolder; contextSettings.ErrorIndexSettings.Name = errorIndexName; ScriptManager scriptManager = new ScriptManager(scriptFolder); string licenseFileName = string.Format("{0}\\License.bin", errorIndexFolder); LicenseManager licenseManager = new LicenseManager(licenseFileName, s_TestServiceGuid); licenseManager.SetLicense(s_LicenseId); ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(), settingsManager, true, StackHashTestData.Default, licenseManager); // Activate the context and the associated index. controllerContext.Activate(); // Hook up to receive admin reports. controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); // Run the download task. Guid guid = new Guid(); StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1); StackHashProduct product = new StackHashProduct(DateTime.Now, DateTime.Now, "www.files.com", 12345678, "CuckuBackup", 10, 1, "1.2.3.4"); StackHashFile file = new StackHashFile(DateTime.Now, DateTime.Now, 23, DateTime.Now, "FileName", "2.3.4.5"); StackHashEvent theEvent = new StackHashEvent(DateTime.Now, DateTime.Now, "EventTypeName", 10, new StackHashEventSignature(), 1, 23); StackHashCab cab = new StackHashCab(DateTime.Now, DateTime.Now, 10, "EventTypeName", "this.cab", 100, 10000); try { controllerContext.RunDownloadCabTask(clientData, product, file, theEvent, cab, false); } catch (ArgumentException ex) { Assert.AreEqual(true, ex.Message.Contains("Product does not exist")); } controllerContext.Deactivate(); controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport); } finally { if (Directory.Exists(errorIndexFolder)) { PathUtils.SetFilesWritable(errorIndexFolder, true); PathUtils.DeleteDirectory(errorIndexFolder, true); } } }