Exemplo 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);
                }
            });
        }
Exemplo 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;
        }
Exemplo 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();
        }
Exemplo n.º 4
0
        private void SetJobBaseInfo(JobBase newJob)
        {
            newJob.JobID       = this.JobID;
            newJob.Name        = txtName.Value.Trim();
            newJob.Enabled     = bool.Parse(this.ddlEnabled.Value);
            newJob.Description = txtDesc.Value;
            newJob.Creator     = DeluxeIdentity.CurrentUser;
            newJob.Category    = txtCategory.Value;

            JobScheduleCollection schedules = new JobScheduleCollection();

            foreach (SimpleSchedule item in detailGrid.InitialData)
            {
                JobSchedule schedule = JobScheduleAdapter.Instance.Load(p => p.AppendItem("SCHEDULE_ID", item.ID))[0];
                schedules.Add(schedule);
            }
            newJob.Schedules = schedules;
        }
        private void LoadData()
        {
            Job job = this.Job;

            // load the data
            if (job != null)
            {
                JobScheduleCollection schedules = job.JobSchedules;

                for (int i = 0; i < schedules.Count; i++)
                {
                    this.jobSchedules.Add(new JobScheduleData(schedules[i], this.IsReadOnly, this.AllowEnableDisable));
                }
            }
            else
            {
                SetDefaults();
            }
        }
        /// <summary>
        /// 根据ID获取计划
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        protected JobScheduleCollection GetSchedules(string ids)
        {
            JobScheduleCollection scheduleList = new JobScheduleCollection();

            if (!string.IsNullOrEmpty(ids))
            {
                string[] propertities = ids.TrimEnd(',').Split(',');
                for (int i = 0; i < propertities.Length; i++)
                {
                    string id = propertities[i];
                    if (!string.IsNullOrEmpty(id))
                    {
                        //根据ID获取ETL实体
                        JobSchedule entity = JobScheduleAdapter.Instance.Load(c => c.AppendItem("SCHEDULE_ID", id)).FirstOrDefault() as JobSchedule;
                        if (entity != null)
                        {
                            scheduleList.Add(entity);
                        }
                    }
                }
            }
            return(scheduleList);
        }
