Пример #1
0
        /// <summary>
        /// Verifies that the input in the textbox is a unique name and is non-empty, calls in to
        /// OutputSwitcher.Core to create and save the new preset.
        /// </summary>
        /// <returns>True if preset created and saved. False if input is invalid or failed to save new preset.</returns>
        private bool TryCreateNewPresetWithEnteredName()
        {
            if (TextboxEnterNewPresetName.Text.Length < 1)
            {
                MessageBox.Show("Please enter at least one character.", "OutputSwitcher");
                return(false);
            }

            string newPresetName = TextboxEnterNewPresetName.Text;

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();
            DisplayPreset           existingPreset          = displayPresetCollection.GetPreset(newPresetName);

            if (existingPreset != null)
            {
                MessageBox.Show("Name already exists, please enter a unique name.", "OutputSwitcher");
                return(false);
            }

            DisplayPreset newPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(newPresetName);

            if (!displayPresetCollection.TryAddDisplayPreset(newPreset))
            {
                MessageBox.Show("Failed to save new display preset configuration.", "OutputSwitcher");
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #2
0
        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 CaptureCurrentConfigAndSaveAsPreset(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("Insufficient arguments.");
                return;
            }

            // Trim quotes in case the preset name has spaces
            string presetName = args[1].Trim(new char[] { '"', '\'' });

            DisplayPreset displayPreset = DisplayPresetRecorderAndApplier.RecordCurrentConfiguration(presetName);

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            if (displayPresetCollection.TryAddDisplayPreset(displayPreset))
            {
                Console.WriteLine(String.Format("New display preset '{0}' saved!", presetName));
            }
            else
            {
                Console.WriteLine("Failed to save preset.");
            }
        }