public override SystemSettingsSwitcher CreateSystemSettingsSwitcher(CommandBase owner, SystemSettingsSwitcherSettings settings)
        {
            // argument checks
            SystemSettingsSwitcherForWindowsSettings actualSettings = null;

            if (settings != null)
            {
                actualSettings = settings as SystemSettingsSwitcherForWindowsSettings;
                if (actualSettings == null)
                {
                    throw new ArgumentNullException($"It must be {nameof(SystemSettingsSwitcherForWindowsSettings)} class.", nameof(settings));
                }
            }

            return(new SystemSettingsSwitcherForWindows(owner, actualSettings));
        }
Esempio n. 2
0
        protected override bool HandleOption(string name, string value, CommandSettings settings)
        {
            // handle option
            bool handled = true;

            if (AreSameOptionNames(name, OptionNames.ProxyOverride))
            {
                SystemSettingsSwitcherForWindowsSettings actualSettings = (SystemSettingsSwitcherForWindowsSettings)settings.SystemSettingsSwitcher;
                actualSettings.ProxyOverride = value;
            }
            else
            {
                handled = base.HandleOption(name, value, settings);
            }

            return(handled);
        }
Esempio n. 3
0
        public SystemSettingsSwitcherForWindows(CommandBase owner, SystemSettingsSwitcherForWindowsSettings settings) : base(owner, settings)
        {
            // argument checks
            // settings can be null

            if (settings == null)
            {
                // simple initialization (ex. to restore)
                Debug.Assert(this.ProxyOverride == null);
            }
            else
            {
                // usual initialization
                this.ProxyOverride = settings.ProxyOverride;
            }

            return;
        }
Esempio n. 4
0
        public SetupContextForWindows(CommandForWindowsSettings settings, SystemSettingsSwitcherForWindows switcher) : base(settings, switcher)
        {
            // argument checks
            Debug.Assert(settings != null);
            SystemSettingsSwitcherForWindowsSettings switcherSettings = settings.SystemSettingsSwitcher;

            Debug.Assert(switcherSettings != null);
            Debug.Assert(switcher != null);

            // ProxyOverride
            this.DefaultProxyOverride = SystemSettingsSwitcherForWindows.GetDefaultProxyOverride();
            if (settings.InitialSetupLevel == 0 || base.NeedActualProxy)
            {
                // User must set ProxyOverride
                this.NeedProxyOverride = true;

                if (string.IsNullOrEmpty(switcherSettings.ProxyOverride))
                {
                    // give default value
                    // DefaultProxyOverride may be set in config file
                    switcherSettings.ProxyOverride = this.DefaultProxyOverride;
                }
            }

            if (settings.InitialSetupLevel == 1)
            {
                // After MAPE supports auto detect and auto config script,
                // ProxyOverride should be reviewed because only overrides which
                // are not handled by auto config should be specified.
                SystemSettingsForWindows current = switcher.GetCurrentSystemSettings();
                if (
                    (current.AutoDetect || string.IsNullOrEmpty(current.AutoConfigURL) == false) &&
                    string.CompareOrdinal(switcherSettings.ProxyOverride, this.DefaultProxyOverride) != 0
                    )
                {
                    this.NeedProxyOverride        = true;
                    this.ShouldResetProxyOverride = true;
                }
            }

            return;
        }
        internal SettingsWindow(CommandForWindowsGUISettings commandSettings, bool enableSaveAsDefault, bool runningProxy)
        {
            // argument checks
            if (commandSettings == null)
            {
                throw new ArgumentNullException(nameof(commandSettings));
            }

            // initialize members
            this.CommandSettings     = commandSettings;
            this.SaveAsDefault       = false;
            this.enableSaveAsDefault = enableSaveAsDefault;
            this.runningProxy        = runningProxy;

            // initialize components
            InitializeComponent();
            // Tuple(control, tab index on which the control resides)
            this.validatableControls = new Tuple <Control, int>[] {
                new Tuple <Control, int>(this.retryTextBox, 0),
                new Tuple <Control, int>(this.resumeTryCountTextBox, 3),
                new Tuple <Control, int>(this.resumeDelayTextBox, 3),
                new Tuple <Control, int>(this.resumeIntervalTextBox, 3)
            };
            this.Icon        = App.Current.OnIcon;
            this.DataContext = this;

            // Proxy Tab
            // Actual Proxy
            SystemSettingsSwitcherForWindowsSettings systemSettingsSwitcherSettings = commandSettings.SystemSettingsSwitcher;

            this.actualProxy.SystemSettingsSwitcherSettings = systemSettingsSwitcherSettings;

            // SystemSettingSwither
            // this.enableSystemSettingSwitherCheckBox.IsChecked is bound to this.EnableSystemSettingSwitch
            this.systemSettingsSwitcher.SystemSettingsSwitcherSettings = systemSettingsSwitcherSettings;

            // Misc
            // this.retryTextBox.Text is bound to this.RetryCount

            // Listener Tab
            ProxySettings  proxySettings = commandSettings.Proxy;
            ItemCollection items         = this.listenerListView.Items;

            items.Add(proxySettings.MainListener);
            if (proxySettings.AdditionalListeners != null)
            {
                foreach (ListenerSettings listenerSetting in proxySettings.AdditionalListeners)
                {
                    items.Add(listenerSetting);
                }
            }

            // Credential Tab
            if (commandSettings.Credentials != null)
            {
                items = this.credentialListView.Items;
                foreach (CredentialSettings credentialSettings in commandSettings.Credentials)
                {
                    items.Add(credentialSettings);
                }
            }

            // Misc Tab
            // this.logLevelComboBox.SelectedItem is bound to this.LogLevel

            // update UI state
            if (runningProxy)
            {
                // modify the title
                this.Title = Properties.Resources.SettingsWindow_Title_ReadOnly;

                // disable input controls
                // Note that buttons are disabled through GetUIState().
                Control[] inputControls = new Control[] {
                    this.actualProxy,
                    this.systemSettingsSwitcher,
                    this.retryTextBox,
                    this.logLevelComboBox,
                    this.resumeTryCountTextBox,
                    this.resumeDelayTextBox,
                    this.resumeIntervalTextBox
                };
                Array.ForEach(inputControls, c => { c.IsEnabled = false; });
            }
            UpdateUIState();

            return;
        }