Exemplo n.º 7
0
		private void SetJobBaseInfo(JobBase newJob)
		{
			newJob.JobID = this.JobID;
			newJob.Name = txtName.Value.Trim();
			newJob.Enabled = bool.Parse(this.ddlEnabled.Value);
			newJob.Description = txtDesc.Value;
			newJob.Creator = DeluxeIdentity.CurrentUser;
			newJob.Category = txtCategory.Value;

			JobScheduleCollection schedules = new JobScheduleCollection();
			foreach (SimpleSchedule item in detailGrid.InitialData)
			{
				JobSchedule schedule = JobScheduleAdapter.Instance.Load(p => p.AppendItem("SCHEDULE_ID", item.ID))[0];
				schedules.Add(schedule);
			}
			newJob.Schedules = schedules;
		}
        //保存
        protected void btn_Save_Click(object sender, EventArgs e)
        {
            //错误信息
            StringBuilder error = new StringBuilder();

            if (this.Data == null && Request["id"] != null)
            {
                //根据ID获取任务对象
                //this.Data = (ETLJob)ETLJobAdapter.Instance.Load(Convert.ToString(Request["id"]));
                this.Data = JobBaseAdapter.Instance.Load(c => c.AppendItem("job_id", Convert.ToString(Request["id"]))).FirstOrDefault();
            }

            if (!Util.CheckOperationSafe())
            {
                return;
            }
            //ETL任务
            if (ddl_JobType.SelectedValue == "ETLService")
            {
                #region

                JobScheduleCollection pvc = new JobScheduleCollection();
                //计划列表
                if (ch_IsAuto.Checked)
                {
                    //pvc = JSONSerializerExecute.Deserialize<JobScheduleCollection>(schedules.Value);
                    pvc = GetSchedules(schedules.Value);
                }

                ETLEntityCollection etls = GetETLEntities(etlEntities.Value);

                ETLWhereConditionCollection wheres = JSONSerializerExecute.Deserialize <ETLWhereConditionCollection>(conditions.Value);
                if (this.Data != null)
                {
                    ETLJob job = ETLJobAdapter.Instance.Load(this.Data.JobID) as ETLJob;
                    this.Data       = job;
                    job.Category    = txt_jobCategory.Text;
                    job.Enabled     = ddl_Enabled.SelectedValue == "1" ? true : false;
                    job.JobType     = JobType.ETLService;
                    job.Description = txt_JobDescription.Text;
                    job.Name        = txt_JobName.Text;
                    job.Schedules   = pvc;
                    job.ETLEntities = etls;
                    job.IsAuto      = ch_IsAuto.Checked;
                    job.IsIncrement = ch_IsIncrement.Checked;
                    wheres.ForEach(w => { w.JOB_ID = this.Data.JobID; w.ID = Guid.NewGuid().ToString(); });

                    job.ETLWhereConditions = wheres;

                    if (CheckEtlEntities())
                    {
                        ETLJobOperations.Instance.DoOperation(EntityJobOperationMode.Update, job);
                    }
                }
                else
                {
                    ETLJob job = new ETLJob()
                    {
                        JobID       = Guid.NewGuid().ToString(),
                        Category    = txt_jobCategory.Text,
                        Enabled     = ddl_Enabled.SelectedValue == "1" ? true : false,
                        JobType     = JobType.ETLService,
                        Description = txt_JobDescription.Text,
                        Name        = txt_JobName.Text,
                        Schedules   = pvc,
                        ETLEntities = etls,
                        IsAuto      = ch_IsAuto.Checked,
                        IsIncrement = ch_IsIncrement.Checked
                    };
                    wheres.ForEach(w => { w.JOB_ID = job.JobID; w.ID = Guid.NewGuid().ToString(); });

                    job.ETLWhereConditions = wheres;

                    this.Data = job;
                    if (CheckEtlEntities())
                    {
                        ETLJobOperations.Instance.DoOperation(EntityJobOperationMode.Add, job);
                    }
                }
                if (string.IsNullOrEmpty(ErrorMsg))
                {
                    HttpContext.Current.Response.Write("<script>window.returnValue=true;window.close();</script>");
                    //this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "closeWindow", "window.returnValue=true;window.close()", true);
                }
                else
                {
                    //ViewState["conditions"] = conditions.Value;
                    ViewState["schedules"] = schedules.Value;
                    conditions.Value       = JSONSerializerExecute.Serialize((this.Data as ETLJob).ETLWhereConditions);

                    ViewState["etlEntities"] = etlEntities.Value;


                    //计划列表
                    List <ScheduleGridObj> scheduleList = new List <ScheduleGridObj>();
                    foreach (JobSchedule item in this.Data.Schedules)
                    {
                        scheduleList.Add(new ScheduleGridObj()
                        {
                            ID          = item.ID,
                            Name        = item.Name,
                            Description = item.Description
                        });
                    }
                    ViewState["schedulesGrid"] = JSONSerializerExecute.Serialize(scheduleList);;
                    grid.InitialData           = scheduleList;

                    //etl实体列表
                    List <EtlGridObj> etlJobs = new List <EtlGridObj>();
                    foreach (ETLEntity item in (this.Data as ETLJob).ETLEntities)
                    {
                        etlJobs.Add(new EtlGridObj()
                        {
                            ID          = item.ID,
                            CodeName    = item.Name,
                            Description = item.Description
                        });
                    }

                    ViewState["etlsGrid"] = JSONSerializerExecute.Serialize(etlJobs);
                    gridEtl.InitialData   = etlJobs;

                    string msg       = ErrorMsg.Replace("\r\n", string.Empty);
                    string scriptStr = string.Format("alert('{0}');", msg);
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "closeWindow", scriptStr, true);
                    //HttpContext.Current.Response.Write(scriptStr);
                }
                #endregion
            }
            //WebService任务
            else
            {
                #region

                JobScheduleCollection pvc = new JobScheduleCollection();
                //计划列表
                if (ch_IsAuto.Checked)
                {
                    //pvc = JSONSerializerExecute.Deserialize<JobScheduleCollection>(schedules.Value);
                    pvc = GetSchedules(schedules.Value);
                }

                if (this.Data != null)
                {
                    InvokeWebServiceJob job = InvokeWebServiceJobAdapter.Instance.Load(w => w.AppendItem("Job_id", this.Data.JobID)).FirstOrDefault();// this.Data as InvokeWebServiceJob;
                    job.Category         = txt_jobCategory.Text;
                    job.Enabled          = ddl_Enabled.SelectedValue == "1" ? true : false;
                    job.JobType          = JobType.InvokeService;
                    job.Description      = txt_JobDescription.Text;
                    job.Name             = txt_JobName.Text;
                    job.Schedules        = pvc;
                    job.ISManual         = !ch_IsAuto.Checked;
                    job.SvcOperationDefs = JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(this.services.Value);
                    //入库
                    DoUpdate(job);
                }
                else
                {
                    InvokeWebServiceJob job = new InvokeWebServiceJob()
                    {
                        JobID            = Guid.NewGuid().ToString(),
                        Category         = txt_jobCategory.Text,
                        Enabled          = ddl_Enabled.SelectedValue == "1" ? true : false,
                        JobType          = JobType.InvokeService,
                        Description      = txt_JobDescription.Text,
                        Name             = txt_JobName.Text,
                        Schedules        = pvc,
                        ISManual         = !ch_IsAuto.Checked,
                        SvcOperationDefs = JSONSerializerExecute.Deserialize <WfServiceOperationDefinitionCollection>(this.services.Value)
                    };

                    this.Data = job;

                    //入库
                    DoUpdate(job);
                }
                if (string.IsNullOrEmpty(ErrorMsg))
                {
                    HttpContext.Current.Response.Write("<script>window.returnValue=true;window.close();</script>");
                    //this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "closeWindow", "window.returnValue=true;window.close()", true);
                }
                else
                {
                    //ViewState["conditions"] = conditions.Value;
                    ViewState["schedules"] = schedules.Value;
                    conditions.Value       = JSONSerializerExecute.Serialize((this.Data as ETLJob).ETLWhereConditions);

                    ViewState["etlEntities"] = etlEntities.Value;


                    //计划列表
                    List <ScheduleGridObj> scheduleList = new List <ScheduleGridObj>();
                    foreach (JobSchedule item in this.Data.Schedules)
                    {
                        scheduleList.Add(new ScheduleGridObj()
                        {
                            ID          = item.ID,
                            Name        = item.Name,
                            Description = item.Description
                        });
                    }
                    ViewState["schedulesGrid"] = JSONSerializerExecute.Serialize(scheduleList);;
                    grid.InitialData           = scheduleList;

                    //etl实体列表
                    List <EtlGridObj> etlJobs = new List <EtlGridObj>();
                    foreach (ETLEntity item in (this.Data as ETLJob).ETLEntities)
                    {
                        etlJobs.Add(new EtlGridObj()
                        {
                            ID          = item.ID,
                            CodeName    = item.Name,
                            Description = item.Description
                        });
                    }

                    ViewState["etlsGrid"] = JSONSerializerExecute.Serialize(etlJobs);
                    gridEtl.InitialData   = etlJobs;

                    string msg       = ErrorMsg.Replace("\r\n", string.Empty);
                    string scriptStr = string.Format("alert('{0}');", msg);
                    this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "closeWindow", scriptStr, true);
                }
                #endregion
            }
        }
