public void AddTrigger(JobTrigger trigger)
        {
            UnitOfWork.JobTriggerRepository.Insert(trigger);
            UnitOfWork.Save();
            //DateTimeOffset runDate = DateBuilder.EvenMinuteDate(DateTimeOffset.UtcNow);
            //DateTimeOffset runDate = DateBuilder.TodayAt(DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second);

            //var jobkey = new JobKey(trigger.Job.JOB_NAME, trigger.Job.JOB_GROUP);
            //ITrigger triggerBuilder = TriggerBuilder.Create()
            //    .StartAt(runDate)
            //    .ForJob(jobkey)
            //    .Build();
            //Scheduler.ScheduleJob(triggerBuilder);
        }
        public void AddJob(Job job, JobTrigger jobTrigger)
        {
            IJobDetail jobDetail = JobBuilder.Create<SqlScheduledJob>()
                .WithIdentity(job.JOB_NAME, job.JOB_GROUP)
                .Build();

            jobDetail.JobDataMap.Put("TriggerId",job.JobId);

            DateTimeOffset runDate = DateBuilder.TodayAt(((DateTime)jobTrigger.StartExecutionDate).Hour, ((DateTime)jobTrigger.StartExecutionDate).Minute, ((DateTime)jobTrigger.StartExecutionDate).Second);

            ITrigger trigger = TriggerBuilder.Create()
                .StartAt(runDate)
                .Build();

            Scheduler.ScheduleJob(jobDetail, trigger);
        }
        public void AddQuartzJob(Job job, JobTrigger jobTrigger)
        {
            var jobDetail = JobBuilder.Create<SqlScheduledJob>()
              .WithIdentity(job.JobId.ToString(), jobTrigger.JobTriggerId.ToString())
              .Build();

            jobDetail.JobDataMap.Put("TriggerId", jobTrigger.JobTriggerId.ToString());

            DateTimeOffset runDate = DateBuilder.TodayAt((jobTrigger.ScheduledStartExecutionDate).Hour, (jobTrigger.ScheduledStartExecutionDate).Minute, (jobTrigger.ScheduledStartExecutionDate).Second);

            ITrigger trigger = TriggerBuilder.Create()
                .WithIdentity(jobTrigger.JobTriggerId.ToString())
                .ForJob(jobDetail)
                .StartAt(runDate)
                .Build();

            if (Status() == SchedulerStatus.Apagado)
                throw new QuartzException("El servicio scheduler se encuentra apagado");
            Scheduler.ScheduleJob(jobDetail, trigger);
        }
        /// <summary>
        /// Si el job es de tipo Automático crea un trigger en CGControlPanel y en Quartz. Se ejecuta automáticamente.
        /// Si el job es de tipo manual se crea un trigger DESHABILITADO en CGControlPanel. Se ejecutará luego manualmente desde el menú contextual correspondiente -que disparará ExecuteManualJob-.
        /// </summary>
        /// <param name="job"></param>
        /// <param name="trigger"></param>
        public void AddTrigger(Job job, JobTrigger trigger)
        {
            // OJO: Si el trigger viene deshabilitado NO se lo debe agregar al Quartz, es el caso de agendamiento de un job manual
            job.Triggers.Add(trigger);
            trigger.Job = job;
            trigger.JobId = job.JobId;

            if (trigger.Validate())
            {
                UnitOfWork.JobTriggerRepository.Insert(trigger);
                UnitOfWork.JobsRepository.Update(job);
                UnitOfWork.Save();
                if (trigger.Enabled)
                {
                    AddQuartzJob(job, trigger);
                }
            }
            else {
                Utils.Validation.Helper.BuildValidationErrors(trigger.ValidationErrors);
            }
        }
