/// Gets the search results and displays on the screen. /// </summary> /// <param name="criteria">The job search criteria.</param> private void PopulateData(JobSearchCriteria criteria) { // 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(); DashboardJob dashboardJob = service.GetJobList(criteria); if (dashboardJob != null && dashboardJob.Jobs.Count() > 0) { divSearchResults.Visible = true; ResultsOverviewLabel.Text = String.Format(Constants.StringFormats.ResultsOverviewStringFormat, dashboardJob.CurrentPageNo, dashboardJob.TotalPages, dashboardJob.TotalRecords); SetupPageNavButtons(dashboardJob.TotalPages, dashboardJob.CurrentPageNo); gridJobs.DataSource = dashboardJob.Jobs; gridJobs.DataBind(); } else { DisplayNoResults(); } } else { ResultsOverviewLabel.Text = "The service account cannot be impersonated."; } } catch (Exception ex) { ResultsOverviewLabel.Text = ex.Message + "\n" + ex.StackTrace; } finally { if (context != null) { IMS.NCS.CourseSearchService.Common.Utilities.UndoImpersonation(context); } } }
/// <summary> /// Gets a list of Jobs for the search criteria. /// </summary> /// <param name="searchCriteria">The search criteria.</param> /// <returns>A DashboardJob of data.</returns> DashboardJob IDashboardGateway.GetJobList(JobSearchCriteria searchCriteria) { DashboardJob dashboardJob = new DashboardJob(); using (SqlConnection sqlConnection = new SqlConnection(Utilities.GetDatabaseConnection())) { using (SqlCommand command = new SqlCommand()) { command.Connection = sqlConnection; command.CommandType = CommandType.StoredProcedure; command.CommandText = Constants.Database.UspGetJobsByCriteria; if (searchCriteria.StartDate != DateTime.MinValue) { AddParameter(command, SqlDbType.DateTime, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.StartDate, searchCriteria.StartDate); } else { AddParameter(command, SqlDbType.DateTime, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.StartDate, DBNull.Value); } if (searchCriteria.EndDate != DateTime.MinValue) { AddParameter(command, SqlDbType.DateTime, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.EndDate, searchCriteria.EndDate); } else { AddParameter(command, SqlDbType.DateTime, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.EndDate, DBNull.Value); } AddBoolParameter(command, SqlDbType.Bit, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.InProgressJobs, searchCriteria.InProgressJobs); AddBoolParameter(command, SqlDbType.Bit, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.CompletedJobs, searchCriteria.CompletedJobs); AddBoolParameter(command, SqlDbType.Bit, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.FailedJobs, searchCriteria.FailedJobs); AddParameter(command, SqlDbType.VarChar, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.SortBy, searchCriteria.SortBy); AddParameter(command, SqlDbType.Int, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.NoOfRecords, searchCriteria.RecordsPerPage); AddParameter(command, SqlDbType.Int, ParameterDirection.Input, Constants.UspGetJobsByCriteriaParameters.PageNo, searchCriteria.NextPage); AddParameter(command, SqlDbType.Int, ParameterDirection.Output, Constants.UspGetJobsByCriteriaParameters.TotalRows); command.Connection.Open(); SqlDataReader reader = command.ExecuteReader(); List <Job> jobsList = new List <Job>(); while (reader.Read()) { Job job = new Job(); job.CurrentStep = (string)reader[Constants.UspGetJobsByCriteriaColumns.CurrentStep]; object tempObj = reader[Constants.UspGetJobsByCriteriaColumns.ElapsedTime]; if (tempObj != DBNull.Value) { job.ElapsedTime = (long)tempObj; } tempObj = reader[Constants.UspGetJobsByCriteriaColumns.JobId]; if (tempObj != DBNull.Value) { job.JobId = (int)reader[Constants.UspGetJobsByCriteriaColumns.JobId]; } tempObj = reader[Constants.UspGetJobsByCriteriaColumns.JobName]; if (tempObj != DBNull.Value) { job.JobName = (string)reader[Constants.UspGetJobsByCriteriaColumns.JobName]; } tempObj = reader[Constants.UspGetJobsByCriteriaColumns.ProcessEnd]; if (tempObj != DBNull.Value) { job.ProcessEnd = (DateTime)reader[Constants.UspGetJobsByCriteriaColumns.ProcessEnd]; } tempObj = reader[Constants.UspGetJobsByCriteriaColumns.ProcessStart]; if (tempObj != DBNull.Value) { job.ProcessStart = (DateTime)reader[Constants.UspGetJobsByCriteriaColumns.ProcessStart]; } job.Status = (string)reader[Constants.UspGetJobsByCriteriaColumns.Status]; jobsList.Add(job); } // need to close the reader to get hold of the output params // and create our paging values reader.Close(); dashboardJob.CurrentPageNo = searchCriteria.NextPage; dashboardJob.TotalRecords = Int32.Parse(GetOutputParameter(command, Constants.UspGetJobsByCriteriaParameters.TotalRows)); var result = Decimal.Divide((decimal)dashboardJob.TotalRecords, (decimal)searchCriteria.RecordsPerPage); var totalPages = Math.Ceiling((decimal)result); dashboardJob.TotalPages = (int)totalPages; command.Connection.Close(); dashboardJob.Jobs = jobsList; } } return(dashboardJob); }