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); }
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); }
private void UpdateDuration(Commands.OperationStatus status) { // Prevent a NPE when accessing `CurrentOperation.StartedAt` below. if (!CurrentOperation.GotInitialInfo) { return; } // Calculate duration. var duration = !status.IsEnded() || !CurrentOperation.FinishedAt.HasValue ? DateTime.UtcNow - CurrentOperation.StartedAt.Value : CurrentOperation.FinishedAt.Value - CurrentOperation.StartedAt.Value; lblDuration.Text = TimeSpanUtils.GetReadableTimespan(duration); }
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; } } }