Exemplo n.º 1
0
        private Commands.GuiReportPlanStatus BuildGuiReportPlanStatus(Commands.OperationStatus status)
        {
            Commands.GuiReportPlanStatus data = null;

            if (RunningOperation is BackupOperation)
            {
                BackupOperation   op   = RunningOperation as BackupOperation;
                Models.BackupPlan plan = Model as Models.BackupPlan;
                data = new Commands.GuiReportPlanStatus
                {
                    Status              = status,
                    StartedAt           = op.StartedAt,
                    FinishedAt          = op.FinishedAt,
                    LastRunAt           = plan.LastRunAt,
                    LastSuccessfulRunAt = plan.LastSuccessfulRunAt,
                    //Sources = op.Sources,
                };

                // Sources
                if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED ||
                    status == Commands.OperationStatus.FINISHED ||
                    status == Commands.OperationStatus.FAILED ||
                    status == Commands.OperationStatus.CANCELED)
                {
                    data.Sources = op.Sources;
                }
            }
            else if (RunningOperation is RestoreOperation)
            {
                RestoreOperation   op   = RunningOperation as RestoreOperation;
                Models.RestorePlan plan = Model as Models.RestorePlan;
                data = new Commands.GuiReportPlanStatus
                {
                    Status              = status,
                    StartedAt           = op.StartedAt,
                    FinishedAt          = op.FinishedAt,
                    LastRunAt           = plan.LastRunAt,
                    LastSuccessfulRunAt = plan.LastSuccessfulRunAt,
                    //Sources = op.Sources,
                };

                // Sources
                if (status == Commands.OperationStatus.PROCESSING_FILES_FINISHED ||
                    status == Commands.OperationStatus.FINISHED ||
                    status == Commands.OperationStatus.FAILED ||
                    status == Commands.OperationStatus.CANCELED)
                {
                    data.Sources = op.Sources;
                }
            }
            else
            {
                string message = string.Format("Type {0} is not handled", RunningOperation.GetType().FullName);
                throw new NotImplementedException(message);
            }

            return(data);
        }
Exemplo n.º 2
0
        private void OnReportPlanStatus(object sender, GuiCommandEventArgs e)
        {
            string planType = e.Command.GetArgumentValue <string>("planType");

            if (this.Model == null || !planType.Equals("backup"))
            {
                return;
            }

            Models.BackupPlan plan = this.Model as Models.BackupPlan;

            Int32 planId = e.Command.GetArgumentValue <Int32>("planId");

            if (planId != plan.Id)
            {
                return;
            }

            Commands.GuiReportPlanStatus report = e.Command.GetArgumentValue <Commands.GuiReportPlanStatus>("report");
            UpdatePlanInfo(report);
        }
