Exemple #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);
                }
            });
        }
 /// <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[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;
                     jobHistories   = AgentUtilities.ConvertToAgentJobHistoryInfo(logEntries, job);
                     tlog.CloseReader();
                 }
                 result.Jobs    = jobHistories.ToArray();
                 result.Success = true;
                 connection.Disconnect();
                 await requestContext.SendResult(result);
             }
         }
         catch (Exception e)
         {
             await requestContext.SendError(e);
         }
     });
 }