Esempio n. 1
0
        /// <summary>
        /// Handle request to get Agent Job history
        /// </summary>
        internal async Task HandleJobHistoryRequest(AgentJobHistoryParams parameters, RequestContext <AgentJobHistoryResult> requestContext)
        {
            await Task.Run(async() =>
            {
                try
                {
                    var result = new AgentJobHistoryResult();
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(
                        parameters.OwnerUri,
                        out connInfo);
                    if (connInfo != null)
                    {
                        ConnectionServiceInstance.TryFindConnection(parameters.OwnerUri, out connInfo);
                        CDataContainer dataContainer = CDataContainer.CreateDataContainer(connInfo, databaseExists: true);
                        var jobs = dataContainer.Server.JobServer.Jobs;
                        Tuple <SqlConnectionInfo, DataTable, ServerConnection> tuple = CreateSqlConnection(connInfo, parameters.JobId);
                        SqlConnectionInfo sqlConnInfo = tuple.Item1;
                        DataTable dt = tuple.Item2;
                        ServerConnection connection = tuple.Item3;
                        int count = dt.Rows.Count;
                        List <AgentJobHistoryInfo> jobHistories = new List <AgentJobHistoryInfo>();
                        if (count > 0)
                        {
                            var job        = dt.Rows[0];
                            string jobName = Convert.ToString(job[AgentUtilities.UrnJobName], System.Globalization.CultureInfo.InvariantCulture);
                            Guid jobId     = (Guid)job[AgentUtilities.UrnJobId];
                            int runStatus  = Convert.ToInt32(job[AgentUtilities.UrnRunStatus], System.Globalization.CultureInfo.InvariantCulture);
                            var t          = new LogSourceJobHistory(jobName, sqlConnInfo, null, runStatus, jobId, null);
                            var tlog       = t as ILogSource;
                            tlog.Initialize();
                            var logEntries = t.LogEntries;

                            // Send Steps, Alerts and Schedules with job history in background
                            JobStepCollection steps         = jobs[jobName].JobSteps;
                            JobScheduleCollection schedules = jobs[jobName].JobSchedules;
                            List <Alert> alerts             = new List <Alert>();
                            foreach (Alert alert in dataContainer.Server.JobServer.Alerts)
                            {
                                if (alert.JobID == jobId && alert.JobName == jobName)
                                {
                                    alerts.Add(alert);
                                }
                            }
                            jobHistories = AgentUtilities.ConvertToAgentJobHistoryInfo(logEntries, job, steps, schedules, alerts);
                            tlog.CloseReader();
                        }
                        result.Jobs    = jobHistories.ToArray();
                        result.Success = true;
                        connection.Disconnect();
                        await requestContext.SendResult(result);
                    }
                }
                catch (Exception e)
                {
                    await requestContext.SendError(e);
                }
            });
        }
Esempio n. 2
0
        private void FillJobBackupInfo()
        {
            FillCtlDaysBackup();
            JobScheduleCollection schedules = backup.JobSchedules;

            ctlDaysBackup.SelectedText = daysOfWeek.FirstOrDefault(x => x.Value == schedules[0].FrequencyInterval).Key;
            ctlTimeBackup.Text         = schedules[0].ActiveStartTimeOfDay.ToString();
            JobStepCollection steps = backup.JobSteps;

            txtBackupPath.Text         = steps[0].Command.Substring(19, steps[0].Command.Length - 20);
            ctlIsEnabledBackup.Checked = backup.IsEnabled;
        }
Esempio n. 3
0
        private void SaveJobBackupSettings()
        {
            JobScheduleCollection schedules = backup.JobSchedules;

            schedules[0].FrequencyInterval    = daysOfWeek.FirstOrDefault(x => x.Key == ctlDaysBackup.SelectedItem.ToString()).Value;
            schedules[0].ActiveStartTimeOfDay = ctlTimeBackup.Value.TimeOfDay;
            schedules[0].Alter();
            JobStepCollection steps = backup.JobSteps;

            steps[0].Command = $"exec CreateBackup '{txtBackupPath.Text}'";
            steps[0].Alter();
            backup.IsEnabled = ctlIsEnabledBackup.Checked;
            backup.Alter();
        }
