public RestorePlanViewControl() { InitializeComponent(); AttachEventHandlers(); /* * EventDispatcher dispatcher = new EventDispatcher(); * * Watcher.Subscribe((RestoreUpdateMsg msg) => * { * if (this.Model == null) * return; * * Models.RestorePlan plan = this.Model as Models.RestorePlan; * * // Only process messages that are related to the plan associated with this control. * if (msg.PlanId != plan.Id.Value) * return; * * // IMPORTANT: Always invoke from Main thread! * dispatcher.Invoke(() => { ProcessRemoteMessage(msg); }); * }); */ this.ModelChangedEvent += (sender, args) => { if (Model == null) { return; } Models.RestorePlan plan = Model as Models.RestorePlan; if (CurrentOperation != null) { CurrentOperation.Dispose(); } CurrentOperation = new RemoteOperation(DurationTimer_Tick); CurrentOperation.Status = Commands.OperationStatus.NOT_RUNNING; CurrentOperation.LastRunAt = plan.LastRunAt; CurrentOperation.LastSuccessfulRunAt = plan.LastSuccessfulRunAt; this.lblSources.Text = plan.SelectedSourcesAsDelimitedString(", ", 50, "..."); // Duplicate from RestoreOperation.cs - Sources property this.llblRunNow.Text = LBL_RUNNOW_STOPPED; this.llblRunNow.Enabled = false; this.lblStatus.Text = "Querying status...";; this.lblDuration.Text = "Unknown";; this.lblFilesTransferred.Text = "Unknown";; this.llblEditPlan.Enabled = false; this.llblDeletePlan.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.RequestedInitialInfo = true; Provider.Handler.Send(Commands.ServerQueryPlan("restore", plan.Id.Value)); }; }
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; } } }