Beispiel #1
0
        public List <HistoryModel> GetJobHistoryForJobName(string jobName, string result = null)
        {
            List <HistoryModel> jobHistory = new List <HistoryModel>();
            SqlCommand          cmd        = GetDbcommand();

            cmd.CommandText = @"SELECT * FROM WAM.dbo.JobHistory WHERE JobType = @jobName ORDER BY DateRan DESC";
            if (result != null)
            {
                cmd.CommandText = @"SELECT * FROM WAM.dbo.JobHistory WHERE JobType = @jobName AND Status = @result ORDER BY DateRan DESC";
                cmd.Parameters.AddWithValue("@result", result);
            }
            cmd.Parameters.AddWithValue("@jobName", jobName);
            try
            {
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    HistoryModel m = BuildHistoryItem(reader);
                    jobHistory.Add(m);
                }
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to retrieve JobHistory. Error: {ex.Message}");
            }
            return(jobHistory);
        }
Beispiel #2
0
        private HistoryModel BuildHistoryItem(SqlDataReader reader)
        {
            HistoryModel m = new HistoryModel(
                (Guid)reader["Id"],
                (string)reader["JobType"],
                (string)reader["JobName"],
                (string)reader["DateRan"],
                (string)reader["Status"]
                );

            if (!(reader["Error"] is DBNull))
            {
                m.Error = (string)reader["Error"];
            }
            return(m);
        }
Beispiel #3
0
        public List <HistoryModel> GetAllJobHistory()
        {
            List <HistoryModel> jobHistory = new List <HistoryModel>();
            SqlCommand          cmd        = GetDbcommand();

            cmd.CommandText = @"SELECT * FROM WAM.dbo.JobHistory ORDER BY DateRan DESC";
            //cmd.Parameters.AddWithValue("@Id", newGuid);
            try
            {
                cmd.Connection.Open();
                SqlDataReader reader = cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
                while (reader.Read())
                {
                    HistoryModel m = BuildHistoryItem(reader);
                    jobHistory.Add(m);
                }
                cmd.Connection.Close();
            }
            catch (Exception ex)
            {
                throw new Exception($"Failed to retrieve JobHistory. Error: {ex.Message}");
            }
            return(jobHistory);
        }