Example #1
0
 private void UpdatePlanProgress(Commands.GuiReportPlanProgress progress)
 {
     this.lblFilesTransferred.Text = string.Format("{0} of {1} ({2} / {3})",
                                                   progress.Completed, progress.Total,
                                                   FileSizeUtils.FileSizeToString(progress.BytesCompleted),
                                                   FileSizeUtils.FileSizeToString(progress.BytesTotal));
 }
Example #2
0
        private void OnReportPlanProgress(object sender, GuiCommandEventArgs e)
        {
            if (this.Model == null || !CurrentOperation.GotInitialInfo)
            {
                return;
            }

            string planType = e.Command.GetArgumentValue <string>("planType");

            if (!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.GuiReportPlanProgress progress = e.Command.GetArgumentValue <Commands.GuiReportPlanProgress>("progress");
            UpdatePlanProgress(progress);
        }
Example #3
0
        private Commands.GuiReportPlanProgress BuildGuiReportPlanProgress(Commands.OperationStatus status)
        {
            TransferOperationReport report = RunningOperation.GetReport() as TransferOperationReport;

            Commands.GuiReportPlanProgress data = new Commands.GuiReportPlanProgress
            {
                Completed      = report.TransferResults.Stats.Completed,
                Total          = report.TransferResults.Stats.Total,
                BytesCompleted = report.TransferResults.Stats.BytesCompleted,
                BytesTotal     = report.TransferResults.Stats.BytesTotal,
            };
            return(data);
        }
Example #4
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;
            }
            }
        }