private DiagnoserSessionStub CreateDiagnoserSession(string type, int numFiles, DiagnosisStatus collectStatus, DiagnosisStatus analyzeStatus) { DiagnoserSessionStub d = new DiagnoserSessionStub { Diagnoser = new DiagnoserStub(type + "LogsDiag"), CollectorDiagnosisStatus = collectStatus, AnalyzerDiagnosisStatus = analyzeStatus }; for (int i = 0; i < numFiles; i++) { d.AddLog(new LogStub { StartTime = DateTime.Now, EndTime = DateTime.Now, FileName = type + "Log" + i + ".txt", FullPath = @"\\path\to\" + type + "Log" + i + ".txt" }); d.AddReport(new ReportStub { FileName = "httpReport" + i + ".txt", FullPath = @"\\path\to\" + type + "Report" + i + ".txt" }); } return(d); }
private void LoadDiagnoserFromXml(XElement diagnoserXml) { var diagnoserName = diagnoserXml.Attribute(SessionXml.Name).Value; var allDiagnosers = Infrastructure.Settings.GetDiagnosers(); Diagnoser = allDiagnosers.FirstOrDefault(d => d.Name.Equals(diagnoserName, StringComparison.OrdinalIgnoreCase)); if (Diagnoser == null) { // The settings file has changed so that this diagnoser no longer exists. // We can no longer analyze this session but we'll create a mock diagnoser that no-ops on everything Diagnoser = new Diagnoser() { Name = diagnoserName, Collector = new RangeCollector() { Arguments = "", Command = "", Name = "" }, Analyzer = new Analyzer() { Arguments = "", Command = "", Name = "MockAnalyzer" } }; } var collectorXml = diagnoserXml.Element(SessionXml.Collector); var analyzerXml = diagnoserXml.Element(SessionXml.Analyzer); DiagnosisStatus collectorStatus; DiagnosisStatus.TryParse( collectorXml.Attribute(SessionXml.Status).Value, ignoreCase: true, result: out collectorStatus); CollectorStatus = collectorStatus; if (collectorStatus == DiagnosisStatus.InProgress) { CheckAndReturnCollectorDetailedStatus(diagnoserXml); } var collectorRunCountXml = collectorXml.Attribute(SessionXml.RunCount); if (collectorRunCountXml != null && !string.IsNullOrEmpty(collectorRunCountXml.Value)) { _collectorRunCount = int.Parse(collectorRunCountXml.Value); } _collectorFailureCount = int.Parse(collectorXml.Attribute(SessionXml.FailureCount).Value); foreach (var errorXml in collectorXml.Elements(SessionXml.Error)) { _collectorErrors.Add(errorXml.Value); } DiagnosisStatus analyzerStatus; DiagnosisStatus.TryParse( analyzerXml.Attribute(SessionXml.Status).Value, ignoreCase: true, result: out analyzerStatus); AnalyzerStatus = analyzerStatus; if (analyzerXml.Attribute(SessionXml.AnalyzerStartTime) != null) { if (DateTime.TryParse(analyzerXml.Attribute(SessionXml.AnalyzerStartTime).Value, out DateTime analyzerStartTime)) { AnalyzerStartTime = analyzerStartTime.ToUniversalTime(); } } var analyzerRunCountXml = analyzerXml.Attribute(SessionXml.RunCount); if (analyzerRunCountXml != null && !string.IsNullOrEmpty(analyzerRunCountXml.Value)) { _analyzerRunCount = int.Parse(analyzerRunCountXml.Value); } _analyzerFailureCount = int.Parse(analyzerXml.Attribute(SessionXml.FailureCount).Value); foreach (var errorXml in analyzerXml.Elements(SessionXml.Error)) { _analyzerErrors.Add(errorXml.Value); } var logsXml = diagnoserXml.Element(SessionXml.Logs); if (logsXml != null) { foreach (var logXml in logsXml.Elements(SessionXml.Log)) { var logPath = logXml.Attribute(SessionXml.Path).Value; double fileSize = 0; if (logXml.Attribute(SessionXml.FileSize) != null) { double.TryParse(logXml.Attribute(SessionXml.FileSize).Value, out fileSize); } string blobSasUri = string.Empty; if (logXml.Attribute(SessionXml.BlobSasUri) != null) { blobSasUri = logXml.Attribute(SessionXml.BlobSasUri).Value; } var log = Log.GetLogFromPermanentStorage(logPath, fileSize, blobSasUri); if (logXml.Attribute(SessionXml.AnalysisStarted) != null) { if (DateTime.TryParse(logXml.Attribute(SessionXml.AnalysisStarted).Value, out DateTime analysisStarted)) { log.AnalysisStarted = analysisStarted.ToUniversalTime(); } } if (logXml.Attribute(SessionXml.InstanceAnalyzing) != null) { log.InstanceAnalyzing = logXml.Attribute(SessionXml.InstanceAnalyzing).Value; } AddLog(log); if (analyzerStatus == DiagnosisStatus.InProgress) { CheckAndReturnAnalyzerDetailedStatus(log); } foreach (var reportXml in logXml.Elements(SessionXml.Report)) { var reportPath = reportXml.Attribute(SessionXml.Path).Value; var report = Report.GetReport(reportPath); AddReportForLog(log, report); } } } }