Esempio n. 1
0
 /// <summary>
 /// This method can be used to get the next job from queue.
 /// </summary>
 /// <param name="jobTypeId">Job Type Id.</param>
 /// <param name="serverId">Job Server Id.</param>
 /// <returns>Next job to run.</returns>
 internal BaseJobBEO GetNextJobFromQueue(int jobTypeId, Guid serverId)
 {
     try
     {
         DataSet dsResult;
         lock (_db)
         {
             // Instantiate the stored procedure to obtain the jobs from load queue.
             var dbCommand = _db.GetStoredProcCommand(Constants.StoredProcedureGetNextJobFromLoadQueue);
             // Add input parameters.
             _db.AddInParameter(dbCommand, Constants.InputParameterJobTypeId, DbType.Int32, jobTypeId);
             _db.AddInParameter(dbCommand, Constants.InputParameterJobServerId, DbType.Guid, serverId);
             // Execute the stored procedure and obtain the result set from the database into a dataset.
             dsResult = _db.ExecuteDataSet(dbCommand);
         }
         // If there is a job to run then set the job parameters appropriately.
         BaseJobBEO jobParameters = null;
         if (null != dsResult)
         {
             if (dsResult.Tables.Count > 0 && dsResult.Tables[Constants.First].Rows.Count > 0)
             {
                 // Create an instance of the job parameters.
                 jobParameters = new BaseJobBEO();
                 // Set the job parameters.
                 var drResult = dsResult.Tables[Constants.First].Rows[Constants.First];
                 jobParameters.JobId          = Convert.ToInt32(drResult[Constants.TableLoadJobQueueColumnJobId]);
                 jobParameters.JobRunId       = Convert.ToInt32(drResult[Constants.TableLoadJobQueueColumnJobRunId]);
                 jobParameters.BootParameters =
                     !Convert.IsDBNull(drResult[Constants.TableLoadJobQueueColumnJobParameters])
                         ? Convert.ToString(drResult[Constants.TableLoadJobQueueColumnJobParameters])
                         : String.Empty;
                 jobParameters.JobScheduleRunDuration =
                     Convert.ToInt32(drResult[Constants.TableLoadJobQueueColumnJobDurationMinutes]);
                 jobParameters.JobTypeId         = jobTypeId;
                 jobParameters.JobNotificationId =
                     !DBNull.Value.Equals(drResult[Constants.TableJobMasterNotificationId])
                         ? Convert.ToInt64(drResult[Constants.TableJobMasterNotificationId])
                         : 0;
                 jobParameters = GetJobDetails(jobParameters);
             }
         }
         // Return the job parameters for the next job to run.
         return(jobParameters);
     }
     catch (Exception ex)
     {
         ex.Trace();
         return(null); // Calling method handles this gracefully.
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Get Task Details.
        /// </summary>
        /// <typeparam name="JobParametersType">JobParametersType</typeparam>
        /// <typeparam name="TaskType">TaskType</typeparam>
        /// <param name="jobParameters">jobParameters</param>
        /// <returns>Tasks<TaskType></returns>
        public static Tasks <TaskType> GetJobTaskDetails <JobParametersType, TaskType>(JobParametersType jobParameters) where TaskType : class, new()
        {
            Tasks <TaskType> tasks = new Tasks <TaskType>();
            int         jobRunId   = Convert.ToInt32(Helper.GetParameterValue(jobParameters, Constants.PropertyNameJobRunId), CultureInfo.CurrentCulture);
            EVDbManager db         = new EVDbManager();
            // Instantiate the stored procedure to update the job status.
            DbCommand dbCommand = db.GetStoredProcCommand(Constants.StoredProcedureGetTaskDetails);

            // Add input parameters.
            db.AddInParameter(dbCommand, Constants.InputParameterJobRunId, DbType.Int32, jobRunId);
            db.AddInParameter(dbCommand, Constants.InputParamertTaskDetailsRequired, DbType.Boolean, false);

            // Execute the stored procedure and obtain the result set from the database into a dataset.
            DataSet  dsResult = db.ExecuteDataSet(dbCommand);
            TaskType task;

            if (dsResult != null && dsResult.Tables.Count > 0 && dsResult.Tables[Constants.First].Rows.Count > 0)
            {
                Helper.SetParameterValue <JobParametersType, double>(jobParameters, Constants.PropertyNameJobProgressPercent, Convert.ToDouble(dsResult.Tables[Constants.First].Rows[Constants.First][Constants.TableOpenJobsColumnProgressPercent], CultureInfo.CurrentCulture));
                foreach (DataRow drResult in dsResult.Tables[Constants.First].Rows)
                {
                    byte[] binaryData = (byte[])drResult[Constants.TableOpenJobsColumnTaskDetails];
                    task = DeserializeObjectBinary <TaskType>(binaryData);
                    Helper.SetParameterValue <TaskType, int>(task, Constants.PropertyNameTaskNumber, Convert.ToInt32(drResult[Constants.TableOpenJobsColumnTaskId], CultureInfo.CurrentCulture));
                    Helper.SetParameterValue <TaskType, bool>(task, Constants.PropertyNameTaskComplete, Convert.ToBoolean(drResult[Constants.TableOpenJobsColumnIsComplete], CultureInfo.CurrentCulture));
                    Helper.SetParameterValue <TaskType, bool>(task, Constants.PropertyNameIsTaskError, Convert.ToBoolean(drResult[Constants.TableOpenJobsColumnIsError], CultureInfo.CurrentCulture));
                    tasks.Add(task);
                }
            }
            // Return the list of tasks.
            return(tasks);
        }
Esempio n. 3
0
        } // End UpdateJobExecutionStatus()

        #endregion



        #region OtherMethods
        /// <summary>
        /// This method is used to Get the Details of a Job SubScription Details.
        /// </summary>
        /// <param name="JobID">Unique Identifier for a job</param>
        /// <returns>JobBusinessEntity</returns>
        public static JobBusinessEntity GetJobSubScriptionDetails(string jobID)
        {
            bool result; int returnFlag;
            JobBusinessEntity jobBEO;
            // Create a new instance of the DB manager.
            EVDbManager DBManager = new EVDbManager();

            DbCommand dbCommand = DBManager.GetStoredProcCommand(Constants.GetJobSubscriptionDetails);

            DBManager.AddInParameter(dbCommand, Constants.InputParameterJobId, DbType.Int32, Convert.ToInt32(jobID));
            DBManager.AddOutParameter(dbCommand, Constants.JobReturnFlagOutParameter, DbType.Int32, 4);

            DataSet dsJobs = DBManager.ExecuteDataSet(dbCommand);

            jobBEO = new JobBusinessEntity();
            result = Int32.TryParse(DBManager.GetParameterValue(dbCommand, Constants.JobReturnFlagOutParameter).ToString(), NumberStyles.Integer, null, out returnFlag);
            if (result)
            {
                if (dsJobs != null && dsJobs.Tables.Count > 0 && dsJobs.Tables[0].Rows.Count > 0)
                {
                    DataRow job = dsJobs.Tables[0].Rows[0];
                    jobBEO.Type       = !Convert.IsDBNull(job[Constants.PropertyNameSubscriptionTypeId]) ? Convert.ToInt32(job[Constants.PropertyNameSubscriptionTypeId]) : 0;
                    jobBEO.TypeName   = !Convert.IsDBNull(job[Constants.PropertyNameSubscriptionTypeName]) ? job[Constants.PropertyNameSubscriptionTypeName].ToString() : string.Empty;
                    jobBEO.FolderID   = Convert.ToInt64(job[Constants.PropertyNameFolderId]);
                    jobBEO.FolderName = job[Constants.PropertyNameFolderName].ToString();
                    jobBEO.Visibility = Convert.ToBoolean(job[Constants.PropertyNameVisibility]);
                    jobBEO.Priority   = Convert.ToInt32(job[Constants.PropertyNamePriority]);
                    jobBEO.Name       = !Convert.IsDBNull(job[Constants.PropertyNameJobName]) ? job[Constants.PropertyNameJobName].ToString() : string.Empty;
                }
            }
            return(jobBEO);
        }
Esempio n. 4
0
        /// <summary>
        /// Get Job Task Log Details.
        /// </summary>
        /// <param name="jobId">Job Identifier</param>
        /// <param name="jobRunId">Job Run Identifier</param>
        /// <param name="taskId">Task Identifier</param>
        /// <returns>LogInfo Xml</returns>
        public static string GetLogDetails(int jobId, int jobRunId, int taskId)
        {
            EVDbManager DBManager = new EVDbManager();
            DbCommand   dbCommand = DBManager.GetStoredProcCommand(Constants.GetLogDetailsProcedure);

            DBManager.AddInParameter(dbCommand, Constants.JobInputParameterJobId, DbType.Int32, jobId);
            DBManager.AddInParameter(dbCommand, Constants.JobInputParameterJobRunId, DbType.Int32, jobRunId);
            DBManager.AddInParameter(dbCommand, Constants.JobInputParameterTaskId, DbType.Int32, taskId);
            DBManager.AddOutParameter(dbCommand, Constants.ParamOutTotalNoOfRecord, DbType.Int32, 4);
            JobBusinessEntity jobBeo = new JobBusinessEntity();
            DataSet           dsJobs = DBManager.ExecuteDataSet(dbCommand);
            int totalNoOfRecords     = Convert.ToInt32(DBManager.GetParameterValue(dbCommand, Constants.ParamOutTotalNoOfRecord), CultureInfo.CurrentCulture);

            if (totalNoOfRecords == -1)
            {
                return(string.Empty);
            }
            if (dsJobs != null && dsJobs.Tables.Count > 0 && dsJobs.Tables[0].Rows.Count > 0)
            {
                return(Convert.IsDBNull(dsJobs.Tables[0].Rows[0][Constants.LogInformation]) ? string.Empty : Convert.ToString(dsJobs.Tables[0].Rows[0][Constants.LogInformation]));
            }

            return(string.Empty);
        }
Esempio n. 5
0
        /// <summary>
        /// This method can be used to retrieve the list jobs to be loaded based on their schedule.
        /// </summary>
        /// <returns>List of jobs to be loaded.</returns>
        internal static List <JobSchedule> GetJobsToLoad()
        {
            // Create an instance of the JobScheduleMonitorBEO.
            List <JobSchedule> jobsToLoad = null;

            // Create a new instance of the DB manager.
            EVDbManager db = new EVDbManager(Constants.ConfigKeyDatabaseToUse);

            // Instantiate the stored procedure to obtain the jobs from load queue.
            DbCommand dbCommand = db.GetStoredProcCommand(Constants.StoredProcedureGetJobsToLoad);

            // Add input parameters.
            // RK - Changed the sp to work for both the functions. Need to send DBNull.Value for JobID.
            // Arun - This is incorrect. I've no idea why this SP needs JobId!
            db.AddInParameter(dbCommand, Constants.InputParameterJobId, DbType.Int32, DBNull.Value);

            // Execute the stored procedure and obtain the result set from the database into a dataset.
            DataSet dsResult = db.ExecuteDataSet(dbCommand);

            // If there are jobs to load then obtain the schedules.
            if (dsResult != null && dsResult.Tables.Count > Constants.None)
            {
                // Create an instance of job schedules list.
                jobsToLoad = new List <JobSchedule>();

                // Declare a job schedule object to represent a current job schedule.
                JobSchedule currentJob;

                // Declare a job schedule object to represent the previous job schedule while processing in a loop.
                JobSchedule previousJob = null;

                // Declare an integer to store the current job id.
                int currentJobId = Constants.None;

                // For each job that has to be loaded process the schedule information.
                foreach (DataRow drResult in dsResult.Tables[Constants.First].Rows)
                {
                    // Create an instance of the current job schedule.
                    currentJob = new JobSchedule();

                    // Get the current job id.
                    currentJobId = Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnJobId]);

                    // If this is the first job or if this is a different job from the previous job then create a new instance for the current job.
                    if ((previousJob == null) || (previousJob.JobId != currentJobId))
                    {
                        // Set the job id.
                        currentJob.JobId = currentJobId;

                        // Set the job name.
                        currentJob.JobName = Convert.ToString(drResult[Constants.TableJobMasterColumnJobName]);

                        // Set the job server id.
                        currentJob.JobServerId = !Convert.IsDBNull(drResult[Constants.TableJobMasterColumnJobServerId]) ? new Guid(Convert.ToString(drResult[Constants.TableJobMasterColumnJobServerId])) : Guid.Empty;

                        // Set the job server id.
                        currentJob.BootParameters = !Convert.IsDBNull(drResult[Constants.TableJobMasterColumnJobParameters]) ? Convert.ToString(drResult[Constants.TableJobMasterColumnJobParameters]) : string.Empty;

                        // Set the job type id.
                        currentJob.JobTypeId = Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnJobTypeId]);

                        // Set the job type name.
                        currentJob.JobTypeName = Convert.ToString(drResult[Constants.TableJobTypeMasterColumnJobRunId]);

                        // Set the job start date.
                        currentJob.JobStartDate = Convert.ToDateTime(drResult[Constants.TableJobScheduleMasterColumnJobStartDate]);

                        // Set the hourly repeat interval. If the value is null set it to 0.
                        currentJob.Hourly = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnHourly]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnHourly]) : Constants.None;

                        // Set the daily repeat interval. If the value is null set it to 0.
                        currentJob.Daily = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnDaily]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnDaily]) : Constants.None;

                        // Set the requested recurrence count for the job. If the value is null set it to 0.
                        currentJob.RequestedRecurrenceCount = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnRequestedRecurrenceCount]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnRequestedRecurrenceCount]) : Constants.None;

                        // Set the requested occurence count for the job. If the value is null set it to 0.
                        currentJob.ActualOccurenceCount = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnActualOccurrenceCount]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnActualOccurrenceCount]) : 0;

                        // Set the job next run date.
                        currentJob.NextRunDate = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnNextRunDate]) ? Convert.ToDateTime(drResult[Constants.TableJobScheduleMasterColumnNextRunDate]) : Constants.MinDate;

                        // Set the job run duration.
                        currentJob.JobRunDuration = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnDurationMinutes]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnDurationMinutes]) : Constants.MinutesInOneYear;

                        // Set the previous job instance to current job.
                        previousJob = currentJob;
                    }
                    else
                    {
                        // If this is not the first job and if this is the same job as the previous job set the current job instance to the previous job.
                        currentJob = previousJob;
                    } // End if

                    // Create an instance of the job schedule details.
                    JobScheduleDetails jobScheduleDetails = new JobScheduleDetails
                    {
                        WeekMonthIndicator =
                            Convert.ToString(
                                drResult[
                                    Constants.
                                    TableJobScheduleDetailsColumnWeekMonthIndicator
                                ]),
                        DayDateIndicator =
                            Convert.ToString(
                                drResult[
                                    Constants.
                                    TableJobScheduleDetailsColumnDayDateIndicator
                                ])
                    };

                    // Set the week / month indicator.

                    // Set the day / date indicator.

                    // Set the date value.
                    if (!Convert.IsDBNull(drResult[Constants.TableJobScheduleDetailsColumnDate]))
                    {
                        jobScheduleDetails.DateValue = Convert.ToDateTime(drResult[Constants.TableJobScheduleDetailsColumnDate]);
                    }

                    // Set the repeat every interval.
                    jobScheduleDetails.RepeatEvery = !Convert.IsDBNull(drResult[Constants.TableJobScheduleDetailsColumnRepeatEvery]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleDetailsColumnRepeatEvery]) : 0;


                    // Add the schedule details to the current job.
                    if (currentJob.ScheduleDetails == null)
                    {
                        currentJob.ScheduleDetails = new List <JobScheduleDetails>();
                    }

                    // Add the current schedule information to the current job.
                    currentJob.ScheduleDetails.Add(jobScheduleDetails);

                    // Add the current job to the jobs to load list.
                    jobsToLoad.Add(currentJob);
                } // End for each
            }     // End if

            // Return the list of jobs to load.
            return(jobsToLoad);
        } // End GetJobsToLoad()
        /// <summary>
        /// This method can be used to retrieve the list jobs to be loaded based on their schedule.
        /// </summary>
        /// <returns>List of jobs to be loaded.</returns>
        internal static List<JobSchedule> GetJobsToLoad()
        {
            // Create an instance of the JobScheduleMonitorBEO.
            List<JobSchedule> jobsToLoad = null;

            // Create a new instance of the DB manager.
            EVDbManager db = new EVDbManager(Constants.ConfigKeyDatabaseToUse);

            // Instantiate the stored procedure to obtain the jobs from load queue.
            DbCommand dbCommand = db.GetStoredProcCommand(Constants.StoredProcedureGetJobsToLoad);
            // Add input parameters. 
            // RK - Changed the sp to work for both the functions. Need to send DBNull.Value for JobID.
            // Arun - This is incorrect. I've no idea why this SP needs JobId!
            db.AddInParameter(dbCommand, Constants.InputParameterJobId, DbType.Int32, DBNull.Value);

            // Execute the stored procedure and obtain the result set from the database into a dataset.
            DataSet dsResult = db.ExecuteDataSet(dbCommand);

            // If there are jobs to load then obtain the schedules.
            if (dsResult != null && dsResult.Tables.Count > Constants.None)
            {

                // Create an instance of job schedules list.
                jobsToLoad = new List<JobSchedule>();

                // Declare a job schedule object to represent a current job schedule.
                JobSchedule currentJob;

                // Declare a job schedule object to represent the previous job schedule while processing in a loop.
                JobSchedule previousJob = null;

                // Declare an integer to store the current job id.
                int currentJobId = Constants.None;

                // For each job that has to be loaded process the schedule information.
                foreach (DataRow drResult in dsResult.Tables[Constants.First].Rows)
                {
                    // Create an instance of the current job schedule.
                    currentJob = new JobSchedule();

                    // Get the current job id.
                    currentJobId = Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnJobId]);

                    // If this is the first job or if this is a different job from the previous job then create a new instance for the current job.
                    if ((previousJob == null) || (previousJob.JobId != currentJobId))
                    {
                        // Set the job id.
                        currentJob.JobId = currentJobId;

                        // Set the job name.
                        currentJob.JobName = Convert.ToString(drResult[Constants.TableJobMasterColumnJobName]);

                        // Set the job server id.
                        currentJob.JobServerId = !Convert.IsDBNull(drResult[Constants.TableJobMasterColumnJobServerId]) ? new Guid(Convert.ToString(drResult[Constants.TableJobMasterColumnJobServerId])) : Guid.Empty;

                        // Set the job server id.
                        currentJob.BootParameters = !Convert.IsDBNull(drResult[Constants.TableJobMasterColumnJobParameters]) ? Convert.ToString(drResult[Constants.TableJobMasterColumnJobParameters]) : string.Empty;

                        // Set the job type id.
                        currentJob.JobTypeId = Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnJobTypeId]);

                        // Set the job type name.
                        currentJob.JobTypeName = Convert.ToString(drResult[Constants.TableJobTypeMasterColumnJobRunId]);

                        // Set the job start date.
                        currentJob.JobStartDate = Convert.ToDateTime(drResult[Constants.TableJobScheduleMasterColumnJobStartDate]);

                        // Set the hourly repeat interval. If the value is null set it to 0.
                        currentJob.Hourly = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnHourly]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnHourly]) : Constants.None;

                        // Set the daily repeat interval. If the value is null set it to 0.
                        currentJob.Daily = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnDaily]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnDaily]) : Constants.None;

                        // Set the requested recurrence count for the job. If the value is null set it to 0.
                        currentJob.RequestedRecurrenceCount = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnRequestedRecurrenceCount]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnRequestedRecurrenceCount]) : Constants.None;

                        // Set the requested occurence count for the job. If the value is null set it to 0.
                        currentJob.ActualOccurenceCount = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnActualOccurrenceCount]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnActualOccurrenceCount]) : 0;

                        // Set the job next run date.
                        currentJob.NextRunDate = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnNextRunDate]) ? Convert.ToDateTime(drResult[Constants.TableJobScheduleMasterColumnNextRunDate]) : Constants.MinDate;

                        // Set the job run duration.
                        currentJob.JobRunDuration = !Convert.IsDBNull(drResult[Constants.TableJobScheduleMasterColumnDurationMinutes]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleMasterColumnDurationMinutes]) : Constants.MinutesInOneYear;

                        // Set the previous job instance to current job.
                        previousJob = currentJob;
                    }
                    else
                    {
                        // If this is not the first job and if this is the same job as the previous job set the current job instance to the previous job.
                        currentJob = previousJob;
                    } // End if

                    // Create an instance of the job schedule details.
                    JobScheduleDetails jobScheduleDetails = new JobScheduleDetails
                                                                {
                                                                    WeekMonthIndicator =
                                                                        Convert.ToString(
                                                                            drResult[
                                                                                Constants.
                                                                                    TableJobScheduleDetailsColumnWeekMonthIndicator
                                                                                ]),
                                                                    DayDateIndicator =
                                                                        Convert.ToString(
                                                                            drResult[
                                                                                Constants.
                                                                                    TableJobScheduleDetailsColumnDayDateIndicator
                                                                                ])
                                                                };

                    // Set the week / month indicator.

                    // Set the day / date indicator.

                    // Set the date value.
                    if (!Convert.IsDBNull(drResult[Constants.TableJobScheduleDetailsColumnDate]))
                        jobScheduleDetails.DateValue = Convert.ToDateTime(drResult[Constants.TableJobScheduleDetailsColumnDate]);

                    // Set the repeat every interval.
                    jobScheduleDetails.RepeatEvery = !Convert.IsDBNull(drResult[Constants.TableJobScheduleDetailsColumnRepeatEvery]) ? Convert.ToInt32(drResult[Constants.TableJobScheduleDetailsColumnRepeatEvery]) : 0;


                    // Add the schedule details to the current job.
                    if (currentJob.ScheduleDetails == null)
                    {
                        currentJob.ScheduleDetails = new List<JobScheduleDetails>();
                    }

                    // Add the current schedule information to the current job.
                    currentJob.ScheduleDetails.Add(jobScheduleDetails);

                    // Add the current job to the jobs to load list.
                    jobsToLoad.Add(currentJob);
                } // End for each
            } // End if

            // Return the list of jobs to load.
            return jobsToLoad;
        } // End GetJobsToLoad()