Exemplo n.º 1
0
        /// <summary>
        /// Gets the next execution date for the given schedule.
        /// </summary>
        /// <param name="schedule">The schedule to get the next execution date for.</param>
        /// <param name="now">The reference time to compare schedule dates to.</param>
        /// <returns>The schedule's next execution date.</returns>
        public static DateTime GetNextExecuteDate(ScheduleConfigurationElement schedule, DateTime now)
        {
            if (now < schedule.StartDate)
            {
                return(schedule.StartDate);
            }

            /*
             * TODO: The only repeat type is Daily right now.
             */

            int days = (int)Math.Ceiling(now.Subtract(schedule.StartDate).TotalDays);

            return(schedule.StartDate.AddDays(days));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Fires an event for this instance.
        /// </summary>
        /// <param name="handler">The event handler to fire.</param>
        /// <param name="schedule">The schedule to fire the event for.</param>
        /// <param name="target">The target to fire the event for, if applicable.</param>
        /// <param name="exception">The exeption to fire the event for, if applicable.</param>
        private void Fire(EventHandler <ScheduleEventArgs> handler, ScheduleConfigurationElement schedule, DatabaseTargetConfigurationElement target, Exception exception)
        {
            if (handler != null)
            {
                ScheduleEventArgs args = new ScheduleEventArgs()
                {
                    ErrorException = exception,
                    Name           = schedule.Name,
                    RepeatType     = schedule.Repeat,
                    StartDate      = schedule.StartDate
                };

                if (target != null)
                {
                    args.OperationType = target is DatabaseRestoreTargetConfigurationElement ? ScheduleOperationType.Restore : ScheduleOperationType.Backup;
                    args.TargetName    = target.Name;
                }

                handler(this, args);
            }
        }
Exemplo n.º 3
0
        private void ExecuteSchedule(object schd)
        {
            ScheduleConfigurationElement schedule = (ScheduleConfigurationElement)schd;

            this.Fire(this.ScheduleStart, schedule, null, null);

            foreach (ScheduleTargetConfigurationElement target in schedule.BackupTargets)
            {
                DatabaseTargetConfigurationElement config = null;

                try
                {
                    config = SThreeQLConfiguration.Section.BackupTargets[target.Name];

                    BackupTask task = new BackupTask(config);
                    task.BackupComplete   += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupComplete);
                    task.BackupStart      += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupStart);
                    task.CompressComplete += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupCompressComplete);
                    task.CompressStart    += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupCompressStart);
                    task.TransferComplete += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupTransferComplete);
                    task.TransferProgress += new EventHandler <DatabaseTargetEventArgs>(this.OnBackupTransferProgress);
                    task.TransferStart    += new EventHandler <DatabaseTargetEventArgs>(this.OnTransferStart);

                    task.Execute();
                }
                catch (Exception ex)
                {
                    this.Fire(this.ScheduleError, schedule, config, ex);
                }
            }

            foreach (ScheduleTargetConfigurationElement target in schedule.RestoreTargets)
            {
                DatabaseRestoreTargetConfigurationElement config = null;

                try
                {
                    config = SThreeQLConfiguration.Section.RestoreTargets[target.Name];

                    RestoreTask task = new RestoreTask(config);
                    task.DecompressComplete += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreDecompressComplete);
                    task.DecompressStart    += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreDecompressStart);
                    task.RestoreComplete    += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreComplete);
                    task.RestoreStart       += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreStart);
                    task.TransferComplete   += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreTransferComplete);
                    task.TransferProgress   += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreTransferProgress);
                    task.TransferStart      += new EventHandler <RestoreDatabaseTargetEventArgs>(this.OnRestoreTransferStart);

                    task.Execute();
                }
                catch (Exception ex)
                {
                    this.Fire(this.ScheduleError, schedule, config, ex);
                }
            }

            this.Fire(this.ScheduleComplete, schedule, null, null);

            lock (this)
            {
                this.inProgress.Remove(schedule.Name);
                this.pending.Add(schedule.Name, GetNextExecuteDate(schedule));
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Gets the next execution date for the given schedule.
 /// </summary>
 /// <param name="schedule">The schedule to get the next execution date for.</param>
 /// <returns>The schedule's next execution date.</returns>
 public static DateTime GetNextExecuteDate(ScheduleConfigurationElement schedule)
 {
     return(GetNextExecuteDate(schedule, DateTime.Now));
 }