Ejemplo n.º 5
0
        protected void FillUI(JobTrigger jobTrigger)
        {
            var sqlJobTrigger =  (SqlJobTrigger)jobTrigger;

            lblProcessName.Text = "Proceso: " + jobTrigger.Job.JobId + " - " + jobTrigger.Job.Name;
            lblProcessOwner.Text =  "Usuario: " + jobTrigger.Job.CreatedBy;
            lblDescription.Text =  "Descripción: " + jobTrigger.Job.Description;
            txtInputValues.Text = sqlJobTrigger.Job.FixedParametersProcedure + sqlJobTrigger.XmlFormInputValues;

            lblTrigger.Text =  "Trigger: " + jobTrigger.JobTriggerId;
            lblRecords.Text = "Registros: " + sqlJobTrigger.RecordsAffected.ToString() + "/" + sqlJobTrigger.RecordsProcessed.ToString();
            lblDaily.Text = "Frecuencia: " + (sqlJobTrigger.Job.IsDaily ? "DIARIA" : "");

            lblComments.Text = "Comentarios: " + sqlJobTrigger.Job.Comments;
            lblProcessType.Text = "Tipo de Proceso: " + sqlJobTrigger.Job.JobType;

            // AREA DE INFORMACION DE EJECUCION
            if (!sqlJobTrigger.StartExecutionDate.HasValue)
            {
                tabControl.ActiveTabPage.Visible = false;
                tabControl.ActiveTabIndex = 0;

                if (Request.QueryString["delete"] != "1")
                {
                    btnDeleteTrigger.Visible = false;
                }
            }

            // TODO: Poner un tag en el xmlResultado para mostrar datos luego de que arme la tabla.
            // InputValues es el resultado de la ejecución del stored de Configuración que arma el Form Dinámico
            txtXmlTableInputParameters.Text= sqlJobTrigger.XmlTableInput;
            txtXmlTableOutput.Text = sqlJobTrigger.XmlTableOutput;
            txtExecutionLog.Text = sqlJobTrigger.XmlTableExecutionLog;
            Utils.UI.Helper.BuildASPTable(sqlJobTrigger.XmlResult, tblResult);

            lblStartExecutionDate.Text = "Ejecución: " + ((sqlJobTrigger.StartExecutionDate.HasValue) ? sqlJobTrigger.StartExecutionDate.Value.ToString("dd/MM/yyyy hh:mm:ss") : "");
            lblEndExecutionDate.Text = ((sqlJobTrigger.EndExecutionDate.HasValue) ? sqlJobTrigger.EndExecutionDate.Value.ToString("dd/MM/yyyy hh:mm:ss") : "");
        }