Exemplo n.º 9
0
        public static List <AgentJobHistoryInfo> ConvertToAgentJobHistoryInfo(List <ILogEntry> logEntries,
                                                                              DataRow jobRow, JobStepCollection steps, JobScheduleCollection schedules, List <Alert> alerts)
        {
            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 (JobStep step in steps)
                {
                    var jobId = jobRow[UrnJobId].ToString();
                    jobSteps.Add(AgentUtilities.ConvertToAgentJobStepInfo(step, logEntry, jobId));
                }

                jobHistoryInfo.Steps = jobSteps.ToArray();

                // Add schedules to the job if any
                var jobSchedules = new List <AgentScheduleInfo>();
                foreach (JobSchedule schedule in schedules)
                {
                    jobSchedules.Add(AgentUtilities.ConvertToAgentScheduleInfo(schedule));
                }
                jobHistoryInfo.Schedules = jobSchedules.ToArray();

                // Add alerts to the job if any
                var jobAlerts = new List <AgentAlertInfo>();
                foreach (Alert alert in alerts)
                {
                    jobAlerts.Add(AgentUtilities.ConvertToAgentAlertInfo(alert));
                }
                jobHistoryInfo.Alerts = jobAlerts.ToArray();
                jobs.Add(jobHistoryInfo);
            }
            return(jobs);
        }