示例#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)
             {
                 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[JobUtilities.UrnJobName], System.Globalization.CultureInfo.InvariantCulture);
                     Guid jobId     = (Guid)job[JobUtilities.UrnJobId];
                     int runStatus  = Convert.ToInt32(job[JobUtilities.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;
                     jobHistories   = JobUtilities.ConvertToAgentJobHistoryInfo(logEntries, job);
                     tlog.CloseReader();
                 }
                 result.Jobs      = jobHistories.ToArray();
                 result.Succeeded = true;
                 connection.Disconnect();
                 await requestContext.SendResult(result);
             }
         }
         catch (Exception e)
         {
             await requestContext.SendError(e);
         }
     });
 }
示例#2
0
        public static List <AgentJobHistoryInfo> ConvertToAgentJobHistoryInfo(List <ILogEntry> logEntries, DataRow jobRow)
        {
            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.RunStatus  = Convert.ToInt32(jobRow[UrnRunStatus], System.Globalization.CultureInfo.InvariantCulture);
                jobHistoryInfo.JobId      = (Guid)jobRow[UrnJobId];
                var logEntry = entry as LogSourceJobHistory.LogEntryJobHistory;
                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>();
                if (entry.CanLoadSubEntries)
                {
                    foreach (ILogEntry step in entry.SubEntries)
                    {
                        jobSteps.Add(JobUtilities.ConvertToAgentJobStep(step, jobRow));
                    }
                }
                jobHistoryInfo.Steps = jobSteps.ToArray();
                jobs.Add(jobHistoryInfo);
            }
            return(jobs);
        }
示例#3
0
        /// <summary>
        /// Handle request to get Agent job activities
        /// </summary>
        internal async Task HandleAgentJobsRequest(AgentJobsParams parameters, RequestContext <AgentJobsResult> requestContext)
        {
            await Task.Run(async() =>
            {
                try
                {
                    var result = new AgentJobsResult();
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(
                        parameters.OwnerUri,
                        out connInfo);

                    if (connInfo != null)
                    {
                        var sqlConnection    = ConnectionService.OpenSqlConnection(connInfo);
                        var serverConnection = new ServerConnection(sqlConnection);
                        var fetcher          = new JobFetcher(serverConnection);
                        var filter           = new JobActivityFilter();
                        this.jobs            = fetcher.FetchJobs(filter);
                        var agentJobs        = new List <AgentJobInfo>();
                        if (this.jobs != null)
                        {
                            foreach (var job in this.jobs.Values)
                            {
                                agentJobs.Add(JobUtilities.ConvertToAgentJobInfo(job));
                            }
                        }
                        result.Succeeded = true;
                        result.Jobs      = agentJobs.ToArray();
                        sqlConnection.Close();
                    }
                    await requestContext.SendResult(result);
                }
                catch (Exception e)
                {
                    await requestContext.SendError(e);
                }
            });
        }