/// <summary> /// Gets the Job and Step details for a Job. /// </summary> /// <param name="jobId">The id of the Job.</param> /// <returns>A Job and list of Steps for that Job.</returns> DashboardDetailJob IDashboardGateway.GetJobDetails(int jobId) { bool result; Int64 elapsedTime; DashboardDetailJob detailsJob = null; DateTime dateTimeResult; using (SqlConnection sqlConnection = new SqlConnection(Utilities.GetDatabaseConnection())) { using (SqlCommand command = new SqlCommand()) { command.Connection = sqlConnection; command.CommandType = CommandType.StoredProcedure; command.CommandText = Constants.Database.UspGetJobByJobId; AddParameter(command, SqlDbType.Int, ParameterDirection.Input, Constants.UspGetJobByJobIdParameters.JobId, jobId); AddParameter(command, SqlDbType.VarChar, ParameterDirection.Output, Constants.UspGetJobByJobIdParameters.JobName); AddParameter(command, SqlDbType.DateTime, ParameterDirection.Output, Constants.UspGetJobByJobIdParameters.JobProcessStart); AddParameter(command, SqlDbType.DateTime, ParameterDirection.Output, Constants.UspGetJobByJobIdParameters.JobProcessEnd); AddParameter(command, SqlDbType.BigInt, ParameterDirection.Output, Constants.UspGetJobByJobIdParameters.JobElapsedTime); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); Job job = new Job(); List <JobStep> steps = new List <JobStep>(); // and get our Step data from the data set sent back while (reader.Read()) { JobStep step = new JobStep(); result = Int64.TryParse(reader[Constants.UspGetJobByJobIdColumns.StepElapsedTime].ToString(), out elapsedTime); if (result) { step.ElapsedTime = elapsedTime; } result = DateTime.TryParse(reader[Constants.UspGetJobByJobIdColumns.StepProcessEnd].ToString(), out dateTimeResult); if (result) { step.ProcessEnd = dateTimeResult; } result = DateTime.TryParse(reader[Constants.UspGetJobByJobIdColumns.StepProcessStart].ToString(), out dateTimeResult); if (result) { step.ProcessStart = dateTimeResult; } step.Status = (string)reader[Constants.UspGetJobByJobIdColumns.Status]; step.StepName = (string)reader[Constants.UspGetJobByJobIdColumns.StepName]; steps.Add(step); } // need to close the reader to get hold of the output params // and create our Job details reader.Close(); job.JobId = jobId; job.JobName = GetOutputParameter(command, Constants.UspGetJobByJobIdParameters.JobName); result = DateTime.TryParse(GetOutputParameter(command, Constants.UspGetJobByJobIdParameters.JobProcessStart), out dateTimeResult); if (result) { job.ProcessStart = dateTimeResult; } result = DateTime.TryParse(GetOutputParameter(command, Constants.UspGetJobByJobIdParameters.JobProcessEnd), out dateTimeResult); if (result) { job.ProcessEnd = dateTimeResult; } result = Int64.TryParse(GetOutputParameter(command, Constants.UspGetJobByJobIdParameters.JobElapsedTime), out elapsedTime); if (result) { job.ElapsedTime = elapsedTime; } command.Connection.Close(); detailsJob = new DashboardDetailJob(); detailsJob.DetailJob = job; detailsJob.Steps = steps; } } return(detailsJob); }
/// <summary> /// Retrieves the Job data for the Job Id passed in and displays the data /// </summary> /// <param name="jobId">The id of the Job to view.</param> private void PopulateData(int jobId) { // get some results // need to impersonate as the service account so we can access the Import Control database. string serviceAccount = ConfigurationManager.AppSettings[Constants.ConfigurationKeys.ServiceAccount].ToString(); string domain = ConfigurationManager.AppSettings[Constants.ConfigurationKeys.ServiceAccountDomain].ToString(); string password = ConfigurationManager.AppSettings[Constants.ConfigurationKeys.ServiceAccountPassword].ToString(); WindowsImpersonationContext context = null; try { context = IMS.NCS.CourseSearchService.Common.Utilities.impersonateValidUser(serviceAccount, domain, password); if (context != null) { IDashboardService service = new DashboardService(); DashboardDetailJob jobDetails = service.GetJobDetails(jobId); if (jobDetails != null && jobDetails.DetailJob != null) { JobTitle.Text = "JOB - " + jobDetails.DetailJob.JobName; JobId.Text = jobDetails.DetailJob.JobId.ToString(); TimeElapsed.Text = jobDetails.DetailJob.ElapsedTime.ToString(); if (jobDetails.DetailJob.ProcessStart != null) { StartDate.Text = jobDetails.DetailJob.ProcessStart.ToString("dd/MM/yyyy HH:mm:ss"); } else { StartDate.Text = "N/A"; } if (jobDetails.DetailJob.ProcessEnd != null) { EndDate.Text = jobDetails.DetailJob.ProcessEnd.ToString("dd/MM/yyyy HH:mm:ss"); } else { EndDate.Text = "N/A"; } divResults.Visible = true; gridSteps.DataSource = jobDetails.Steps; gridSteps.DataBind(); } else { divResults.Visible = false; ResultsOverviewLabel.Text = "There are no results to display."; } } } catch (Exception ex) { ResultsOverviewLabel.Text = ex.Message + "\n" + ex.StackTrace; } finally { if (context != null) { IMS.NCS.CourseSearchService.Common.Utilities.UndoImpersonation(context); } } }