public HttpResponseMessage Get(string sessionId, bool detailed) { SessionDetails retVal = new SessionDetails(); try { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)); retVal.Description = session.Description; retVal.SessionId = session.SessionId.ToString(); retVal.StartTime = session.StartTime.ToString("yyyy-MM-dd HH:mm:ss"); retVal.EndTime = session.EndTime.ToString("yyyy-MM-dd HH:mm:ss"); retVal.Status = session.Status; retVal.HasBlobSasUri = !string.IsNullOrWhiteSpace(session.BlobSasUri); foreach (DiagnoserSession diagSession in session.GetDiagnoserSessions()) { DiagnoserSessionDetails diagSessionDetails = new DiagnoserSessionDetails { Name = diagSession.Diagnoser.Name, CollectorStatus = diagSession.CollectorStatus, AnalyzerStatus = diagSession.AnalyzerStatus, CollectorStatusMessages = diagSession.CollectorStatusMessages, AnalyzerStatusMessages = diagSession.AnalyzerStatusMessages }; foreach (String analyzerError in diagSession.GetAnalyzerErrors()) { diagSessionDetails.AddAnalyzerError(analyzerError); } foreach (String collectorError in diagSession.GetCollectorErrors()) { diagSessionDetails.AddCollectorError(collectorError); } int minLogRelativePathSegments = Int32.MaxValue; double logFileSize = 0; foreach (Log log in diagSession.GetLogs()) { logFileSize += log.FileSize; LogDetails logDetails = new LogDetails { FileName = log.FileName, RelativePath = log.RelativePath, FullPermanentStoragePath = log.FullPermanentStoragePath, StartTime = log.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime = log.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }; int relativePathSegments = logDetails.RelativePath.Split('\\').Length; if (relativePathSegments == minLogRelativePathSegments) { logDetails.RelativePath = logDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.AddLog(logDetails); } else if (relativePathSegments < minLogRelativePathSegments) { minLogRelativePathSegments = relativePathSegments; logDetails.RelativePath = logDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.ClearReports(); diagSessionDetails.AddLog(logDetails); } } retVal.LogFilesSize = logFileSize; int minReportRelativePathSegments = Int32.MaxValue; foreach (Report report in diagSession.GetReports()) { ReportDetails reportDetails = new ReportDetails { FileName = report.FileName, RelativePath = report.RelativePath, FullPermanentStoragePath = report.FullPermanentStoragePath }; int relativePathSegments = reportDetails.RelativePath.Split('\\').Length; if (relativePathSegments == minReportRelativePathSegments) { reportDetails.RelativePath = reportDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.AddReport(reportDetails); } else if (relativePathSegments < minReportRelativePathSegments) { minReportRelativePathSegments = relativePathSegments; reportDetails.RelativePath = reportDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.ClearReports(); diagSessionDetails.AddReport(reportDetails); } } retVal.AddDiagnoser(diagSessionDetails); } } catch (FileNotFoundException fex) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, fex.Message)); } catch (Exception ex) { Logger.LogSessionErrorEvent("Encountered exception while getting session", ex, sessionId); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex.Message)); } return(Request.CreateResponse(HttpStatusCode.OK, retVal)); }
public DiagnoserSessionDetails Get(string sessionId, string diagnoser, bool detailed) { SessionController sessionController = new SessionController(); Session session = sessionController.GetSessionWithId(new SessionId(sessionId)); DiagnoserSession diagSession = session.GetDiagnoserSessions().First(p => p.Diagnoser.Name.Equals(diagnoser, StringComparison.OrdinalIgnoreCase)); DiagnoserSessionDetails retVal = new DiagnoserSessionDetails { Name = diagSession.Diagnoser.Name, CollectorStatus = diagSession.CollectorStatus, AnalyzerStatus = diagSession.AnalyzerStatus, CollectorStatusMessages = diagSession.CollectorStatusMessages, AnalyzerStatusMessages = diagSession.AnalyzerStatusMessages }; foreach (String analyzerError in diagSession.GetAnalyzerErrors()) { retVal.AddAnalyzerError(analyzerError); } foreach (String collectorError in diagSession.GetCollectorErrors()) { retVal.AddCollectorError(collectorError); } int minLogRelativePathSegments = Int32.MaxValue; foreach (Log log in diagSession.GetLogs()) { LogDetails temp = new LogDetails { FileName = log.FileName, RelativePath = log.RelativePath, FullPermanentStoragePath = log.FullPermanentStoragePath, StartTime = log.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime = log.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }; int relativePathSegments = temp.RelativePath.Split('\\').Length; if (relativePathSegments == minLogRelativePathSegments) { temp.RelativePath = temp.RelativePath.Replace('\\', '/'); retVal.AddLog(temp); } else if (relativePathSegments < minLogRelativePathSegments) { minLogRelativePathSegments = relativePathSegments; temp.RelativePath = temp.RelativePath.Replace('\\', '/'); retVal.ClearReports(); retVal.AddLog(temp); } } int minReportRelativePathSegments = Int32.MaxValue; foreach (Report report in diagSession.GetReports()) { ReportDetails temp = new ReportDetails { FileName = report.FileName, RelativePath = report.RelativePath, FullPermanentStoragePath = report.FullPermanentStoragePath }; int relativePathSegments = temp.RelativePath.Split('\\').Length; if (relativePathSegments == minReportRelativePathSegments) { temp.RelativePath = temp.RelativePath.Replace('\\', '/'); retVal.AddReport(temp); } else if (relativePathSegments < minReportRelativePathSegments) { minReportRelativePathSegments = relativePathSegments; temp.RelativePath = temp.RelativePath.Replace('\\', '/'); retVal.ClearReports(); retVal.AddReport(temp); } } return(retVal); }
public HttpResponseMessage Get(string type, bool detailed) { List <SessionDetails> retVal = new List <SessionDetails>(); try { SessionController sessionController = new SessionController(); IEnumerable <Session> sessions; switch (type.ToLowerInvariant()) { case "all": sessions = sessionController.GetAllSessions(); break; case "pending": sessions = sessionController.GetAllActiveSessions(); break; case "needanalysis": sessions = sessionController.GetAllUnanalyzedSessions(); break; case "complete": sessions = sessionController.GetAllCompletedSessions(); break; default: sessions = sessionController.GetAllSessions(); break; } IEnumerable <Session> sortedSessions = sessions.OrderByDescending(p => p.StartTime); foreach (Session session in sortedSessions) { SessionDetails sessionDetails = new SessionDetails { Description = session.Description, SessionId = session.SessionId.ToString(), StartTime = session.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime = session.EndTime.ToString("yyyy-MM-dd HH:mm:ss"), Status = session.Status, HasBlobSasUri = !string.IsNullOrWhiteSpace(session.BlobSasUri) }; foreach (DiagnoserSession diagSession in session.GetDiagnoserSessions()) { DiagnoserSessionDetails diagSessionDetails = new DiagnoserSessionDetails { Name = diagSession.Diagnoser.Name, CollectorStatus = diagSession.CollectorStatus, AnalyzerStatus = diagSession.AnalyzerStatus, CollectorStatusMessages = diagSession.CollectorStatusMessages, AnalyzerStatusMessages = diagSession.AnalyzerStatusMessages }; foreach (String analyzerError in diagSession.GetAnalyzerErrors()) { diagSessionDetails.AddAnalyzerError(analyzerError); } foreach (String collectorError in diagSession.GetCollectorErrors()) { diagSessionDetails.AddCollectorError(collectorError); } int minLogRelativePathSegments = Int32.MaxValue; double logFileSize = 0; foreach (Log log in diagSession.GetLogs()) { logFileSize += log.FileSize; LogDetails logDetails = new LogDetails { FileName = log.FileName, RelativePath = log.RelativePath, FullPermanentStoragePath = log.FullPermanentStoragePath, StartTime = log.StartTime.ToString("yyyy-MM-dd HH:mm:ss"), EndTime = log.EndTime.ToString("yyyy-MM-dd HH:mm:ss") }; int relativePathSegments = logDetails.RelativePath.Split('\\').Length; if (relativePathSegments == minLogRelativePathSegments) { logDetails.RelativePath = logDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.AddLog(logDetails); } else if (relativePathSegments < minLogRelativePathSegments) { minLogRelativePathSegments = relativePathSegments; logDetails.RelativePath = logDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.ClearReports(); diagSessionDetails.AddLog(logDetails); } } sessionDetails.LogFilesSize = logFileSize; int minReportRelativePathSegments = Int32.MaxValue; foreach (Report report in diagSession.GetReports()) { ReportDetails reportDetails = new ReportDetails { FileName = report.FileName, RelativePath = report.RelativePath, FullPermanentStoragePath = report.FullPermanentStoragePath }; int relativePathSegments = reportDetails.RelativePath.Split('\\').Length; if (relativePathSegments == minReportRelativePathSegments) { reportDetails.RelativePath = reportDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.AddReport(reportDetails); } else if (relativePathSegments < minReportRelativePathSegments) { minReportRelativePathSegments = relativePathSegments; reportDetails.RelativePath = reportDetails.RelativePath.Replace('\\', '/'); diagSessionDetails.ClearReports(); diagSessionDetails.AddReport(reportDetails); } } sessionDetails.AddDiagnoser(diagSessionDetails); } retVal.Add(sessionDetails); } } catch (Exception ex) { Logger.LogErrorEvent("Encountered exception while getting sessions from file", ex); return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, $"Encountered exception {ex.Message} while getting sessions from file")); } return(Request.CreateResponse(HttpStatusCode.OK, retVal)); }