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);
        }
Beispiel #2
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);
            }
        }
        /// <summary>
        /// Applies the supplied DisplayPreset and displays a 15 second countdown to
        /// revert to the previous display configuration unless a user intervenes. This is
        /// to mimic the behavior of Windows when display resolutions are changed, and is
        /// a safety pattern in case the new display configuration is not visible.
        /// </summary>
        /// <param name="displayPreset">The display preset to apply.</param>
        public static void ApplyPresetWithRevertCountdown(DisplayPreset displayPreset)
        {
            DisplayPreset lastConfig = DisplayPresetRecorderAndApplier.ReturnLastConfigAndApplyPreset(displayPreset);

            // Pop up a dialog to give user the option to keep the configuration or else
            // automatically revert to the last configuration.
            // TODO: This seems weird to pass control away like this.
            UseAppliedPresetCountdownForm revertPresetCountdownForm = new UseAppliedPresetCountdownForm(lastConfig);

            revertPresetCountdownForm.Show();
        }
        private void CloseAndRevertPreset(bool revertPreset)
        {
            mTimer.Stop();

            if (revertPreset)
            {
                DisplayPresetRecorderAndApplier.ApplyPreset(mRevertPreset);
            }

            Close();
        }
        static public void ApplyPreset()
        {
            Console.Write("Enter name of preset to apply: ");
            string presetName = Console.ReadLine();

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            DisplayPreset targetPreset = displayPresetCollection.GetPreset(presetName);

            if (targetPreset == null)
            {
                Console.WriteLine("Preset with name '" + presetName + "' does not exist.");
                return;
            }

            Console.WriteLine("Applying preset '" + presetName + "'...");
            DisplayPresetRecorderAndApplier.ApplyPreset(targetPreset);
        }
        public static void ApplyPreset(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[] { '"', '\'' });

            DisplayPresetCollection displayPresetCollection = DisplayPresetCollection.GetDisplayPresetCollection();

            DisplayPreset displayPreset = displayPresetCollection.GetPreset(presetName);

            if (displayPreset == null)
            {
                Console.WriteLine(String.Format("Preset '{0}' does not exist.", presetName));
                return;
            }

            DisplayPresetRecorderAndApplier.ApplyPreset(displayPreset);
        }
        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.");
            }
        }