Exemple #1
0
        /// <exception cref="System.InvalidOperationException">
        ///   Thrown when the previous backup operation has not finished yet.
        /// </exception>
        /// <exception cref="System.NotImplementedException">
        ///   Thrown when the previous backup operation has not finished yet and it's marked to be resumed (`options.Resume` is `true`).
        ///   The restore operation doesn't support resume.
        /// </exception>
        private RestoreOperation CreateRestoreOperation(Models.RestorePlan plan)
        {
            var dao = new RestoreRepository();

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

            if (MustResumeLastOperation && Options.Resume)
            {
                throw new NotImplementedException("The restore operation still does not support resuming.");
            }

            if (MustResumeLastOperation && !Options.Resume)
            {
                string message = string.Format("The restore (#{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 restore or resume the last unfinished one.
            RestoreOperation obj = /* MustResumeLastOperation
                                    * ? new ResumeRestoreOperation(latest) as RestoreOperation
                                    * : */new NewRestoreOperation(plan) as RestoreOperation;

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

            RestoreUpdateStatsInfo(RestoreOperationStatus.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));
        }