Esempio n. 4
0
        public static List <AgentJobHistoryInfo> ConvertToAgentJobHistoryInfo(List <ILogEntry> logEntries, DataRow jobRow, JobStepCollection steps)
        {
            List <AgentJobHistoryInfo> jobs = new List <AgentJobHistoryInfo>();

            // get all the values for a job history
            foreach (ILogEntry entry in logEntries)
            {
                // Make a new AgentJobHistoryInfo object
                var jobHistoryInfo = new AgentJobHistoryInfo();
                jobHistoryInfo.InstanceId = Convert.ToInt32(jobRow[UrnInstanceID], System.Globalization.CultureInfo.InvariantCulture);
                jobHistoryInfo.JobId      = (Guid)jobRow[UrnJobId];
                var logEntry = entry as LogSourceJobHistory.LogEntryJobHistory;
                jobHistoryInfo.RunStatus        = entry.Severity == SeverityClass.Error ? 0 : 1;
                jobHistoryInfo.SqlMessageId     = logEntry.SqlMessageID;
                jobHistoryInfo.Message          = logEntry.Message;
                jobHistoryInfo.StepId           = logEntry.StepID;
                jobHistoryInfo.StepName         = logEntry.StepName;
                jobHistoryInfo.SqlSeverity      = logEntry.SqlSeverity;
                jobHistoryInfo.JobName          = logEntry.JobName;
                jobHistoryInfo.RunDate          = entry.PointInTime;
                jobHistoryInfo.RunDuration      = logEntry.Duration;
                jobHistoryInfo.OperatorEmailed  = logEntry.OperatorEmailed;
                jobHistoryInfo.OperatorNetsent  = logEntry.OperatorNetsent;
                jobHistoryInfo.OperatorPaged    = logEntry.OperatorPaged;
                jobHistoryInfo.RetriesAttempted = logEntry.RetriesAttempted;
                jobHistoryInfo.Server           = logEntry.Server;

                // Add steps to the job if any
                var jobSteps = new List <AgentJobStep>();
                foreach (LogSourceJobHistory.LogEntryJobHistory subEntry in entry.SubEntries)
                {
                    if (steps.Contains(subEntry.StepName))
                    {
                        var jobId = jobRow[UrnJobId].ToString();
                        jobSteps.Add(AgentUtilities.ConvertToAgentJobStep(steps.ItemById(Convert.ToInt32(subEntry.StepID)), logEntry, jobId));
                    }
                }
                jobHistoryInfo.Steps = jobSteps.ToArray();
                jobs.Add(jobHistoryInfo);
            }
            return(jobs);
        }
        /// <summary>
        /// Load job steps from the server
        /// </summary>
        private void LoadData()
        {
            STParameters parameters  = new STParameters(this.context.Document);
            string       urn         = string.Empty;
            string       jobIdString = string.Empty;

            parameters.GetParam("urn", ref urn);
            parameters.GetParam("jobid", ref jobIdString);

            // save current state of default fields
            StringCollection originalFields = this.context.Server.GetDefaultInitFields(typeof(JobStep));

            // Get all JobStep properties since the JobStepData class is going to use themn
            this.context.Server.SetDefaultInitFields(typeof(JobStep), true);

            try
            {
                Job job = null;
                // If JobID is passed in look up by jobID
                if (!string.IsNullOrEmpty(jobIdString))
                {
                    job = this.context.Server.JobServer.Jobs.ItemById(Guid.Parse(jobIdString));
                }
                else
                {
                    // or use urn path to query job
                    job = this.context.Server.GetSmoObject(urn) as Job;
                }

                // load the data
                JobStepCollection steps = job.JobSteps;

                // allocate the array list
                this.jobSteps = new ArrayList(steps.Count);

                for (int i = 0; i < steps.Count; i++)
                {
                    // add them in step id order
                    int ii = 0;
                    for (; ii < this.jobSteps.Count; ii++)
                    {
                        if (steps[i].ID < ((JobStepData)this.jobSteps[ii]).ID)
                        {
                            break;
                        }
                    }
                    this.jobSteps.Insert(ii, new JobStepData(steps[i], this));
                }
                // figure out the start step
                this.startStep = GetObjectForStep(job.StartStepID);

                // fixup all of the jobsteps failure/completion actions
                foreach (JobStepData jobStep in this.jobSteps)
                {
                    jobStep.LoadCompletionActions();
                }
            }
            finally
            {
                // revert to initial default fields for this type
                this.context.Server.SetDefaultInitFields(typeof(JobStep), originalFields);
            }
        }