Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scheduleID"></param>
        /// <returns></returns>
        public static List <ScheduleJobLog> Load(int scheduleID)
        {
            List <ScheduleJobLog> list = new List <ScheduleJobLog>();

            using (DBCommand cmd = Configuration.GetCommand()) {
                try {
                    cmd.CommandText = "SELECT * FROM ScheduleLogs WHERE Schedule_ID = " + scheduleID;
                    while (cmd.Read())
                    {
                        list.Add(new ScheduleJobLog()
                        {
                            LogID      = cmd.GetInt("ScheduleLog_ID"),
                            ScheduleID = scheduleID,
                            Date       = cmd.GetDateTime("Date"),
                            Success    = cmd.GetBit("Success"),
                            Entry      = cmd.GetString("Entry")
                        });
                    }
                    if (list.Count > 1)
                    {
                        list.Sort(delegate(ScheduleJobLog x, ScheduleJobLog y) {
                            return(DateTime.Compare(x.Date, y.Date) * -1);
                        });
                    }
                } catch {
                }
            }
            return(list);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="con"></param>
        /// <param name="commandType"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static object QuickExecuteScalar(SQLiteConnection con, CommandType commandType, string command)
        {
            DBCommand cmd = new DBCommand(con, commandType, command);

            try {
                return(cmd.ExecuteScalar());
            } finally {
                cmd.Close();
            }
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 internal static BackupScheduleWrapper GetSchedule(int id)
 {
     using (DBCommand cmd = GetCommand()) {
         cmd.CommandText = "SELECT * FROM Schedules WHERE Schedule_ID = {0}".FillBlanks(id);
         while (cmd.Read())
         {
             return(new BackupScheduleWrapper(cmd.GetInt("Schedule_ID"), cmd.GetString("Name"), cmd.GetDateTime("CreatedDate"), cmd.GetString("JobType"), cmd.GetString("JobConfiguration"), cmd.GetString("TargetType"), cmd.GetString("TargetConfiguration"), cmd.GetString("PreCommands"), cmd.GetString("PostCommands"), cmd.GetString("CronConfig"), cmd.GetNullableDateTime("LastStarted"), cmd.GetNullableDateTime("LastFinished")));
         }
     }
     return(null);
 }
Beispiel #4
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();
 }
Beispiel #5
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();
        }
Beispiel #6
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 {
                }
            }
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public int GetLastAutoIncrement()
        {
            DBCommand tmpCmd = new DBCommand(Con, CommandType.Text);

            tmpCmd.CommandText = "select last_insert_rowid()";
            try {
                SQLiteDataReader r = tmpCmd.ExecuteReader();
                if (r.Read())
                {
                    return(r.GetInt32(0));
                }
                return(0);
            } catch {
                return(0);
            } finally {
                tmpCmd.Close();
            }
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        internal static List <BackupScheduleWrapper> GetSchedules()
        {
            List <BackupScheduleWrapper> list = new List <BackupScheduleWrapper>();

            using (DBCommand cmd = GetCommand()) {
                cmd.CommandText = "SELECT * FROM Schedules";
                while (cmd.Read())
                {
                    list.Add(new BackupScheduleWrapper(cmd.GetInt("Schedule_ID"), cmd.GetString("Name"), cmd.GetDateTime("CreatedDate"), cmd.GetString("JobType"), cmd.GetString("JobConfiguration"), cmd.GetString("TargetType"), cmd.GetString("TargetConfiguration"), cmd.GetString("PreCommands"), cmd.GetString("PostCommands"), cmd.GetString("CronConfig"), cmd.GetNullableDateTime("LastStarted"), cmd.GetNullableDateTime("LastFinished")));
                }
                if (list.Count > 1)
                {
                    list.Sort(delegate(BackupScheduleWrapper x, BackupScheduleWrapper y) {
                        return(string.Compare(x.Name, y.Name) * -1);
                    });
                }
            }
            return(list);
        }
Beispiel #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public int GetLastAutoIncrement()
 {
     DBCommand tmpCmd = new DBCommand( Con, CommandType.Text );
     tmpCmd.CommandText = "select last_insert_rowid()";
     try {
         SQLiteDataReader r = tmpCmd.ExecuteReader();
         if( r.Read() ) {
             return r.GetInt32( 0 );
         }
         return 0;
     } catch {
         return 0;
     } finally {
         tmpCmd.Close();
     }
 }
Beispiel #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="con"></param>
 /// <param name="commandType"></param>
 /// <param name="command"></param>
 /// <returns></returns>
 public static object QuickExecuteScalar( SQLiteConnection con, CommandType commandType, string command )
 {
     DBCommand cmd = new DBCommand( con, commandType, command );
     try {
         return cmd.ExecuteScalar();
     } finally {
         cmd.Close();
     }
 }
Beispiel #11
0
 /// <summary>
 ///
 /// </summary>
 /// <returns></returns>
 internal static DBCommand GetCommand()
 {
     return(DBCommand.Create(string.Format("{0}\\Schedules.s3db", DataDirectory.FullName)));
 }