public void ToggleSelectRestore(int index) { RestorePlan rp = this.restorePlan; if (rp == null || rp.RestoreOperations.Count <= index) { return; } //the last index - this will include tail-Log restore operation if present if (index == rp.RestoreOperations.Count - 1) { if (this.RestoreSelected[index]) { this.RestoreSelected[index] = false; } else { for (int i = 0; i <= index; i++) { this.RestoreSelected[i] = true; } } return; } if (index == 0) { if (!this.RestoreSelected[index]) { this.RestoreSelected[index] = true; } else { for (int i = index; i < rp.RestoreOperations.Count; i++) { this.RestoreSelected[i] = false; } } return; } if (index == 1 && rp.RestoreOperations[index].BackupSet.BackupSetType == BackupSetType.Differential) { if (!this.RestoreSelected[index]) { this.RestoreSelected[0] = true; this.RestoreSelected[index] = true; } else if (rp.RestoreOperations[2].BackupSet == null) { this.RestoreSelected[index] = false; this.RestoreSelected[2] = false; } else if (this.Server.Version.Major < 9 || BackupSet.IsBackupSetsInSequence(rp.RestoreOperations[0].BackupSet, rp.RestoreOperations[2].BackupSet)) { this.RestoreSelected[index] = false; } else { for (int i = index; i < rp.RestoreOperations.Count; i++) { this.RestoreSelected[i] = false; } } return; } if (rp.RestoreOperations[index].BackupSet.BackupSetType == BackupSetType.Log) { if (this.RestoreSelected[index]) { for (int i = index; i < rp.RestoreOperations.Count; i++) { this.RestoreSelected[i] = false; } return; } else { for (int i = 0; i <= index; i++) { this.RestoreSelected[i] = true; } return; } } }
public void UpdateSelectedBackupSets() { this.backupSetsFilterInfo.Clear(); var selectedBackupSetsFromClient = this.RestoreParams.SelectedBackupSets; if (this.RestorePlan != null && this.RestorePlan.RestoreOperations != null) { for (int index = 0; index < this.RestorePlan.RestoreOperations.Count; index++) { BackupSet backupSet = this.RestorePlan.RestoreOperations[index].BackupSet; if (backupSet != null) { // If the collection client sent is null, select everything; otherwise select the items that are selected in client bool backupSetSelected = selectedBackupSetsFromClient == null || selectedBackupSetsFromClient.Any(x => BackUpSetGuidEqualsId(backupSet, x)); if (backupSetSelected) { AddBackupSetsToSelected(index, index); //the last index - this will include tail-Log restore operation if present //If the last item is selected, select all the items before that because the last item //is tail-log if (index == this.RestorePlan.RestoreOperations.Count - 1) { AddBackupSetsToSelected(0, index); } //If the second item is selected and it's a diff backup, the fist item (full backup) has to be selected if (index == 1 && backupSet.BackupSetType == BackupSetType.Differential) { AddBackupSetsToSelected(0, 0); } //If the selected item is a log backup, select all the items before that if (backupSet.BackupSetType == BackupSetType.Log) { AddBackupSetsToSelected(0, index); } } else { // If the first item is not selected which is always the full backup, other backupsets cannot be selected if (index == 0) { selectedBackupSetsFromClient = new string[] { }; } //The a log is not selected, the logs after that cannot be selected if (backupSet.BackupSetType == BackupSetType.Log) { break; } //If the second item is not selected and it's a diff backup if (index == 1 && backupSet.BackupSetType == BackupSetType.Differential) { if (this.Server.Version.Major < 9 || (this.RestorePlan.RestoreOperations.Count >= 3 && BackupSet.IsBackupSetsInSequence(this.RestorePlan.RestoreOperations[0].BackupSet, this.RestorePlan.RestoreOperations[2].BackupSet))) { // only the item at index 1 won't be selected } else { // nothing after index 1 should be selected break; } } } } } } }