Ejemplo n.º 6
0
        protected void FillReport(JobTrigger jobTrigger)
        {
            var sqlJobTrigger = (SqlJobTrigger)jobTrigger;

            /* DATOS JOB */

            lblProcessName.Text = jobTrigger.Job.Name + " (" + jobTrigger.Job.Group + ") - " + jobTrigger.Job.JobId  + " -" ;
            lblProcessOwner.Text = jobTrigger.Job.CreatedBy;
            lblDescription.Text = jobTrigger.Job.Description;
            lblInputValues.Text = Utils.UI.Helper.FormatXml(sqlJobTrigger.Job.InputXmlFixedParameters + sqlJobTrigger.InputFormXmlValues);
            lblComments.Text = sqlJobTrigger.Job.Comments;
            lblProcessType.Text = sqlJobTrigger.Job.JobType.ToString();

            Weekdays weekdays = new Weekdays();
            weekdays.AllDays = Convert.ToByte(((SqlJob)sqlJobTrigger.Job).Weekdays);

            if (weekdays.AllDays == 0)
                lblWeekDays.Text = "No Diaria";
            else
                lblWeekDays.Text = Utils.UI.Helper.BuildPopulateDaysLegend(weekdays);

            lblServerName.Text = ((SqlJob)sqlJobTrigger.Job).ServerName;
            lblDataBaseName.Text = ((SqlJob)sqlJobTrigger.Job).DatabaseName;
            lblStoredProcedure.Text = ((SqlJob)sqlJobTrigger.Job).ExecProcedure;
            lblInputXmlFixedParameters.Text = Utils.UI.Helper.FormatXml(sqlJobTrigger.Job.InputXmlFixedParameters);
            lblInputXmlFixedParameters.Text = lblInputXmlFixedParameters.Text.Replace("<ROOT>", "").Replace("</ROOT>", "");

            if (sqlJobTrigger.Job.JobType == JobType.Automático)
            {
                lblScheduledStartExecutionDate.Text = sqlJobTrigger.ScheduledStartExecutionDate.ToString("dd/MM/yyyy HH:mm:ss");

                if (sqlJobTrigger.Job.AutomaticProcessTime.HasValue && sqlJobTrigger.Job.Weekdays != 0)
                {
                    lblAutomaticProcessTime.Text = "Hora Ejecución: " + sqlJobTrigger.Job.AutomaticProcessTime.Value.ToString("HH:mm:ss");
                }
                else
                    lblAutomaticProcessTime.Text = "-";
            }
            else
            {
                lblScheduledStartExecutionDate.Text = sqlJobTrigger.ScheduledStartExecutionDate.ToString("dd/MM/yyyy");
                lblInputSchemaProcedure.Text = sqlJobTrigger.Job.InputSchemaProcedure;
                lblAutomaticProcessTime.Text = "-";
            }

            /* FIN DATOS JOB */

            /* DATOS JOBTRIGGER */
            if (String.IsNullOrEmpty(sqlJobTrigger.OutputExecutionStatus))
                lblOutputStatus.Text = "NO Ejecutado";
            else
                lblOutputStatus.Text = sqlJobTrigger.OutputExecutionStatus;

            lblTrigger.Text = jobTrigger.JobTriggerId.ToString();

            if ((sqlJobTrigger.RecordsAffected == 0) && (sqlJobTrigger.RecordsProcessed == 0))
                lblRecords.Text = "- / -";
            else
                lblRecords.Text = sqlJobTrigger.RecordsAffected.ToString() + "/" + sqlJobTrigger.RecordsProcessed.ToString();

            lblOuputExecutionLog.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionLog) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionLog;
            lblOutputResult.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionResult) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionResult;
            lblOutputExecutionTrace.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionTrace) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionTrace;

            lblJobTriggerStatus.Text = sqlJobTrigger.JobTriggerStatus.ToString().ToUpper();
            lblStartExecutionDate.Text = ((sqlJobTrigger.StartExecutionDate.HasValue) ? sqlJobTrigger.StartExecutionDate.Value.ToString("dd/MM/yyyy HH:mm:ss") : "");
            lblEndExecutionDate.Text = ((sqlJobTrigger.EndExecutionDate.HasValue) ? sqlJobTrigger.EndExecutionDate.Value.ToString("dd/MM/yyyy HH:mm:ss") : "");

            /* FIN DATOS JOBTRIGGER */
        }
 public void DeleteTrigger(JobTrigger trigger)
 {
     UnitOfWork.JobTriggerRepository.Delete(trigger);
 }
 public void KillProcess(JobTrigger jobTrigger)
 {
 }
 /// <summary>
 /// Utilizado para proceso manual agendado previamente (mediante Windows Service o desde las grillas usando el método Agendar -que disparó el método AddTrigger- sobre procesos Manuales). 
 /// El método hace un UPDATE del trigger de deshabilitado a habilitado mas otros datos, actualmente ya viene cambiado, y lo crea en Quartz para que se ejecute inmediatamente.
 /// </summary>
 /// <param name="trigger"></param>
 public void ExecuteManualJob(JobTrigger trigger)
 {
     trigger.Enabled = true;
     trigger.ScheduledStartExecutionDate = DateTime.Now;
     var job = trigger.Job;
     UnitOfWork.JobTriggerRepository.Update(trigger);
     UnitOfWork.Save();
     AddQuartzJob(job, trigger);
 }
 public void DeleteTrigger(JobTrigger trigger)
 {
     throw new NotImplementedException();
 }
 public void AddTrigger(Job job, JobTrigger trigger)
 {
 }
 public void AddQuartzJob(Job job, JobTrigger trigger)
 {
 }
 public void KillProcess(JobTrigger jobTrigger)
 {
     Helper.KillProcess((SqlJobTrigger)jobTrigger);
 }
 /// <summary>
 /// Utilizado para proceso manual que no ha sido agendado previamente, se crea el trigger en CGControlPanel y en Quartz.
 /// </summary>
 /// <param name="job">Job Manual</param>
 /// <param name="trigger"></param>
 public void ExecuteManualJob(Job job, JobTrigger trigger)
 {
     trigger.ScheduledStartExecutionDate = DateTime.Now;
     job.Triggers.Add(trigger);
     UnitOfWork.JobsRepository.Update(job);
     UnitOfWork.Save();
     AddQuartzJob(job, trigger);
 }
 public void DeleteTrigger(JobTrigger trigger)
 {
 }
 public void AddJob(Job job, JobTrigger trigger)
 {
     throw new NotImplementedException();
 }
 public void ExecuteManualJob(Job job, JobTrigger trigger)
 {
 }
        protected void FillUI(JobTrigger jobTrigger)
        {
            var sqlJobTrigger = (SqlJobTrigger)jobTrigger;

            ltrlProcessType.Text = sqlJobTrigger.Job.JobType.ToString();

            /* DATOS JOB */
            lblProcessName.Text = "ID: " + jobTrigger.Job.JobId + " - Proceso: " + jobTrigger.Job.Name + " - Grupo: " + jobTrigger.Job.Group;
            lblProcessOwner.Text = "Usuario: " + jobTrigger.Job.CreatedBy;
            lblDescription.Text = "Descripción: " + jobTrigger.Job.Description;

            // Formatea los datos con el estilo XML que muestra Internet Explorer
            txtInputValues.Text = Utils.UI.Helper.FormatXml(sqlJobTrigger.Job.InputXmlFixedParameters + sqlJobTrigger.InputFormXmlValues);

            lblComments.Text = "Comentarios: " + sqlJobTrigger.Job.Comments;
            lblProcessType.Text = "Tipo de Proceso: " + sqlJobTrigger.Job.JobType;

            Weekdays weekdays = new Weekdays();
            weekdays.AllDays = Convert.ToByte(((SqlJob)sqlJobTrigger.Job).Weekdays);

            if (weekdays.AllDays == 0)
                lblWeekDays.Text = "Frecuencia: No Diaria";
            else
                lblWeekDays.Text = "Frecuencia: " + Utils.UI.Helper.BuildPopulateDaysLegend(weekdays);

            lblServerName.Text = "Nombre Servidor: " + ((SqlJob)sqlJobTrigger.Job).ServerName;
            lblDataBaseName.Text = "Nombre BD: " + ((SqlJob)sqlJobTrigger.Job).DatabaseName;
            lblStoredProcedure.Text = "Stored de Ejecución: " + ((SqlJob)sqlJobTrigger.Job).ExecProcedure;
            lblInputXmlFixedParameters.Text = "Valores Fijos: " + sqlJobTrigger.Job.InputXmlFixedParameters;

            if (sqlJobTrigger.Job.JobType == JobType.Automático)
            {
                lblScheduledStartExecutionDate.Text = "Agendado el: " + sqlJobTrigger.ScheduledStartExecutionDate.ToString("dd/MM/yyyy HH:mm");
                lblInputSchemaProcedure.Text = "Stored de Config: -";

                if (sqlJobTrigger.Job.AutomaticProcessTime.HasValue && sqlJobTrigger.Job.Weekdays != 0)
                {
                    lblAutomaticProcessTime.Text = "Hora Ejecución: " + sqlJobTrigger.Job.AutomaticProcessTime.Value.ToString("HH:mm:ss");
                }
                else
                    divAutomaticProcessTime.Visible = false;
            }
            else
            {
                lblScheduledStartExecutionDate.Text = "Agendado el: " + sqlJobTrigger.ScheduledStartExecutionDate.ToString("dd/MM/yyyy");
                lblInputSchemaProcedure.Text = "Stored de Config: " + sqlJobTrigger.Job.InputSchemaProcedure;
                divInputSchemaProcedure.Visible = true;
                divAutomaticProcessTime.Visible = false;
            }

            /* FIN DATOS JOB */

            /* DATOS JOBTRIGGER */
            if (String.IsNullOrEmpty(sqlJobTrigger.OutputExecutionStatus))
                lblOutputStatus.Text = "Estado de la Salida: NO Ejecutado";
            else
                lblOutputStatus.Text = "Estado de la Salida: " + sqlJobTrigger.OutputExecutionStatus;

            lblTrigger.Text = "Trigger: " + jobTrigger.JobTriggerId;

            if ((sqlJobTrigger.RecordsAffected == 0) && (sqlJobTrigger.RecordsProcessed == 0))
                lblRecords.Text = "Registros: - / -";
            else
                lblRecords.Text = "Registros: " + sqlJobTrigger.RecordsAffected.ToString() + "/" + sqlJobTrigger.RecordsProcessed.ToString();

            switch (jobTrigger.JobTriggerStatus)
            {
                case JobTriggerStatus.Agendado:
                    btnDelete.Visible = true;
                    btnKillProcess.Visible = false;
                    break;
                case JobTriggerStatus.Ejecutando:
                    btnDelete.Visible = false;
                    btnKillProcess.Visible = true;
                break;
                default:
                    btnDelete.Visible = false;
                    btnKillProcess.Visible = false;
                    break;
            }

            // TODO: Poner un tag en el xmlResultado para mostrar datos luego de que arme la tabla.
            // InputValues es el resultado de la ejecución del stored de Configuración que arma el Form Dinámico
            txtXmlInputTable.Text= sqlJobTrigger.InputXmlTable;
            txtXmlOutputTable.Text = sqlJobTrigger.OutputXmlTable;

            ltrlOuputExecutionLog.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionLog) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionLog;

            ltrlOutputResult.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionResult) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionResult;
            ltrlOutputExecutionTrace.Text = string.IsNullOrEmpty(sqlJobTrigger.OutputExecutionTrace) ? "SIN DATOS PARA MOSTRAR" : sqlJobTrigger.OutputExecutionTrace;

            lblJobTriggerStatus.Text = "Estado del Proceso: " + sqlJobTrigger.JobTriggerStatus.ToString().ToUpper();
            lblStartExecutionDate.Text = "Inicio Ejecución: " + ((sqlJobTrigger.StartExecutionDate.HasValue) ? sqlJobTrigger.StartExecutionDate.Value.ToString("dd/MM/yyyy hh:mm:ss") : "");
            lblEndExecutionDate.Text = "Fin Ejecución: " + ((sqlJobTrigger.EndExecutionDate.HasValue) ? sqlJobTrigger.EndExecutionDate.Value.ToString("dd/MM/yyyy hh:mm:ss") : "");

            /* FIN DATOS JOBTRIGGER */

            lnkPrint.HRef = "/Reports/JobTriggerInfo.aspx?triggerId=" + jobTrigger.JobTriggerId;
        }
        public void DeleteTrigger(JobTrigger trigger)
        {
            if(trigger.JobTriggerStatus != JobTriggerStatus.Ejecutado)
            {
                trigger.Deleted = true;
                trigger.DeletedDate = DateTime.Now;

                if (Status() == SchedulerStatus.Apagado)
                    throw new QuartzException("El servicio scheduler se encuentra apagado");

                if (trigger.Validate())
                {
                    UnitOfWork.JobTriggerRepository.Update(trigger);
                    UnitOfWork.Save();
                    Scheduler.UnscheduleJob(new TriggerKey(trigger.JobTriggerId.ToString()));
                    return;
                }
                UnitOfWork.Save();
                Utils.Validation.Helper.BuildValidationErrors(trigger.ValidationErrors);
                Scheduler.UnscheduleJob(new TriggerKey(trigger.JobTriggerId.ToString()));
                return;
            }
            throw new Exception("Procesos ya ejecutados no pueden ser eliminados.");
        }