Esempio n. 6
0
        internal SetupWindow(Command command, SetupContextForWindows setupContext)
        {
            // argument checks
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }
            if (setupContext == null)
            {
                throw new ArgumentNullException(nameof(setupContext));
            }
            CommandForWindowsSettings settings = setupContext.Settings;

            // initialize members
            this.Command      = command;
            this.SetupContext = setupContext;

            // initialize components
            InitializeComponent();

            // Authentication Proxy tab
            SystemSettingsSwitcherForWindowsSettings systemSettingsSwitcherSettings = settings.SystemSettingsSwitcher;

            if (setupContext.NeedActualProxy)
            {
                StringBuilder buf = new StringBuilder(Windows.Properties.Resources.Setup_AuthenticationProxy_Description_NeedToChange);
                if (setupContext.IsDefaultActualProxyProvided)
                {
                    buf.AppendLine();
                    buf.AppendLine();
                    buf.Append(Windows.Properties.Resources.Setup_Description_DefaultValueProvided);
                }
                this.authenticationProxyDescriptionTextBlock.Text = buf.ToString();
                if (systemSettingsSwitcherSettings.ActualProxy == null)
                {
                    systemSettingsSwitcherSettings.ActualProxy = setupContext.CreateActualProxySettings();
                }
            }
            else
            {
                this.authenticationProxyDescriptionTextBlock.Text = Windows.Properties.Resources.Setup_Description_NoNeedToChange;
                if (setupContext.ProxyDetected == false && systemSettingsSwitcherSettings.ActualProxy == null)
                {
                    systemSettingsSwitcherSettings.ActualProxy = setupContext.CreateActualProxySettings();
                }
            }
            this.actualProxy.SystemSettingsSwitcherSettings = systemSettingsSwitcherSettings;

            // System Settings Switch tab
            this.systemSettingsSwitcher.SystemSettingsSwitcherSettings = settings.SystemSettingsSwitcher;
            if (setupContext.NeedProxyOverride)
            {
                this.systemSettingsSwitcherDescriptionTextBlock.Text = Windows.Properties.Resources.Setup_Description_Confirm;
            }
            else
            {
                this.systemSettingsSwitcherDescriptionTextBlock.Text = Windows.Properties.Resources.Setup_Description_NoNeedToChange;
            }

            // Test tab
            this.testDescriptionTextBlock.Text = Windows.Properties.Resources.Setup_Test_Description;
            this.targetUrlTextBox.Text         = SystemSettingsSwitcher.GetTestUrl();

            // Finish tab
            string description = string.Concat(Windows.Properties.Resources.Setup_Finishing_Description, Environment.NewLine, Environment.NewLine, Properties.Resources.SetupWindow_finishingDescriptionTextBox_Text_Addition);

            this.finishingDescriptionTextBlock.Text = description;

            UpdateUIState();

            return;
        }