Exemplo n.º 1
0
        public static bool IsJobRunning(BackupScheduleWrapper job)
        {
            string procName = "Bummer.ScheduleRunner.{0}".FillBlanks(job.ID);

            Process[] processes = Process.GetProcessesByName(procName);
            return(processes.Length > 0);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <b>ScheduleForm</b> class.
 /// </summary>
 /// <param name="job"></param>
 public ScheduleForm(BackupScheduleWrapper job)
 {
     InitializeComponent();
     _job           = job.Clone();
     timer          = new Timer();
     timer.Interval = 1000;
     timer.Tick    += timer_Tick;
     timer.Start();
 }
Exemplo n.º 3
0
 public ScheduleItemControl(BackupScheduleWrapper job)
 {
     InitializeComponent();
     this.job       = job ?? new BackupScheduleWrapper();
     Disposed      += ScheduleItemControl_Disposed;
     timer          = new Timer();
     timer.Interval = 1000;
     timer.Tick    += timer_Tick;
     timer.Start();
 }
Exemplo n.º 4
0
 public ScheduleItemControl( BackupScheduleWrapper job )
 {
     InitializeComponent();
     this.job = job ?? new BackupScheduleWrapper();
     Disposed += ScheduleItemControl_Disposed;
     timer = new Timer();
     timer.Interval = 1000;
     timer.Tick += timer_Tick;
     timer.Start();
 }
Exemplo n.º 5
0
        public static bool SpawAndRun(BackupScheduleWrapper job)
        {
            SpawnLogger.Log("Spawn request {0}".FillBlanks(job.Name));
            string procName = "Bummer.ScheduleRunner.{0}".FillBlanks(job.ID);

            Process[] processes = Process.GetProcessesByName(procName);
            if (processes.Length > 0)
            {
                SpawnLogger.Log("Spawn request, already running {0}".FillBlanks(job.Name));
                return(false);
            }
            DirectoryInfo dir = new DirectoryInfo(Configuration.DataDirectory.FullName + "\\" + job.ID);

            if (Directory.Exists(dir.FullName))
            {
                try {
                    Directory.Delete(dir.FullName, true);
                } catch (Exception ex) {
                    SpawnLogger.Log("Spawn request, cleanup failed {0}: {1}".FillBlanks(job.Name, ex.Message));
                    return(false);
                }
            }
            Type          t      = typeof(ScheduleJobSpawner);
            FileInfo      fi     = new FileInfo(t.Assembly.Location);
            DirectoryInfo binDir = new DirectoryInfo(fi.DirectoryName);

            binDir.Copy(dir.FullName, true);
            string exeName = "{0}\\{1}.exe".FillBlanks(dir.FullName, procName);

            fi.CopyTo(exeName, true);
            FileInfo[] configs = binDir.GetFiles("*.config");
            foreach (FileInfo configFile in configs)
            {
                if (configFile.Name.Contains(".vshost."))
                {
                    continue;
                }
                configFile.CopyTo(exeName + ".config");
                break;
            }
            SpawnLogger.Log("Spawn request spawning {0}".FillBlanks(job.Name));
            Process p = new Process();

            p.StartInfo = new ProcessStartInfo(exeName);
            p.StartInfo.CreateNoWindow  = true;
            p.StartInfo.UseShellExecute = false;
            p.EnableRaisingEvents       = true;
            p.Exited += p_Exited;
            p.Start();
            return(true);
        }
Exemplo n.º 6
0
        public void Execute(JobExecutionContext context)
        {
            int jobID;

            if (!int.TryParse(context.JobDetail.Name, out jobID))
            {
                Logger.Log("Error getting ID for job to execute", LogStatuses.Error);
                return;
            }
            BackupScheduleWrapper schedule = Configuration.GetSchedule(jobID);

            if (schedule == null)
            {
                Logger.Log("Error getting Schedule for {0}".FillBlanks(jobID), LogStatuses.Error);
                return;
            }
            Logger.Log("Running schedule {0}".FillBlanks(schedule.Name), LogStatuses.Execute);
            ScheduleJobSpawner.SpawAndRun(schedule);
        }
Exemplo n.º 7
0
        static void Main()
        {
            //bool s = true;
            //while( s ) {
            //    Thread.Sleep( 100 );
            //}
            SpawnLogger.Log("Spawn starting");
            Process p = Process.GetCurrentProcess();
            string  n = p.ProcessName.Replace("Bummer.ScheduleRunner.", "");
            int     id;

            if (!int.TryParse(n, out id))
            {
                SpawnLogger.Log("Spawn failed to parse ID from {0}".FillBlanks(n));
                Console.WriteLine("Invalid start of ScheduleRunner");
                Console.Error.WriteLine("Invalid start of ScheduleRunner");
                return;
            }
            BackupScheduleWrapper sc = Configuration.GetSchedule(id);

            if (sc == null)
            {
                SpawnLogger.Log("Spawn unable to find schedule {0}".FillBlanks(id));
                Console.WriteLine("ScheduleRunner is unable to find schedule to run");
                Console.Error.WriteLine("ScheduleRunner is unable to find schedule to run");
                return;
            }
            Process[] processesRunning = Process.GetProcessesByName(p.ProcessName);
            if (processesRunning.Length > 1)
            {
                SpawnLogger.Log("Spawn {0} already running".FillBlanks(id));
                Console.WriteLine("ScheduleRunner's schedule is already running");
                Console.Error.WriteLine("ScheduleRunner's schedule is already running");
                return;
            }
            SpawnLogger.Log("Spawn executing schedule {0}".FillBlanks(sc.Name));
            try {
                sc.Execute();
            } catch (Exception ex) {
                SpawnLogger.Log("Spawn execution error for schedule {0}: {1}".FillBlanks(sc.Name, ex.Message));
            }
        }
Exemplo n.º 8
0
 public static bool SpawAndRun( BackupScheduleWrapper job )
 {
     SpawnLogger.Log( "Spawn request {0}".FillBlanks( job.Name ) );
     string procName = "Bummer.ScheduleRunner.{0}".FillBlanks( job.ID );
     Process[] processes = Process.GetProcessesByName( procName );
     if( processes.Length > 0 ) {
         SpawnLogger.Log( "Spawn request, already running {0}".FillBlanks( job.Name ) );
         return false;
     }
     DirectoryInfo dir = new DirectoryInfo( Configuration.DataDirectory.FullName + "\\" + job.ID );
     if( Directory.Exists( dir.FullName ) ) {
         try {
             Directory.Delete( dir.FullName, true );
         } catch( Exception ex ) {
             SpawnLogger.Log( "Spawn request, cleanup failed {0}: {1}".FillBlanks( job.Name, ex.Message ) );
             return false;
         }
     }
     Type t = typeof(ScheduleJobSpawner);
     FileInfo fi = new FileInfo( t.Assembly.Location );
     DirectoryInfo binDir = new DirectoryInfo( fi.DirectoryName );
     binDir.Copy( dir.FullName, true );
     string exeName = "{0}\\{1}.exe".FillBlanks( dir.FullName, procName );
     fi.CopyTo( exeName, true );
     FileInfo[] configs = binDir.GetFiles( "*.config" );
     foreach( FileInfo configFile in configs ) {
         if( configFile.Name.Contains( ".vshost." ) ) {
             continue;
         }
         configFile.CopyTo( exeName + ".config" );
         break;
     }
     SpawnLogger.Log( "Spawn request spawning {0}".FillBlanks( job.Name ) );
     Process p = new Process();
     p.StartInfo = new ProcessStartInfo( exeName );
     p.StartInfo.CreateNoWindow = true;
     p.StartInfo.UseShellExecute = false;
     p.EnableRaisingEvents = true;
     p.Exited += p_Exited;
     p.Start();
     return true;
 }
Exemplo n.º 9
0
        /// <summary>
        /// This method is called when the btnTryPostCommand's Click event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> of the event.</param>
        private void btnTryPostCommand_Click(object sender, EventArgs e)
        {
            if (lvPostCommands.Items.Count == 0)
            {
                MessageBox.Show("There are no commands to run...");
                return;
            }
            List <string> list = new List <string>();

            foreach (ListViewItem li in lvPostCommands.Items)
            {
                list.Add("{0}\t{1}".FillBlanks(li.Text, li.SubItems[1].Text));
            }
            string commands = list.ToString(Environment.NewLine);

            try {
                BackupScheduleWrapper.RunCommands(commands);
            } catch (Exception ex) {
                MessageBox.Show("Error: {0}".FillBlanks(ex.Message));
            }
        }
Exemplo n.º 10
0
        void ShowJobSettings(object sender, EventArgs e)
        {
            MenuItem si = sender as MenuItem;

            if (si == null)
            {
                return;
            }
            BackupScheduleWrapper job = Configuration.GetSchedule((int)si.Tag);
            ScheduleForm          sf  = new ScheduleForm(job);

            sf.ShowInTaskbar = true;
            if (sf.ShowDialog(this) == DialogResult.OK)
            {
                try {
                    sf.Job.Persist();
                } catch (Exception ex) {
                    MessageBox.Show("Error saving schedule: {0}".FillBlanks(ex.Message));
                    return;
                }
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// This method is called when the ScheduleForm's FormClosing event has been fired.
        /// </summary>
        /// <param name="sender">The <see cref="object"/> that fired the event.</param>
        /// <param name="e">The <see cref="FormClosingEventArgs"/> of the event.</param>
        private void ScheduleForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (DialogResult != DialogResult.OK)
            {
                timer.Stop();
                timer.Dispose();
                return;
            }
            string cronString;

            try {
                cronString = cronControl.CRONString;
                CronExpression ce   = new CronExpression(cronString);
                DateTime?      next = ce.GetNextValidTimeAfter(DateTime.Now);
                if (!next.HasValue)
                {
                    MessageBox.Show("You have to select repetitions for the job");
                }
            } catch (Exception ex) {
                MessageBox.Show("Repetition error{0}{1}".FillBlanks(Environment.NewLine, ex.Message), "Repetition error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (DialogResult != DialogResult.OK)
            {
                return;
            }
            if (string.IsNullOrEmpty(tbName.Text))
            {
                MessageBox.Show("You have to specify a name", "Specify name", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (cbJobType.SelectedIndex < 0)
            {
                MessageBox.Show("You have to specify a job type", "Specify job type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            if (cbTargetType.SelectedIndex < 0)
            {
                MessageBox.Show("You have to specify a target type", "Specify target type", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            string config;
            string targetConfig;

            try {
                config       = Job.Job.SaveConfiguration();
                targetConfig = target.SaveConfiguration();
            } catch (Exception ex) {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                e.Cancel = true;
                return;
            }
            _job     = Job.Clone();
            Job.Name = tbName.Text;
            PlugWrapper pw = (PlugWrapper)cbJobType.SelectedItem;

            Job.JobType             = pw.job.GetType().FullName;
            Job.JobConfiguration    = config;
            Job.TargetConfiguration = targetConfig;
            Job.CronConfig          = cronString;
            Job.PreCommands         = null;
            if (lvPreCommands.Items.Count > 0)
            {
                List <string> list = new List <string>();
                foreach (ListViewItem li in lvPreCommands.Items)
                {
                    list.Add("{0}\t{1}".FillBlanks(li.Text, li.SubItems[1].Text));
                }
                Job.PreCommands = list.ToString(Environment.NewLine);
            }
            Job.PostCommands = null;
            if (lvPostCommands.Items.Count > 0)
            {
                List <string> list = new List <string>();
                foreach (ListViewItem li in lvPostCommands.Items)
                {
                    list.Add("{0}\t{1}".FillBlanks(li.Text, li.SubItems[1].Text));
                }
                Job.PostCommands = list.ToString(Environment.NewLine);
            }
            timer.Stop();
            timer.Dispose();
        }
Exemplo n.º 12
0
 public LogViewerForm(BackupScheduleWrapper job = null)
 {
     InitializeComponent();
     this.job = job;
 }
Exemplo n.º 13
0
 public static bool IsJobRunning( BackupScheduleWrapper job )
 {
     string procName = "Bummer.ScheduleRunner.{0}".FillBlanks( job.ID );
     Process[] processes = Process.GetProcessesByName( procName );
     return processes.Length > 0;
 }
Exemplo n.º 14
0
 public LogViewerForm( BackupScheduleWrapper job = null )
 {
     InitializeComponent();
     this.job = job;
 }