static public void CaptureCurrentConfigAndSaveAsPreset() { bool uniqueNameEntered = false; string presetName; DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection(); do { Console.Write("Enter name for new preset: "); presetName = Console.ReadLine(); DisplayPreset existingDisplayPreset = displayPresetCollection.GetPreset(presetName); uniqueNameEntered = existingDisplayPreset == null; if (!uniqueNameEntered) { Console.WriteLine("Preset with name '" + presetName + "' already exists. Please choose a different name."); } } while (!uniqueNameEntered); DisplayPreset newPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(presetName); if (!displayPresetCollection.TryAddDisplayPreset(newPreset)) { throw new Exception("Failed to add new preset to saved presets collection."); // This is really unexpected because we've checked for existence already. } Console.WriteLine("Added new preset!"); ConsoleOutputUtilities.WriteDisplayPresetToConsole(newPreset); }
public static void ListPresetDetail() { DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection(); List <DisplayPreset> displayPresets = displayPresetCollection.GetPresets(); Console.WriteLine("Available presets: "); IEnumerator <DisplayPreset> displayPresetsEnumerator = displayPresets.GetEnumerator(); for (int i = 0; i < displayPresets.Count; i++) { displayPresetsEnumerator.MoveNext(); Console.WriteLine(String.Format("[{0}] {1}", i, displayPresetsEnumerator.Current.Name)); } Console.Write("Select preset: "); string selection = Console.ReadLine(); int selectedPresetIndex = -1; string selectedPresetName = String.Empty; if (!Int32.TryParse(selection, out selectedPresetIndex)) { // If it's not a number, assume the user typed in a name selectedPresetName = selection; } else if (selectedPresetIndex >= displayPresets.Count) { Console.WriteLine("Invalid selection!"); return; } else { selectedPresetName = displayPresets[selectedPresetIndex].Name; } DisplayPreset selectedPreset = displayPresetCollection.GetPreset(selectedPresetName); if (selectedPreset == null) { Console.WriteLine("Invalid preset name: " + selectedPresetName); return; } ConsoleOutputUtilities.WriteDisplayPresetToConsole(selectedPreset); }