/// <summary> /// Updates the statistics related to the task in the specified index. /// The stats relate to tasks that have been run on that index. /// </summary> /// <param name="index">Index to update.</param> public void UpdateTaskCompletedStatistics(IErrorIndex index) { if ((index != null) && (index.Status == ErrorIndexStatus.Created)) { StackHashTaskStatus taskStatus = index.GetTaskStatistics(this.TaskType); taskStatus.TaskState = StackHashTaskState.Completed; taskStatus.ServiceErrorCode = StackHashException.GetServiceErrorCode(this.LastException); if (this.LastException != null) { taskStatus.FailedCount++; taskStatus.LastFailedRunTimeUtc = taskStatus.LastStartedTimeUtc; taskStatus.LastException = this.LastException.ToString(); } else { taskStatus.SuccessCount++; taskStatus.LastSuccessfulRunTimeUtc = taskStatus.LastStartedTimeUtc; } taskStatus.LastDurationInSeconds = (int)(DateTime.Now.ToUniversalTime() - taskStatus.LastStartedTimeUtc).TotalSeconds; taskStatus.TaskState = StackHashTaskState.Completed; index.SetTaskStatistics(taskStatus); } }
public void ProvideFault(Exception error, System.ServiceModel.Channels.MessageVersion version, ref System.ServiceModel.Channels.Message fault) { if (m_ReentrancyCheck) { return; } m_ReentrancyCheck = true; try { if ((fault == null) && (error != null)) { ReceiverFaultDetail receiverFaultDetail = new ReceiverFaultDetail( error.Message, getDescription(error), StackHashException.GetServiceErrorCode(error)); FaultException <ReceiverFaultDetail> fe = new FaultException <ReceiverFaultDetail>( receiverFaultDetail, error.Message, FaultCode.CreateReceiverFaultCode(new FaultCode("ReceiverFault"))); MessageFault mf = fe.CreateMessageFault(); fault = Message.CreateMessage(version, mf, fe.Action); try { DiagnosticsHelper.LogException(DiagSeverity.Warning, "Service exception occurred", error); } catch (System.Exception) { // Ignore the error. } } } finally { m_ReentrancyCheck = false; } }
public void RunScriptOnCorruptCab() { // Create an index with 1 cab file. XmlErrorIndex errorIndex = new XmlErrorIndex(m_TempPath, "ErrorIndex"); errorIndex.Activate(); StackHashTestIndexData testData = new StackHashTestIndexData(); testData.NumberOfProducts = 1; testData.NumberOfFiles = 1; testData.NumberOfEvents = 1; testData.NumberOfEventInfos = 1; testData.NumberOfCabs = 1; testData.UseLargeCab = false; TestManager.CreateTestIndex(errorIndex, testData); // Delete the cab file. StackHashProduct product = errorIndex.GetProduct(1); StackHashFile file = errorIndex.GetFile(product, 1); StackHashEventPackageCollection events = errorIndex.GetProductEvents(product); String cabFileName = errorIndex.GetCabFileName(product, file, events[0].EventData, events[0].Cabs[0].Cab); if (File.Exists(cabFileName)) { FileStream fileStream = File.Open(cabFileName, FileMode.Open, FileAccess.ReadWrite); try { fileStream.SetLength(100); } finally { fileStream.Close(); } } ScriptManager scriptManager = new ScriptManager(m_TempPath + "Scripts"); Assert.AreEqual(scriptManager.NumberOfAutoScripts, scriptManager.ScriptNames.Count); ScriptResultsManager scriptResultsManager = new ScriptResultsManager(errorIndex, scriptManager, m_Debugger, m_DebuggerSettings); // Set up parameters for the task. DebugScriptTaskParameters runScriptParams = new DebugScriptTaskParameters(); // Standard task parameters. runScriptParams.IsBackgroundTask = true; runScriptParams.Name = "TestRunOneTask"; runScriptParams.RunInParallel = false; runScriptParams.UseSeparateThread = true; runScriptParams.ContextId = 0; runScriptParams.ClientData = new StackHashClientData(Guid.NewGuid(), "MarkJ", 1); runScriptParams.Debugger = m_Debugger; runScriptParams.TheScriptManager = scriptManager; runScriptParams.TheScriptResultsManager = scriptResultsManager; runScriptParams.Product = product; runScriptParams.File = file; runScriptParams.TheEvent = events[0].EventData; runScriptParams.Cab = events[0].Cabs[0].Cab; runScriptParams.ErrorIndex = errorIndex; // Create the task and run it. DebugScriptTask debugScriptTask = new DebugScriptTask(runScriptParams); TaskManager taskManager = new TaskManager("Test"); taskManager.Enqueue(debugScriptTask); taskManager.WaitForTaskCompletion(debugScriptTask, s_TaskTimeout); Assert.AreEqual(true, debugScriptTask.CurrentTaskState.TaskCompleted); Assert.AreNotEqual(null, debugScriptTask.LastException); Assert.AreEqual(true, debugScriptTask.LastException is StackHashException); StackHashException ex = debugScriptTask.LastException as StackHashException; Assert.AreEqual(StackHashServiceErrorCode.CabIsCorrupt, ex.ServiceErrorCode); StackHashCabCollection cabs = errorIndex.LoadCabList(product, file, events[0].EventData); StackHashDumpAnalysis analysis = cabs[0].DumpAnalysis; }