public override void OnCancel() { base.OnCancel(); Models.BackupPlan plan = Model as Models.BackupPlan; _dao.Refresh(plan); }
private void cbAmazonS3_SelectionChangeCommitted(object sender, EventArgs e) { if (cbAmazonS3.SelectedIndex == 0) { using (var form = new AmazonS3AccountForm(new Models.AmazonS3Account())) { form.AccountSaved += (object sender1, AmazonS3AccountSaveEventArgs e1) => { _s3dao.Insert(e1.Account); // Insert new account into the database. LoadAccounts(Models.EStorageAccountType.AmazonS3, true); SelectExistingAccount(Models.EStorageAccountType.AmazonS3, e1.Account.Id); }; form.AccountCanceled += (object sender1, AmazonS3AccountSaveEventArgs e1) => { cbAmazonS3.SelectedIndex = -1; // Deselect it. }; form.ShowDialog(this); } } if (cbAmazonS3.SelectedIndex != -1) { Models.BackupPlan plan = Model as Models.BackupPlan; plan.StorageAccountType = Models.EStorageAccountType.AmazonS3; plan.StorageAccount = _s3dao.Get((int)cbAmazonS3.SelectedValue); } }
public override void OnFormClosed() { base.OnFormClosed(); Models.BackupPlan plan = Model as Models.BackupPlan; _dao.Refresh(plan); }
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); }
protected override bool IsValid() { Models.BackupPlan plan = Model as Models.BackupPlan; bool didSelectSource = plan.SelectedSources != null && plan.SelectedSources.Count > 0; return(didSelectSource); }
/// <exception cref="System.InvalidOperationException"> /// Thrown when the previous backup operation has not finished yet. /// </exception> private BackupOperation CreateBackupOperation(Models.BackupPlan plan) { var dao = new BackupRepository(); Models.Backup latest = dao.GetLatestByPlan(plan); MustResumeLastOperation = latest != null && latest.NeedsResume(); if (MustResumeLastOperation && !Options.Resume) { string message = string.Format("The backup (#{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 backup or resume the last unfinished one. BackupOperation obj = MustResumeLastOperation ? new ResumeBackupOperation(latest) as BackupOperation : new NewBackupOperation(plan) as BackupOperation; obj.Updated += (sender2, e2) => BackupUpdateStatsInfo(e2.Status, e2.TransferStatus); //obj.EventLog = ... //obj.TransferListControl = ... BackupUpdateStatsInfo(BackupOperationStatus.Unknown, TransferStatus.STOPPED); return(obj); }
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); }
public BackupPlanGiveNameForm() { InitializeComponent(); this.ModelChangedEvent += (sender, args) => { this.Plan = args.Model as Models.BackupPlan; // Setup data bindings textBox1.DataBindings.Clear(); textBox1.DataBindings.Add(new Binding("Text", this.Plan, this.GetPropertyName((Models.BackupPlan x) => x.Name))); }; }
private void cbFileSystem_SelectionChangeCommitted(object sender, EventArgs e) { if (cbFileSystem.SelectedIndex == 0) { MessageBox.Show("Show <Create new account> window."); } else { Models.BackupPlan plan = Model as Models.BackupPlan; plan.StorageAccountType = Models.EStorageAccountType.FileSystem; //plan.StorageAccount = new CloudStorageAccount { Id = (int)cbFileSystem.SelectedValue }; throw new NotImplementedException(); } }
private void llblEditPlan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Models.BackupPlan plan = this.Model as Models.BackupPlan; using (var presenter = new NewBackupPlanPresenter(plan)) { presenter.ShowDialog(this.ParentForm); } // Reload after edit is complete. //plan.InvalidateCachedSelectedSourcesAsDelimitedString(); //UpdateStatusInfo(Commands.OperationStatus.QUERY); Provider.Handler.Send(Commands.ServerQueryPlan("backup", plan.Id.Value)); }
protected override void OnBeforeNextOrFinish(object sender, CancelEventArgs e) { Models.BackupPlan plan = Model as Models.BackupPlan; ICollection <Models.BackupPlanSourceEntry> entries = tvFiles.GetCheckedTagData().ToBackupPlanSourceEntry(plan, _dao); plan.SelectedSources.Clear(); plan.SelectedSources.AddRange(entries); if (DoValidate && !IsValid()) { e.Cancel = true; this.ShowErrorMessage("Please, select a source."); } base.OnBeforeNextOrFinish(sender, e); }
public NewBackupPlanPresenter(Models.BackupPlan plan) { IsEditingModel = true; Model = plan; WizardFormOptions options = new WizardFormOptions { DoValidate = true }; RegisterFormClass(typeof(BackupPlanSelectAccountForm), options); RegisterFormClass(typeof(BackupPlanGiveNameForm), options); RegisterFormClass(typeof(BackupPlanSelectSourceForm), options); RegisterFormClass(typeof(SchedulablePlanForm <Models.BackupPlan>), options); RegisterFormClass(typeof(BackupPlanPurgeOptionsForm), options); RegisterFormClass(typeof(NotificationOptionsForm <Models.BackupPlan>), options); RegisterFormClass(typeof(ExecuteCommandsForm), options); }
private void llblDeletePlan_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Models.BackupPlan plan = Model as Models.BackupPlan; DialogResult result = MessageBox.Show( "Are you sure you want to delete this plan?", string.Format("Deleting {0}", plan.Name), MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (result == DialogResult.Yes) { _daoBackupPlan.Delete(plan); Model = null; OnDelete(this, e); } }
// // Loads or creates `BackupPlanFile`s for each file in `filePaths`. // Returns the complete list of `BackupPlanFile`s that are related to `filePaths`. // If a `BackupPlanFile` does not exist for a given filePath, one will be created. // // NOTE: This method does NOT change the database. // private LinkedList <Models.BackupPlanFile> DoLoadOrCreateBackupPlanFiles(Models.BackupPlan plan, LinkedList <string> filePaths) { Assert.IsNotNull(plan); Assert.IsNotNull(filePaths); Assert.IsNotNull(AllFilesFromPlan); BlockPerfStats stats = new BlockPerfStats(); stats.Begin(); Dictionary <string, Models.BackupPlanFile> processed = new Dictionary <string, Models.BackupPlanFile>(); // Check all files. foreach (string path in filePaths) { // Throw if the operation was canceled. CancellationToken.ThrowIfCancellationRequested(); string normalizedPath = StringUtils.NormalizeUsingPreferredForm(path); // // Create or update `BackupPlanFile`. // Models.BackupPlanFile backupPlanFile = null; // The complexity of Dictionary<TKey,TValue>.TryGetValue(TKey,TValue) approaches O(1) bool backupPlanFileAlreadyExists = AllFilesFromPlan.TryGetValue(normalizedPath, out backupPlanFile); if (!backupPlanFileAlreadyExists) { backupPlanFile = new Models.BackupPlanFile(plan, normalizedPath); backupPlanFile.CreatedAt = DateTime.UtcNow; } // This avoids duplicates in the list. // The complexity of setting Dictionary<TKey,TValue>[TKey] is amortized O(1) processed[normalizedPath] = backupPlanFile; } LinkedList <Models.BackupPlanFile> result = processed.ToLinkedList <Models.BackupPlanFile, KeyValuePair <string, Models.BackupPlanFile> >(p => p.Value); stats.End(); return(result); }
public bool ControlsAlreadyContainControlForPlan(Models.BackupPlan plan) { foreach (Control ctrl in this.layoutPanel.Controls) { if (!(ctrl is BackupPlanViewControl)) { continue; } BackupPlanViewControl obj = ctrl as BackupPlanViewControl; Models.BackupPlan objPlan = obj.Model as Models.BackupPlan; if (objPlan.Id.Equals(plan.Id)) { return(true); } } return(false); }
public BackupPlanSelectSourceForm() { InitializeComponent(); loadingPanel.Dock = DockStyle.Fill; tvFiles.ExpandFetchStarted += (object sender, EventArgs e) => { //loadingPanel.Visible = true; }; tvFiles.ExpandFetchEnded += (object sender, EventArgs e) => { //loadingPanel.Visible = false; }; this.ModelChangedEvent += (object sender, Teltec.Forms.Wizard.WizardForm.ModelChangedEventArgs e) => { Models.BackupPlan plan = e.Model as Models.BackupPlan; // Lazily select nodes that match entries from `plan.SelectedSources`. tvFiles.CheckedDataSource = BackupPlanSelectedSourcesToCheckedDataSource(plan); }; }
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); }
private void llblRunNow_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { Models.BackupPlan plan = this.Model as Models.BackupPlan; if (OperationIsRunning) { // These buttons are re-enabled after the GUI receives the command `Commands.GUI_REPORT_PLAN_STATUS` // where the report status is one of these: // Commands.OperationStatus.FAILED: // Commands.OperationStatus.CANCELED: // Commands.OperationStatus.FINISHED: this.llblRunNow.Enabled = false; this.llblEditPlan.Enabled = false; this.llblDeletePlan.Enabled = false; this.llblRestore.Enabled = false; Provider.Handler.Send(Commands.ServerCancelPlan("backup", plan.Id.Value)); } else { // These buttons are re-enabled after the GUI receives the command `Commands.GUI_REPORT_PLAN_STATUS` // where the report status is one of these: // Commands.OperationStatus.FAILED: // Commands.OperationStatus.CANCELED: // Commands.OperationStatus.FINISHED: this.llblRunNow.Enabled = false; this.llblEditPlan.Enabled = false; this.llblDeletePlan.Enabled = false; this.llblRestore.Enabled = false; string cmd = CurrentOperation.Status == Commands.OperationStatus.INTERRUPTED ? Commands.ServerResumePlan("backup", plan.Id.Value) : Commands.ServerRunPlan("backup", plan.Id.Value); Provider.Handler.Send(cmd); } }
public BackupPlanSelectAccountForm() { InitializeComponent(); this.ModelChangedEvent += (sender, args) => { this.Plan = args.Model as Models.BackupPlan; switch (this.Plan.StorageAccountType) { case Models.EStorageAccountType.AmazonS3: rbtnAmazonS3.Checked = true; break; case Models.EStorageAccountType.FileSystem: rbtnFileSystem.Checked = true; break; } if (this.Plan.StorageAccountType != Models.EStorageAccountType.Unknown) { LoadAccounts(this.Plan.StorageAccountType); if (this.Plan.StorageAccount != null) { SelectExistingAccount(this.Plan.StorageAccountType, this.Plan.StorageAccount.Id); } } }; // Setup data bindings cbAmazonS3.DataBindings.Add(new Binding("Enabled", rbtnAmazonS3, this.GetPropertyName((RadioButton x) => x.Checked))); cbFileSystem.DataBindings.Add(new Binding("Enabled", rbtnFileSystem, this.GetPropertyName((RadioButton x) => x.Checked))); }
public BackupPlanPurgeOptionsForm() { InitializeComponent(); this.ModelChangedEvent += (sender, args) => { this.Plan = args.Model as Models.BackupPlan; if (this.Plan.PurgeOptions == null) { this.Plan.PurgeOptions = new Models.BackupPlanPurgeOptions(); } // Setup data bindings switch (this.Plan.PurgeOptions.PurgeType) { case Models.BackupPlanPurgeTypeEnum.DEFAULT: rbtnDefault.Checked = true; break; case Models.BackupPlanPurgeTypeEnum.CUSTOM: rbtnCustom.Checked = true; break; } // Remove all data bindings ClearBindings(); // Load Model default values ModelDefaults(); // Setup Form state based on Model ModelToForm(); // Setup data bindings between Form <=> Model WireBindings(); }; }
public override void OnFinish() { base.OnFinish(); Models.BackupPlan plan = Model as Models.BackupPlan; Console.WriteLine("Name = {0}", plan.Name); Console.WriteLine("StorageAccount = {0}", plan.StorageAccount.DisplayName); Console.WriteLine("StorageAccountType = {0}", plan.StorageAccountType.ToString()); foreach (Models.BackupPlanSourceEntry entry in plan.SelectedSources) { Console.WriteLine("SelectedSource => #{0}, {1}, {2}", entry.Id, entry.Type.ToString(), entry.Path); } Console.WriteLine("ScheduleType = {0}", plan.ScheduleType.ToString()); Console.WriteLine("Schedule.ScheduleType = {0}", plan.Schedule.ScheduleType.ToString()); Models.PlanSchedule schedule = plan.Schedule; switch (plan.ScheduleType) { case Models.ScheduleTypeEnum.RUN_MANUALLY: break; case Models.ScheduleTypeEnum.SPECIFIC: Console.WriteLine("OccursSpecificallyAt = {0}", schedule.OccursSpecificallyAt.HasValue ? schedule.OccursSpecificallyAt.Value.ToString() : "null"); break; case Models.ScheduleTypeEnum.RECURRING: Console.WriteLine("RecurrencyFrequencyType = {0}", schedule.RecurrencyFrequencyType.HasValue ? schedule.RecurrencyFrequencyType.Value.ToString() : "null"); Console.WriteLine("RecurrencyDailyFrequencyType = {0}", schedule.RecurrencyDailyFrequencyType.HasValue ? schedule.RecurrencyDailyFrequencyType.Value.ToString() : "null"); if (schedule.RecurrencyFrequencyType.HasValue) { switch (schedule.RecurrencyFrequencyType.Value) { case Models.FrequencyTypeEnum.DAILY: break; case Models.FrequencyTypeEnum.WEEKLY: Console.WriteLine("OccursAtDaysOfWeek = {0}", schedule.OccursAtDaysOfWeek != null ? schedule.OccursAtDaysOfWeek.ToReadableString() : "null"); break; case Models.FrequencyTypeEnum.MONTHLY: Console.WriteLine("MonthlyOccurrenceType = {0}", schedule.MonthlyOccurrenceType.HasValue ? schedule.MonthlyOccurrenceType.Value.ToString() : "null"); Console.WriteLine("OccursMonthlyAtDayOfWeek = {0}", schedule.OccursMonthlyAtDayOfWeek.HasValue ? schedule.OccursMonthlyAtDayOfWeek.Value.ToString() : "null"); break; case Models.FrequencyTypeEnum.DAY_OF_MONTH: Console.WriteLine("OccursAtDayOfMonth = {0}", schedule.OccursAtDayOfMonth.HasValue ? schedule.OccursAtDayOfMonth.Value.ToString() : "null"); break; } } Console.WriteLine("RecurrencySpecificallyAtTime = {0}", schedule.RecurrencySpecificallyAtTime.HasValue ? schedule.RecurrencySpecificallyAtTime.Value.ToString() : "null"); Console.WriteLine("RecurrencyTimeInterval = {0}", schedule.RecurrencyTimeInterval.HasValue ? schedule.RecurrencyTimeInterval.Value.ToString() : "null"); Console.WriteLine("RecurrencyTimeUnit = {0}", schedule.RecurrencyTimeUnit.HasValue ? schedule.RecurrencyTimeUnit.Value.ToString() : "null"); Console.WriteLine("RecurrencyWindowStartsAtTime = {0}", schedule.RecurrencyWindowStartsAtTime.HasValue ? schedule.RecurrencyWindowStartsAtTime.Value.ToString() : "null"); Console.WriteLine("RecurrencyWindowEndsAtTime = {0}", schedule.RecurrencyWindowEndsAtTime.HasValue ? schedule.RecurrencyWindowEndsAtTime.Value.ToString() : "null"); Console.WriteLine("PurgeOptions.PurgeType = {0}", plan.PurgeOptions.PurgeType.ToString()); switch (plan.PurgeOptions.PurgeType) { case Models.BackupPlanPurgeTypeEnum.DEFAULT: break; case Models.BackupPlanPurgeTypeEnum.CUSTOM: Console.WriteLine("EnabledKeepNumberOfVersions = {0}", plan.PurgeOptions.EnabledKeepNumberOfVersions); Console.WriteLine("NumberOfVersionsToKeep = {0}", plan.PurgeOptions.NumberOfVersionsToKeep); break; } break; } plan.UpdatedAt = DateTime.UtcNow; //try //{ if (IsEditingModel) { _dao.Update(plan); } else { plan.StorageAccount.Hostname = Environment.MachineName; _dao.Insert(plan); } //} //catch (Exception ex) //{ // MessageBox.Show(ex.Message, "Error"); //} }
public BackupPlanViewControl() { InitializeComponent(); AttachEventHandlers(); /* * EventDispatcher dispatcher = new EventDispatcher(); * * Watcher.Subscribe((BackupUpdateMsg msg) => * { * if (this.Model == null) * return; * * Models.BackupPlan plan = this.Model as Models.BackupPlan; * * // 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.BackupPlan plan = Model as Models.BackupPlan; 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 BackupOperation.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.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.RequestedInitialInfo = true; Provider.Handler.Send(Commands.ServerQueryPlan("backup", 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; } } }
protected void RegisterResultsEventHandlers(Models.Backup backup, TransferResults results) { BackupedFileRepository daoBackupedFile = new BackupedFileRepository(); results.DeleteCompleted += (object sender, DeletionArgs e) => { Int64?backupedFileId = (Int64?)e.UserData; // TODO(jweyrich): We could get rid of the SELECT and perform just the UPDATE. Models.BackupedFile backupedFile = daoBackupedFile.Get(backupedFileId.Value); backupedFile.TransferStatus = TransferStatus.PURGED; backupedFile.UpdatedAt = DateTime.UtcNow; daoBackupedFile.Update(backupedFile); //var message = string.Format("Purged {0}", e.FilePath); //Info(message); //OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = message }); }; results.Failed += (object sender, TransferFileProgressArgs args) => { Models.BackupedFile backupedFile = daoBackupedFile.GetByBackupAndPath(backup, args.FilePath); backupedFile.TransferStatus = TransferStatus.FAILED; backupedFile.UpdatedAt = DateTime.UtcNow; daoBackupedFile.Update(backupedFile); var message = string.Format("Failed {0} - {1}", args.FilePath, args.Exception != null ? args.Exception.Message : "Unknown reason"); Warn(message); //StatusInfo.Update(BackupStatusLevel.ERROR, message); OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = message, TransferStatus = TransferStatus.FAILED }); }; results.Canceled += (object sender, TransferFileProgressArgs args) => { Models.BackupedFile backupedFile = daoBackupedFile.GetByBackupAndPath(backup, args.FilePath); backupedFile.TransferStatus = TransferStatus.CANCELED; backupedFile.UpdatedAt = DateTime.UtcNow; daoBackupedFile.Update(backupedFile); var message = string.Format("Canceled {0} - {1}", args.FilePath, args.Exception != null ? args.Exception.Message : "Unknown reason"); Warn(message); //StatusInfo.Update(BackupStatusLevel.ERROR, message); OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = message, TransferStatus = TransferStatus.CANCELED }); }; results.Completed += (object sender, TransferFileProgressArgs args) => { Models.BackupedFile backupedFile = daoBackupedFile.GetByBackupAndPath(backup, args.FilePath); backupedFile.TransferStatus = TransferStatus.COMPLETED; backupedFile.UpdatedAt = DateTime.UtcNow; daoBackupedFile.Update(backupedFile); var message = string.Format("Completed {0}", args.FilePath); Info(message); OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = message, TransferStatus = TransferStatus.COMPLETED }); Models.BackupPlan plan = Backup.BackupPlan; //backupedFile.Backup.BackupPlan; if (plan.PurgeOptions != null && plan.PurgeOptions.IsTypeCustom && plan.PurgeOptions.EnabledKeepNumberOfVersions) { // Purge the oldest versioned files if the count of versions exceeds the maximum specified for the Backup Plan. IList <Models.BackupedFile> previousVersions = daoBackupedFile.GetCompleteByPlanAndPath(plan, args.FilePath); int found = previousVersions.Count; int keep = plan.PurgeOptions.NumberOfVersionsToKeep; int diff = found - keep; if (diff > 0) { // Delete the oldest Count-N versions. List <Models.BackupedFile> versionsToPurge = previousVersions.Skip(keep).ToList(); foreach (var vp in versionsToPurge) { DeleteVersionedFile(vp.File.Path, new FileVersion { Version = vp.Version }, vp.Id); } } } }; results.Started += (object sender, TransferFileProgressArgs args) => { Models.BackupedFile backupedFile = daoBackupedFile.GetByBackupAndPath(backup, args.FilePath); backupedFile.TransferStatus = TransferStatus.RUNNING; backupedFile.UpdatedAt = DateTime.UtcNow; daoBackupedFile.Update(backupedFile); var message = string.Format("Started {0}", args.FilePath); Info(message); OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = message }); }; results.Progress += (object sender, TransferFileProgressArgs args) => { #if DEBUG var message = string.Format("Progress {0}% {1} ({2}/{3} bytes)", args.PercentDone, args.FilePath, args.TransferredBytes, args.TotalBytes); //Info(message); #endif OnUpdate(new BackupOperationEvent { Status = BackupOperationStatus.Updated, Message = null }); }; }
private Dictionary <string, FileSystemTreeNodeData> BackupPlanSelectedSourcesToCheckedDataSource(Models.BackupPlan plan) { return(plan.SelectedSources.ToDictionary( e => e.Path, e => new FileSystemTreeNodeData { Id = e.Id, Type = Models.EntryTypeExtensions.ToTypeEnum(e.Type), Path = e.Path, State = Teltec.Common.Controls.CheckState.Checked } )); }
public BackupPlanFile(BackupPlan plan, string path) : this(plan.StorageAccount) { _BackupPlan = plan; _Path = path; }
public BackupPlanFile(BackupPlan plan) : this(plan.StorageAccount) { _BackupPlan = plan; }
public NewBackupOperation(Models.BackupPlan plan, BackupOperationOptions options) : base(options) { Backup = new Models.Backup(plan); }
private void BackupUpdateStatsInfo(BackupOperationStatus status, TransferStatus xferStatus) { if (RunningOperation == null) { return; } Models.BackupPlan plan = Model as Models.BackupPlan; BackupOperation operation = RunningOperation as BackupOperation; BackupOperationReport report = operation.Report; switch (status) { default: throw new ArgumentException("Unhandled status", "status"); case BackupOperationStatus.Unknown: { break; } case BackupOperationStatus.Started: case BackupOperationStatus.Resumed: { logger.Info("{0} backup", status == BackupOperationStatus.Resumed ? "Resuming" : "Starting"); // Update timestamps. plan.LastRunAt = DateTime.UtcNow; _daoBackupPlan.Update(plan); // Report Commands.OperationStatus cmdStatus = status == BackupOperationStatus.Started ? Commands.OperationStatus.STARTED : Commands.OperationStatus.RESUMED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.ScanningFilesStarted: { logger.Info("Scanning files..."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.SCANNING_FILES_STARTED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.ScanningFilesFinished: { logger.Info("Scanning files finished."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.SCANNING_FILES_FINISHED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.ProcessingFilesStarted: { logger.Info("Processing files..."); // Report Commands.OperationStatus cmdStatus = Commands.OperationStatus.PROCESSING_FILES_STARTED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.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("backup", plan.Id.Value, cmdData1); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd1); // Report counts Commands.GuiReportPlanProgress cmdData2 = BuildGuiReportPlanProgress(cmdStatus); string cmd2 = Commands.GuiReportOperationProgress("backup", plan.Id.Value, cmdData2); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd2); break; } case BackupOperationStatus.Finished: { //var message = string.Format( // "Backup {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; _daoBackupPlan.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("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.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("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } case BackupOperationStatus.Failed: case BackupOperationStatus.Canceled: { //var message = string.Format( // "Backup {0}! Stats: {1} completed, {2} failed, {3} canceled, {4} pending, {5} running", // status == BackupOperationStatus.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 == BackupOperationStatus.Failed ? Commands.OperationStatus.FAILED : Commands.OperationStatus.CANCELED; Commands.GuiReportPlanStatus cmdData = BuildGuiReportPlanStatus(cmdStatus); string cmd = Commands.GuiReportOperationStatus("backup", plan.Id.Value, cmdData); Handler.Route(Commands.IPC_DEFAULT_GUI_CLIENT_NAME, cmd); break; } } }
public NewBackupOperation(Models.BackupPlan plan) : this(plan, new BackupOperationOptions()) { }