Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        public void Persist()
        {
            if (ID <= 0)
            {
                CreatedDate = DateTime.Now;
            }
            using (DBCommand cmd = Configuration.GetCommand()) {
                if (ID <= 0)
                {
                    cmd.CommandText = "INSERT INTO Schedules( Name, CreatedDate, JobType, JobConfiguration, TargetType, TargetConfiguration, PreCommands, PostCommands, CronConfig ) VALUES( @Name, @CreatedDate, @JobType, @JobConfiguration, @TargetType, @TargetConfiguration, @PreCommands, @PostCommands, @CronConfig );";
                    cmd.AddWithValue("@Name", Name);
                    cmd.AddWithValue("@CreatedDate", CreatedDate);
                    cmd.AddWithValue("@JobType", JobType);
                    cmd.AddWithValue("@JobConfiguration", JobConfiguration);
                    cmd.AddWithValue("@TargetType", TargetType);
                    cmd.AddWithValue("@TargetConfiguration", TargetConfiguration);
                    cmd.AddWithValue("@PreCommands", NZ(PreCommands));
                    cmd.AddWithValue("@PostCommands", NZ(PostCommands));
                    cmd.AddWithValue("@CronConfig", CronConfig);
                    cmd.ExecuteNonQuery();
                    ID = cmd.GetLastAutoIncrement();
                }
                else
                {
                    cmd.CommandText = @"
UPDATE Schedules
SET
Name = @Name,
JobType = @JobType,
PreCommands = @PreCommands,
PostCommands = @PostCommands,
JobConfiguration = @JobConfiguration,
TargetType = @TargetType,
TargetConfiguration = @TargetConfiguration,
CronConfig = @CronConfig
WHERE
Schedule_ID = @Schedule_ID";
                    cmd.AddWithValue("@Name", Name);
                    cmd.AddWithValue("@JobType", JobType);
                    cmd.AddWithValue("@PreCommands", NZ(PreCommands));
                    cmd.AddWithValue("@PostCommands", NZ(PostCommands));
                    cmd.AddWithValue("@JobConfiguration", JobConfiguration);
                    cmd.AddWithValue("@TargetType", TargetType);
                    cmd.AddWithValue("@TargetConfiguration", TargetConfiguration);
                    cmd.AddWithValue("@CronConfig", CronConfig);
                    cmd.AddWithValue("@Schedule_ID", ID);
                    cmd.ExecuteNonQuery();
                }
            }
            Configuration.ReloadService();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        public void Execute()
        {
            DateTime start   = DateTime.Now;
            bool     success = true;
            string   message;

            using (DBCommand cmd = Configuration.GetCommand()) {
                try {
                    cmd.CommandText = "UPDATE Schedules SET LastStarted = @start WHERE Schedule_ID = @ID";
                    cmd.AddWithValue("@start", start);
                    cmd.AddWithValue("@ID", ID);
                    cmd.ExecuteNonQuery();
                } catch {
                }
            }
            try {
                if (!string.IsNullOrEmpty(PreCommands))
                {
                    RunCommands(PreCommands);
                }
                message = Job.Execute(JobConfiguration, ID, Target);
                if (!string.IsNullOrEmpty(PostCommands))
                {
                    RunCommands(PostCommands);
                }
            } catch (Exception ex) {
                success = false;
                message = "{0}{1}{2}".FillBlanks(ex.Message, Environment.NewLine, ex.StackTrace);
            } finally {
                Target.Dispose();
            }
            using (DBCommand cmd = Configuration.GetCommand()) {
                DateTime now = DateTime.Now;
                try {
                    cmd.CommandText = "UPDATE Schedules SET LastFinished = @now WHERE Schedule_ID = @ID";
                    cmd.AddWithValue("@ID", ID);
                    cmd.AddWithValue("@now", now);
                    cmd.ExecuteNonQuery();
                    cmd.CommandText = "INSERT INTO ScheduleLogs( Schedule_ID, Date, Success, Entry ) VALUES( @ID, @now, @Success, @Entry )";
                    cmd.AddWithValue("@Success", success ? 1 : 0);
                    cmd.AddWithValue("@Entry", message ?? "");
                    cmd.ExecuteNonQuery();
                    _logs = null;
                } catch {
                }
            }
        }
Exemple #3
0
 /// <summary>
 ///
 /// </summary>
 public void Delete()
 {
     try {
         Job.Delete(JobConfiguration, ID);
     } catch {
     }
     using (DBCommand cmd = Configuration.GetCommand()) {
         cmd.CommandText = "DELETE FROM Schedules WHERE Schedule_ID = {0}".FillBlanks(ID);
         cmd.ExecuteNonQuery();
         cmd.CommandText = "DELETE FROM ScheduleLogs WHERE Schedule_ID = {0}".FillBlanks(ID);
     }
     Configuration.ReloadService();
 }