public ActionResult ViewLog(int id) { Job job; using (var repo = new JobRepository()) { job = repo.GetJobById(id); } if (job == null) { return Content("Job not found."); } string logFileName = "Deploy_" + job.Name + "_" + job.Id + ".log"; string logFile = Path.Combine(_logDirectory, logFileName); if (System.IO.File.Exists(logFile)) { string allText = System.IO.File.ReadAllText(logFile); var viewModel = new DeploymentLogViewModel { JobId = job.Id.ToString(), DeploymentLog = allText, LogName = job.Name }; return View(viewModel); } return Content("File not found."); }
public static Job GetJob(int jobId, Logger defaultLogger) { Job currentJob; using (var repo = new JobRepository()) { defaultLogger.Info("Passed job with ID of {0}", jobId); currentJob = repo.GetJobById(jobId); if (currentJob == null) { defaultLogger.Warn("Job not found"); return null; } defaultLogger.Info("Job found. URL is {0} and branch is {1}", currentJob.Url, currentJob.Branch); if (currentJob.State != JobState.Pending) { defaultLogger.Warn("Cannot start job. Current state is {0}", currentJob.State); return null; } repo.UpdateStateForJob(currentJob, JobState.Running); } return currentJob; }