public StateChangedEventArgs(StackHashClientData clientData, TaskState taskState, Task task) { // Clone the state. m_TaskState = new TaskState(taskState); m_ClientData = clientData; m_Task = task; }
public RegisteredClient(StackHashClientData clientData, IAdminNotificationEvents clientCallback, DateTime lastAccessTime, DateTime firstRegisteredTime) { m_ClientData = clientData; m_ClientCallback = clientCallback; m_LastAccessTime = lastAccessTime; m_FirstRegisteredTime = firstRegisteredTime; }
public void ActivateOk() { string settingsFileName = string.Format("{0}\\ServiceSettings.xml", m_TempPath); SettingsManager settingsManager = new SettingsManager(settingsFileName); settingsManager.ServiceGuid = s_TestServiceGuid; StackHashContextSettings settings = settingsManager.CreateNewContextSettings(); settings.ErrorIndexSettings.Folder = m_TempPath; settings.ErrorIndexSettings.Name = "TestIndex"; settings.ErrorIndexSettings.Type = ErrorIndexType.Xml; string licenseFileName = string.Format("{0}\\License.bin", m_TempPath); LicenseManager licenseManager = new LicenseManager(licenseFileName, s_TestServiceGuid); licenseManager.SetLicense(s_LicenseId); ScriptManager scriptManager = new ScriptManager(m_ScriptPath); IDebugger debugger = new Windbg(); ControllerContext context = new ControllerContext(settings, scriptManager, debugger, settingsManager, true, StackHashTestData.Default, licenseManager); Assert.AreEqual(false, context.IsActive); Assert.AreEqual(null, context.WinQualSyncTimerTask); // Hook up to receive admin events. context.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); StackHashClientData clientData = new StackHashClientData(Guid.NewGuid(), "Mark", 24); context.Activate(clientData, false); // Wait for the activation event. m_ActivationAdminEvent.WaitOne(3000); Assert.AreEqual(1, m_AllReports.Count); Assert.AreEqual(clientData.ApplicationGuid, m_AllReports[0].Report.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, m_AllReports[0].Report.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, m_AllReports[0].Report.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, m_AllReports[0].Report.ClientData.ClientRequestId); Assert.AreEqual(0, m_AllReports[0].Report.ContextId); Assert.AreNotEqual(null, m_AllReports[0].Report.Description); Assert.AreNotEqual(null, m_AllReports[0].Report.Message); Assert.AreEqual(StackHashAdminOperation.ContextStateChanged, m_AllReports[0].Report.Operation); Assert.AreEqual(StackHashServiceErrorCode.NoError, m_AllReports[0].Report.ServiceErrorCode); Assert.AreEqual(null, m_AllReports[0].Report.LastException); Assert.AreEqual(null, m_AllReports[0].Report.LastException); Assert.AreEqual(StackHashAdminOperation.ContextStateChanged, m_AllReports[0].Report.Operation); StackHashContextStateAdminReport contextChanged = m_AllReports[0].Report as StackHashContextStateAdminReport; Assert.AreEqual(true, contextChanged.IsActivationAttempt); Assert.AreEqual(true, contextChanged.IsActive); Assert.AreEqual(true, context.IsActive); Assert.AreNotEqual(null, context.WinQualSyncTimerTask); context.Dispose(); }
/// <summary> /// Purges old cabs (currently > 180 days) from the index. /// </summary> /// <param name="clientData">Data passed to the client callback.</param> public override void RunPurgeTask(StackHashClientData clientData) { m_RunPurgeCallCount++; // Throw an unexpected error. if (MakeExceptionInPurge) { throw new ArgumentException("clientData"); } }
private StackHashClientData GenerateClientData() { StackHashClientData clientData = new StackHashClientData(); clientData.ApplicationGuid = _clientDataSessionId; clientData.ClientId = 0; clientData.ClientName = Environment.UserName + "_StackHashDBConfig"; clientData.ClientRequestId = _clientDataRequestId; clientData.ServiceGuid = _localServiceGuid == Guid.Empty ? null : _localServiceGuid.ToString(); _clientDataRequestId++; return(clientData); }
public void runAnalyzeJustAutoScripts(ErrorIndexType indexType, int numberOfProducts, int numberOfFiles, int numberOfEvents, int numberOfCabs, int numberOfAutoUnmanagedAndManagedScripts, int numberOfManualUnmanagedAndManagedScripts, bool useUnmanagedCabs, int numberOfAutoManagedScripts, int numberOfManualManagedScripts, int numberOfAutoUnmanagedScripts, int numberOfManualUnmanagedScripts) { int numberOfEventInfos = 1; // Use the dummy winqual. StackHashTestData testData = new StackHashTestData(); testData.DummyWinQualSettings = new StackHashTestDummyWinQualSettings(); testData.DummyWinQualSettings.UseDummyWinQual = true; testData.DummyWinQualSettings.ObjectsToCreate = new StackHashTestIndexData(); testData.DummyWinQualSettings.ObjectsToCreate.UseLargeCab = false; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfProducts = numberOfProducts; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfFiles = numberOfFiles; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEvents = numberOfEvents; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEventInfos = numberOfEventInfos; testData.DummyWinQualSettings.ObjectsToCreate.NumberOfCabs = numberOfCabs; testData.DummyWinQualSettings.ObjectsToCreate.UseUnmanagedCab = useUnmanagedCabs; m_Utils.SetTestData(testData); m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid); m_Utils.CreateNewContext(indexType); // Set the username and password to something valid. GetStackHashPropertiesResponse settings = m_Utils.GetContextSettings(); String testPath = "c:\\stackhashunittest\\testindex\\"; settings.Settings.ContextCollection[0].ErrorIndexSettings.Folder = testPath; settings.Settings.ContextCollection[0].ErrorIndexSettings.Name = "TestIndex"; settings.Settings.ContextCollection[0].WinQualSettings.UserName = m_UserName; settings.Settings.ContextCollection[0].WinQualSettings.Password = m_Password; m_Utils.SetContextSettings(settings.Settings.ContextCollection[0]); // Make sure the index starts off empty. m_Utils.DeleteIndex(0); m_Utils.ActivateContext(0); for (int i = 0; i < numberOfAutoUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i, true, StackHashScriptDumpType.UnmanagedAndManaged, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedAndManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 100, true, StackHashScriptDumpType.UnmanagedAndManaged, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 200, true, StackHashScriptDumpType.ManagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualManagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 300, true, StackHashScriptDumpType.ManagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfAutoUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 400, true, StackHashScriptDumpType.UnmanagedOnly, true); m_Utils.AddDebuggerScript(scriptSettings, false); } for (int i = 0; i < numberOfManualUnmanagedScripts; i++) { StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 500, true, StackHashScriptDumpType.UnmanagedOnly, false); m_Utils.AddDebuggerScript(scriptSettings, false); } try { // Synchronize so we have a copy of just the product list. StartSynchronizationResponse resp = m_Utils.StartSynchronization(0, 60000); StackHashClientData clientData = m_Utils.LastClientData; StackHashWinQualSyncCompleteAdminReport adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(numberOfProducts, adminReport.ErrorIndexStatistics.Products); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.EventInfos); // Enable sync for all the products. GetProductsResponse getProducts = m_Utils.GetProducts(0); foreach (StackHashProductInfo productInfo in getProducts.Products) { Assert.AreEqual(false, productInfo.SynchronizeEnabled); m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true); // Make sure there are no files for this product yet. GetFilesResponse getFiles = m_Utils.GetFiles(0, productInfo.Product); Assert.AreEqual(0, getFiles.Files.Count); } // Start the sync and wait for the sync and analyze to complete. resp = m_Utils.StartSynchronization(0, 120000, false, false, null); clientData = m_Utils.LastClientData; adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport; Assert.AreNotEqual(null, adminReport); Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid); Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId); Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName); Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId); Assert.AreEqual(0, adminReport.ContextId); Assert.AreEqual(null, adminReport.LastException); Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation); Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData); Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Products); // Should have already added the product. Assert.AreEqual(numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Files); Assert.AreEqual(numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Events); Assert.AreEqual(numberOfCabs * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Cabs); Assert.AreEqual(numberOfEventInfos * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.EventInfos); // Make sure the task is no longer running. GetStackHashServiceStatusResponse statusResp = m_Utils.GetServiceStatus(); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.WinQualSynchronizeTask)); Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.AnalyzeTask)); // Check that the scripts have been run ok. Both auto scripts should be run. StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products; foreach (StackHashProductInfo product in products) { StackHashFileCollection files = m_Utils.GetFiles(0, product.Product).Files; foreach (StackHashFile file in files) { StackHashEventCollection events = m_Utils.GetEvents(0, product.Product, file).Events; foreach (StackHashEvent currentEvent in events) { StackHashEventPackage eventPackage = m_Utils.GetEventPackage(0, product.Product, file, currentEvent).EventPackage; foreach (StackHashCabPackage cab in eventPackage.Cabs) { StackHashScriptResultFiles scriptResults = m_Utils.GetDebugResultFiles(0, product.Product, file, currentEvent, cab.Cab).ResultFiles; int numberOfAutoScripts = 2; int expectedResults = numberOfAutoScripts + numberOfAutoUnmanagedAndManagedScripts; if (!useUnmanagedCabs) { expectedResults += numberOfAutoManagedScripts; } else { expectedResults += numberOfAutoUnmanagedScripts; } Assert.AreEqual(expectedResults, scriptResults.Count); } } } } } finally { m_Utils.DeactivateContext(0); m_Utils.DeleteIndex(0); } }
/// <summary> /// Synchronizes the local database with the WinQual service online. /// </summary> /// <param name="clientData">Client information.</param> /// <param name="forceFullSynchronize">True - full sync, false - syncs from last successful sync time.</param> /// <param name="waitForCompletion">true - thread waits, false - returns immediately.</param> /// <param name="justSyncProducts">true - just sync the product list, false - sync according to enabled products.</param> /// <param name="productsToSynchronize">List of products to sync - can be null.</param> /// <param name="isTimedSync">True - started by timer, false - started by user.</param> /// <param name="isRetry">True - task being started after a retry, false - task not started as a result of a retry.</param> public override void RunSynchronizeTask(StackHashClientData clientData, bool forceFullSynchronize, bool waitForCompletion, bool justSyncProducts, StackHashProductSyncDataCollection productsToSynchronize, bool isTimedSync, bool isRetry) { m_SynchronizeCallCount++; }
public StackHashScriptResult RunScript(StackHashProduct product, StackHashFile file, StackHashEvent theEvent, StackHashCab cab, String dumpFileName, String scriptName, bool extractCab, StackHashClientData clientData, bool forceRun) { if (product == null) { throw new ArgumentNullException("product"); } if (file == null) { throw new ArgumentNullException("file"); } if (theEvent == null) { throw new ArgumentNullException("theEvent"); } if (cab == null) { throw new ArgumentNullException("cab"); } if (scriptName == null) { throw new ArgumentNullException("scriptName"); } String machineArchitecture = "x86"; // Default to 32 bit. if ((cab.DumpAnalysis != null) && !String.IsNullOrEmpty(cab.DumpAnalysis.MachineArchitecture)) { machineArchitecture = cab.DumpAnalysis.MachineArchitecture; } StackHashScriptResult result = null; bool use32BitDebugger = true; if (machineArchitecture != null) { if ((String.Compare(machineArchitecture, "x64", StringComparison.OrdinalIgnoreCase) == 0) || (String.Compare(machineArchitecture, "X64", StringComparison.OrdinalIgnoreCase) == 0)) { use32BitDebugger = false; } } // Unwrap the cab if necessary. String cabFileName = m_ErrorIndex.GetCabFileName(product, file, theEvent, cab); String cabFileFolder = Path.GetDirectoryName(cabFileName); if (!File.Exists(cabFileName)) { throw new StackHashException("Cab file does not exist: " + cabFileName, StackHashServiceErrorCode.CabDoesNotExist); } if (extractCab) { try { Cabs.ExtractCab(cabFileName, cabFileFolder); } catch (System.Exception ex) { if (ex.Message.Contains("The file is not a cabinet") || ex.Message.Contains("corrupt") || ex.Message.Contains("Corrupt")) { // Set the downloaded flag appropriately if different. StackHashCab loadedCab = m_ErrorIndex.GetCab(product, file, theEvent, cab.Id); if (loadedCab != null) { if (loadedCab.CabDownloaded) { loadedCab.CabDownloaded = false; m_ErrorIndex.AddCab(product, file, theEvent, loadedCab, false); } } } throw new StackHashException("Cab file cannot be unpackaged. Try downloading the file from again.", ex, StackHashServiceErrorCode.CabIsCorrupt); } } // Now get the dump filename - mdmp and dmp files should be returned. String[] allDumpFiles = Directory.GetFiles(cabFileFolder, "*.*dmp"); if (allDumpFiles.Length == 0) { return(null); } // Choose the largest dump file to process. String fullDumpFilePath = null; long largestFileSize = 0; foreach (String fileName in allDumpFiles) { FileInfo fileInfo = new FileInfo(fileName); if (fileInfo.Length > largestFileSize) { largestFileSize = fileInfo.Length; fullDumpFilePath = fileName; } } if (!String.IsNullOrEmpty(dumpFileName)) { fullDumpFilePath = cabFileFolder + "\\" + dumpFileName; } // Find the script that the user wants to run. StackHashScriptSettings scriptSettings = m_ScriptManager.LoadScript(scriptName); // Auto generate the script file. String dumpAnalysisFolder = cabFileFolder + "\\Analysis"; if (!Directory.Exists(dumpAnalysisFolder)) { Directory.CreateDirectory(dumpAnalysisFolder); } // Check if the file has already been run. bool runScript = true; String resultsFileName = String.Format(CultureInfo.InvariantCulture, "{0}\\{1}.log", dumpAnalysisFolder, scriptSettings.Name); if (File.Exists(resultsFileName)) { DateTime lastWriteTime = File.GetLastWriteTimeUtc(resultsFileName); if (scriptSettings.LastModifiedDate <= lastWriteTime) { runScript = false; } } String installFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); if (runScript || forceRun) { String overrideSymbolPath = null; String overrideBinaryPath = null; String overrideSourcePath = null; if (m_Debugger.Use32BitDebugger(use32BitDebugger, m_DebuggerSettings)) { overrideSymbolPath = m_DebuggerSettings.SymbolPath.FullPath; overrideBinaryPath = m_DebuggerSettings.BinaryPath.FullPath; overrideSourcePath = null; // Check the script for PSSCOR loading. String clrVersion = String.Empty; if ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion))) { clrVersion = cab.DumpAnalysis.DotNetVersion; } scriptSettings.FixUp(StackHashScriptDumpArchitecture.X86, clrVersion, installFolder); } else { overrideSymbolPath = m_DebuggerSettings.SymbolPath64Bit.FullPath; overrideBinaryPath = m_DebuggerSettings.BinaryPath64Bit.FullPath; overrideSourcePath = null; // Check the script for PSSCOR loading. String clrVersion = String.Empty; if ((cab.DumpAnalysis != null) && (!String.IsNullOrEmpty(cab.DumpAnalysis.DotNetVersion))) { clrVersion = cab.DumpAnalysis.DotNetVersion; } scriptSettings.FixUp(StackHashScriptDumpArchitecture.Amd64, clrVersion, installFolder); } String scriptFileName = Path.GetTempFileName(); scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref overrideSymbolPath, ref overrideBinaryPath, ref overrideSourcePath); DateTime timeOfRun = DateTime.Now.ToUniversalTime(); try { m_Debugger.RunScript(m_DebuggerSettings, use32BitDebugger, scriptFileName, fullDumpFilePath, resultsFileName, overrideSymbolPath, overrideBinaryPath, overrideSourcePath); // Check if the results were generated. If not there must be a command line error so get the output from the // debugger and throw an exception. if (!File.Exists(resultsFileName)) { throw new StackHashException("Debugger Error: " + m_Debugger.StandardError, StackHashServiceErrorCode.DebuggerError); } // Load in the results. result = StackHashScriptResult.MergeAnalysisDumpFiles(resultsFileName); // Add a script run note to the error index. StackHashNoteEntry note = new StackHashNoteEntry(); // MUST KEEP THIS TEXT THE SAME - because it is used as a search string by the BugTrackerTask. note.Note = String.Format(CultureInfo.CurrentCulture, "Script {0} executed", scriptName); if ((clientData == null) || (clientData.ClientName == null)) { note.Source = "Service"; note.User = "******"; } else { note.Source = "StackHash Client"; note.User = clientData.ClientName; } note.TimeOfEntry = timeOfRun; int cabNoteId = m_ErrorIndex.AddCabNote(product, file, theEvent, cab, note); // Report the event to bug tracking plug-ins. m_ErrorIndex.AddUpdate(new StackHashBugTrackerUpdate( StackHashDataChanged.DebugScript, StackHashChangeType.NewEntry, product.Id, file.Id, theEvent.Id, theEvent.EventTypeName, cab.Id, cabNoteId)); } catch (System.Exception ex) { // Add a script run note to the error index. StackHashNoteEntry note = new StackHashNoteEntry(); note.Note = String.Format(CultureInfo.CurrentCulture, "Script {0} execution failed: {1}", scriptName, ex.Message); note.Source = "Service"; if ((clientData == null) || (clientData.ClientName == null)) { note.User = "******"; } else { note.User = clientData.ClientName; } note.TimeOfEntry = timeOfRun; m_ErrorIndex.AddCabNote(product, file, theEvent, cab, note); throw; } finally { if (File.Exists(scriptFileName)) { File.Delete(scriptFileName); } } } return(result); }
/// <summary> /// An index will be created in sourceFolder\SourceIndex called SourceIndex. /// It will then be moved to destFolder\DestIndex. /// If defaultDatabaseLocation is specified then only the cab files will be moved and not the SQL database. /// </summary> private void runMoveTask(String settingsFolder, String sourceErrorIndexFolder, String sourceErrorIndexName, String destErrorIndexFolder, String destErrorIndexName, bool defaultDatabaseLocation, StackHashTestIndexData testIndexData) { String scriptFolder = settingsFolder + "\\Scripts"; SqlCommands sqlCommands = new SqlCommands(m_ProviderFactory, s_MasterConnectionString, s_MasterConnectionString, 1); // Create the source database folders and settings. if (sqlCommands.DatabaseExists(destErrorIndexName)) { try { sqlCommands.DeleteDatabase(destErrorIndexName); } catch {; } } if (sqlCommands.DatabaseExists(sourceErrorIndexName)) { try { sqlCommands.DeleteDatabase(sourceErrorIndexName); } catch {; } } if (Directory.Exists(settingsFolder)) { PathUtils.DeleteDirectory(settingsFolder, true); } if (Directory.Exists(destErrorIndexFolder)) { PathUtils.DeleteDirectory(destErrorIndexFolder, true); } if (Directory.Exists(sourceErrorIndexFolder)) { PathUtils.DeleteDirectory(sourceErrorIndexFolder, true); } if (!Directory.Exists(sourceErrorIndexFolder)) { Directory.CreateDirectory(sourceErrorIndexFolder); } if (!Directory.Exists(settingsFolder)) { Directory.CreateDirectory(settingsFolder); } if (!Directory.Exists(scriptFolder)) { Directory.CreateDirectory(scriptFolder); } if (!Directory.Exists(destErrorIndexFolder)) { Directory.CreateDirectory(destErrorIndexFolder); } try { // Create a settings manager and a new context. SettingsManager settingsManager = new SettingsManager(settingsFolder + "\\ServiceSettings.XML"); StackHashContextSettings contextSettings = settingsManager.CreateNewContextSettings(); contextSettings.ErrorIndexSettings = new ErrorIndexSettings(); contextSettings.ErrorIndexSettings.Folder = sourceErrorIndexFolder; contextSettings.ErrorIndexSettings.Name = sourceErrorIndexName; contextSettings.ErrorIndexSettings.Type = ErrorIndexType.SqlExpress; contextSettings.SqlSettings = StackHashSqlConfiguration.Default; contextSettings.SqlSettings.ConnectionString = s_ConnectionString; contextSettings.SqlSettings.InitialCatalog = sourceErrorIndexName; ScriptManager scriptManager = new ScriptManager(scriptFolder); string licenseFileName = string.Format("{0}\\License.bin", settingsFolder); LicenseManager licenseManager = new LicenseManager(licenseFileName, s_ServiceGuid); licenseManager.SetLicense(s_LicenseId); // Create a dummy controller to record the callbacks. BugTrackerManager bugTrackerManager = new BugTrackerManager(new String[0]); // Create a dummy controller to record the callbacks. ControllerContext controllerContext = new ControllerContext(contextSettings, scriptManager, new Windbg(), settingsManager, true, null, licenseManager); // Hook up to receive admin reports. controllerContext.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); // Progress reports don't come through the controller context - they come straight through the contoller so create a dummy. Controller controller = new Controller(); Reporter reporter = new Reporter(controller); controller.AdminReports += new EventHandler <AdminReportEventArgs>(this.OnAdminReport); // ****************************************** // CREATE THE SOURCE INDEX // ****************************************** // Delete any old index first. SqlConnection.ClearAllPools(); try { controllerContext.DeleteIndex(); } catch {; } // Activate the context and the associated index - this will create the index if necessary. controllerContext.Activate(null, defaultDatabaseLocation); String[] databaseFiles = Directory.GetFiles(Path.Combine(sourceErrorIndexFolder, sourceErrorIndexName), "*.mdf"); Assert.AreEqual(defaultDatabaseLocation, databaseFiles.Length == 0); controllerContext.CreateTestIndex(testIndexData); Guid guid = new Guid(); StackHashClientData clientData = new StackHashClientData(guid, "GuidName", 1); // ****************************************** // MOVE TO DESTINATION // ****************************************** // Deactivate before the move. controllerContext.Deactivate(); StackHashSqlConfiguration sqlConfig = new StackHashSqlConfiguration(s_ConnectionString, destErrorIndexName, 1, 100, 15, 100); // Move the index. controllerContext.RunMoveIndexTask(clientData, destErrorIndexFolder, destErrorIndexName, sqlConfig); // Wait for the move task to complete. waitForMoveCompleted(60000 * 20); 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.ErrorIndexMoveStarted, m_AdminReports[0].Report.Operation); Assert.AreEqual(0, m_AdminReports[1].Report.ContextId); Assert.AreEqual(StackHashAdminOperation.ErrorIndexMoveCompleted, m_AdminReports[1].Report.Operation); Assert.AreEqual(null, m_AdminReports[1].Report.LastException); Assert.AreEqual(StackHashServiceErrorCode.NoError, m_AdminReports[1].Report.ServiceErrorCode); if ((testIndexData.NumberOfCabs > 0) && (sourceErrorIndexFolder[0] != destErrorIndexFolder[0])) { Assert.AreEqual(true, m_MoveAdminReports.Count > 0); } controllerContext.AdminReports -= new EventHandler <AdminReportEventArgs>(this.OnAdminReport); ErrorIndexSettings destIndexData = new ErrorIndexSettings() { Folder = destErrorIndexFolder, Name = destErrorIndexName, Type = ErrorIndexType.SqlExpress }; IErrorIndex index1 = getIndex(destIndexData, sqlConfig); try { index1.Activate(); // Make a single call just to ensure the database is still in tact. StackHashProductCollection products = index1.LoadProductList(); Assert.AreEqual(testIndexData.NumberOfProducts, products.Count); } finally { index1.Deactivate(); index1.Dispose(); SqlConnection.ClearAllPools(); } } finally { SqlConnection.ClearAllPools(); if (sqlCommands.DatabaseExists(destErrorIndexName)) { try { sqlCommands.DeleteDatabase(destErrorIndexName); } catch {; } } if (sqlCommands.DatabaseExists(sourceErrorIndexName)) { try { sqlCommands.DeleteDatabase(sourceErrorIndexName); } catch {; } } SqlConnection.ClearAllPools(); if (Directory.Exists(sourceErrorIndexFolder)) { PathUtils.SetFilesWritable(sourceErrorIndexFolder, true); PathUtils.DeleteDirectory(sourceErrorIndexFolder, true); } if (Directory.Exists(destErrorIndexFolder)) { PathUtils.SetFilesWritable(destErrorIndexFolder, true); PathUtils.DeleteDirectory(destErrorIndexFolder, true); } if (Directory.Exists(settingsFolder)) { PathUtils.SetFilesWritable(settingsFolder, true); PathUtils.DeleteDirectory(settingsFolder, true); } } }
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); } } }