Exemple #1
0
        /// <exception cref="System.InvalidOperationException">
        ///   Thrown when the previous backup operation has not finished yet.
        /// </exception>
        private BackupOperation CreateBackupOperation(Models.BackupPlan plan)
        {
            var dao = new BackupRepository();

            Models.Backup latest = dao.GetLatestByPlan(plan);
            MustResumeLastOperation = latest != null && latest.NeedsResume();

            if (MustResumeLastOperation && !Options.Resume)
            {
                string message = string.Format("The backup (#{0}) has not finished yet."
                                               + " If it's still running, please, wait until it finishes,"
                                               + " otherwise you should resume it manually.",
                                               latest.Id);
                throw new InvalidOperationException(message);
            }

            // Create new backup or resume the last unfinished one.
            BackupOperation obj = MustResumeLastOperation
                                ? new ResumeBackupOperation(latest) as BackupOperation
                                : new NewBackupOperation(plan) as BackupOperation;

            obj.Updated += (sender2, e2) => BackupUpdateStatsInfo(e2.Status, e2.TransferStatus);
            //obj.EventLog = ...
            //obj.TransferListControl = ...

            BackupUpdateStatsInfo(BackupOperationStatus.Unknown, TransferStatus.STOPPED);

            return(obj);
        }
Exemple #2
0
        private void OnControlPlanQuery(object sender, ServerCommandEventArgs e)
        {
            string planType = e.Command.GetArgumentValue <string>("planType");
            Int32  planId   = e.Command.GetArgumentValue <Int32>("planId");

            ValidatePlanType(planType);

            bool isRunning   = IsPlanRunning(planType, planId);
            bool needsResume = false;
            bool isFinished  = false;

            bool isBackup  = planType.Equals(PlanTypeEnum.BACKUP.ToString().ToLowerInvariant());
            bool isRestore = planType.Equals(PlanTypeEnum.RESTORE.ToString().ToLowerInvariant());

            // Report to GUI.
            Commands.GuiReportPlanStatus report = new Commands.GuiReportPlanStatus();

            if (isBackup)
            {
                BackupRepository daoBackup = new BackupRepository();
                Models.Backup    latest    = daoBackup.GetLatestByPlan(new Models.BackupPlan {
                    Id = planId
                });

                needsResume = latest != null && latest.NeedsResume();
                isFinished  = latest != null && latest.IsFinished();

                if (isRunning)
                {
                    report.StartedAt = latest.StartedAt;
                }
                else if (isFinished)
                {
                    report.FinishedAt = latest.FinishedAt;
                }
            }
            else if (isRestore)
            {
                RestoreRepository daoRestore = new RestoreRepository();
                Models.Restore    latest     = daoRestore.GetLatestByPlan(new Models.RestorePlan {
                    Id = planId
                });

                needsResume = latest != null && latest.NeedsResume();
                isFinished  = latest != null && latest.IsFinished();

                if (isRunning)
                {
                    report.StartedAt = latest.StartedAt;
                }
                else if (isFinished)
                {
                    report.FinishedAt = latest.FinishedAt;
                }
            }

            bool isInterrupted = !isRunning && needsResume;

            Commands.OperationStatus status;
            // The condition order below is important because more than one flag might be true.
            if (isInterrupted)
            {
                status = Commands.OperationStatus.INTERRUPTED;
            }
            else if (needsResume)
            {
                status = Commands.OperationStatus.RESUMED;
            }
            else if (isRunning)
            {
                status = Commands.OperationStatus.STARTED;
            }
            else
            {
                status = Commands.OperationStatus.NOT_RUNNING;
            }

            report.Status = status;

            Handler.Send(e.Context, Commands.GuiReportOperationStatus(planType, planId, report));
        }