Exemplo n.º 3
0
        private void RestoreUpdateStatsInfo(RestoreOperationStatus status, TransferStatus xferStatus)
        {
            if (RunningOperation == null)
            {
                return;
            }

            Models.RestorePlan     plan      = Model as Models.RestorePlan;
            RestoreOperation       operation = RunningOperation as RestoreOperation;
            RestoreOperationReport report    = operation.Report;

            switch (status)
            {
            default: throw new ArgumentException("Unhandled status", "status");

            case RestoreOperationStatus.Unknown:
            {
                break;
            }

            case RestoreOperationStatus.Started:
            case RestoreOperationStatus.Resumed:
            {
                logger.Info("{0} restore", status == RestoreOperationStatus.Resumed ? "Resuming" : "Starting");

                // Update timestamps.
                plan.LastRunAt = DateTime.UtcNow;
                _daoRestorePlan.Update(plan);

                // Report
                Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Started
                                                        ? Commands.OperationStatus.STARTED : Commands.OperationStatus.RESUMED;
                Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ScanningFilesStarted:
            {
                logger.Info("Scanning files...");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.SCANNING_FILES_STARTED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ScanningFilesFinished:
            {
                logger.Info("Scanning files finished.");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.SCANNING_FILES_FINISHED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.ProcessingFilesStarted:
            {
                logger.Info("Processing files...");

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.PROCESSING_FILES_STARTED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                Handler.Send(Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData));
                break;
            }

            case RestoreOperationStatus.ProcessingFilesFinished:
            {
                logger.Info("Processing files finished.");
                logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total);

                // Report
                Commands.OperationStatus cmdStatus = Commands.OperationStatus.PROCESSING_FILES_FINISHED;
                // Report sources
                Commands.GuiReportPlanStatus cmdData1 = BuildGuiReportPlanStatus(cmdStatus);
                string cmd1 = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData1);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd1);
                // Report counts
                Commands.GuiReportPlanProgress cmdData2 = BuildGuiReportPlanProgress(cmdStatus);
                string cmd2 = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData2);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd2);
                break;
            }

            case RestoreOperationStatus.Finished:
            {
                //var message = string.Format(
                //	"Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running",
                //	"finished",
                //	TransferResults.Stats.Completed, TransferResults.Stats.Failed,
                //	TransferResults.Stats.Canceled, TransferResults.Stats.Pending,
                //	TransferResults.Stats.Running);
                //logger.Info(message);

                // Update success timestamp.
                plan.LastSuccessfulRunAt = DateTime.UtcNow;
                _daoRestorePlan.Update(plan);

                // Signal to the other thread it may terminate.
                RunningOperationEndedEvent.Set();

                // Report
                Commands.OperationStatus     cmdStatus = Commands.OperationStatus.FINISHED;
                Commands.GuiReportPlanStatus cmdData   = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.Updated:
            {
                if (xferStatus == TransferStatus.COMPLETED || xferStatus == TransferStatus.CANCELED || xferStatus == TransferStatus.FAILED)
                {
                    logger.Info("Completed: {0} of {1}", report.TransferResults.Stats.Completed, report.TransferResults.Stats.Total);
                }

                // Report
                Commands.OperationStatus       cmdStatus = Commands.OperationStatus.UPDATED;
                Commands.GuiReportPlanProgress cmdData   = BuildGuiReportPlanProgress(cmdStatus);
                string cmd = Commands.GuiReportOperationProgress("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }

            case RestoreOperationStatus.Failed:
            case RestoreOperationStatus.Canceled:
            {
                //var message = string.Format(
                //	"Restore {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running",
                //	status == RestoreOperationStatus.Failed ? "failed" : "was canceled",
                //	TransferResults.Stats.Completed, TransferResults.Stats.Failed,
                //	TransferResults.Stats.Canceled, TransferResults.Stats.Pending,
                //	TransferResults.Stats.Running);
                //logger.Info(message);

                // Signal to the other thread it may terminate.
                RunningOperationEndedEvent.Set();

                // Report
                Commands.OperationStatus cmdStatus = status == RestoreOperationStatus.Failed
                                                        ? Commands.OperationStatus.FAILED : Commands.OperationStatus.CANCELED;
                Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus);
                string cmd = Commands.GuiReportOperationStatus("restore", plan.Id.Value, cmdData);
                Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd);
                break;
            }
            }
        }
Exemplo n.º 4
0
        private void UpdatePlanInfo(Commands.GuiReportPlanStatus report)
        {
            CurrentOperation.Status = report.Status;

            switch (report.Status)
            {
            default: return;                     // TODO(jweyrich): Somehow report unexpected status?

            case Commands.OperationStatus.NOT_RUNNING:
            case Commands.OperationStatus.INTERRUPTED:
            {
                Models.BackupPlan plan = Model as Models.BackupPlan;

                //this.lblSources.Text = report.Sources;
                this.llblRunNow.Text = report.Status == Commands.OperationStatus.NOT_RUNNING
                                                        ? LBL_RUNNOW_STOPPED : LBL_RUNNOW_RESUME;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = report.Status == Commands.OperationStatus.NOT_RUNNING
                                                        ? LBL_STATUS_STOPPED : LBL_STATUS_INTERRUPTED;
                this.lblDuration.Text          = LBL_DURATION_INITIAL;
                this.lblFilesTransferred.Text  = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled      = true;
                this.llblDeletePlan.Enabled    = true;
                this.llblRestore.Enabled       = true;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                break;
            }

            case Commands.OperationStatus.STARTED:
            case Commands.OperationStatus.RESUMED:
            {
                Models.BackupPlan plan = Model as Models.BackupPlan;

                CurrentOperation.StartedAt           = report.StartedAt;
                CurrentOperation.LastRunAt           = report.LastRunAt;
                CurrentOperation.LastSuccessfulRunAt = report.LastSuccessfulRunAt;

                this.lblSources.Text          = this.lblSources.Text = plan.SelectedSourcesAsDelimitedString(", ", 50, "...");                        // Duplicate from BackupOperation.cs - Sources property
                this.llblRunNow.Text          = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled       = true;
                this.lblStatus.Text           = LBL_STATUS_STARTED;
                this.lblDuration.Text         = LBL_DURATION_STARTED;
                this.lblFilesTransferred.Text = string.Format("{0} of {1} ({2} / {3})",
                                                              0, 0,
                                                              FileSizeUtils.FileSizeToString(0),
                                                              FileSizeUtils.FileSizeToString(0));
                this.llblEditPlan.Enabled      = false;
                this.llblDeletePlan.Enabled    = false;
                this.llblRestore.Enabled       = false;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.GotInitialInfo = true;
                CurrentOperation.StartTimer();
                break;
            }

            case Commands.OperationStatus.SCANNING_FILES_STARTED:
            {
                this.lblSources.Text = "Scanning files...";
                break;
            }

            case Commands.OperationStatus.SCANNING_FILES_FINISHED:
            {
                break;
            }

            case Commands.OperationStatus.PROCESSING_FILES_STARTED:
            {
                this.lblSources.Text        = "Processing files...";
                this.llblRunNow.Text        = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled     = true;
                this.lblStatus.Text         = LBL_STATUS_STARTED;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;
                break;
            }

            case Commands.OperationStatus.PROCESSING_FILES_FINISHED:
            {
                this.lblSources.Text        = report.Sources;
                this.llblRunNow.Text        = LBL_RUNNOW_RUNNING;
                this.llblRunNow.Enabled     = true;
                this.lblStatus.Text         = LBL_STATUS_STARTED;
                this.llblEditPlan.Enabled   = false;
                this.llblDeletePlan.Enabled = false;
                //this.lblFilesTransferred.Text = string.Format("{0} of {1} ({2} / {3})",
                //	progress.Completed, progress.Total,
                //	FileSizeUtils.FileSizeToString(progress.BytesCompleted),
                //	FileSizeUtils.FileSizeToString(progress.BytesTotal));
                break;
            }

            case Commands.OperationStatus.UPDATED:
            {
                // Should be handled by another command.
                break;
            }

            case Commands.OperationStatus.FINISHED:
            {
                CurrentOperation.FinishedAt          = report.FinishedAt;
                CurrentOperation.LastRunAt           = report.LastRunAt;
                CurrentOperation.LastSuccessfulRunAt = report.LastSuccessfulRunAt;
                UpdateDuration(report.Status);

                this.lblSources.Text    = report.Sources;
                this.llblRunNow.Text    = LBL_RUNNOW_STOPPED;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = LBL_STATUS_COMPLETED;
                //this.lblDuration.Text = LBL_DURATION_INITIAL;
                //this.lblFilesTransferred.Text = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled      = true;
                this.llblDeletePlan.Enabled    = true;
                this.llblRestore.Enabled       = true;
                this.lblLastRun.Text           = PlanCommon.Format(CurrentOperation.LastRunAt);
                this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.Reset();
                break;
            }

            case Commands.OperationStatus.FAILED:
            case Commands.OperationStatus.CANCELED:
            {
                CurrentOperation.FinishedAt = report.LastRunAt;
                CurrentOperation.LastRunAt  = report.LastRunAt;
                UpdateDuration(report.Status);

                this.lblSources.Text    = report.Sources;
                this.llblRunNow.Text    = LBL_RUNNOW_STOPPED;
                this.llblRunNow.Enabled = true;
                this.lblStatus.Text     = report.Status == Commands.OperationStatus.CANCELED ? LBL_STATUS_CANCELED : LBL_STATUS_FAILED;
                //this.lblDuration.Text = LBL_DURATION_INITIAL;
                //this.lblFilesTransferred.Text = LBL_FILES_TRANSFER_STOPPED;
                this.llblEditPlan.Enabled   = true;
                this.llblDeletePlan.Enabled = true;
                this.llblRestore.Enabled    = true;
                this.lblLastRun.Text        = PlanCommon.Format(CurrentOperation.LastRunAt);
                //this.lblLastSuccessfulRun.Text = PlanCommon.Format(CurrentOperation.LastSuccessfulRunAt);
                //this.lblTitle.Text = PlanCommon.FormatTitle(plan.Name);
                //this.lblSchedule.Text = plan.ScheduleType.ToString();

                CurrentOperation.Reset();
                break;
            }
            }
        }
Exemplo n.º 5
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));
        }