/// <summary> /// Sets the default proxy for every HTTP request. /// If the caller would like to know if the call throws any exception, the second parameter should be set to true /// </summary> /// <param name="settings">proxy settings.</param> /// <param name="throwExceptions">If set to <c>true</c> throw exceptions.</param> public static void SetDefaultProxy(Config.ProxySettings settings, bool throwExceptions = false) { try { IWebProxy proxy = null; switch (settings.Selection) { case Config.ProxySelection.SYSTEM: proxy = WebRequest.GetSystemWebProxy(); break; case Config.ProxySelection.CUSTOM: proxy = new WebProxy(settings.Server); break; } if (settings.LoginRequired && proxy != null) { proxy.Credentials = new NetworkCredential(settings.Username, Crypto.Deobfuscate(settings.ObfuscatedPassword)); } WebRequest.DefaultWebProxy = proxy; } catch (Exception e) { if (throwExceptions) { throw; } Logger.Warn("Failed to set the default proxy, please check your proxy config: ", e); } }
partial void OnSave(NSObject sender) { CmisSync.Lib.Config.ProxySettings settings = this.ProxySettings; if (NoProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.NOPROXY; } else if (SystemDefaultProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.SYSTEM; } else if (ManualProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.CUSTOM; } string server = Controller.GetServer(this.ProxyServer.StringValue); if (server != null) { settings.Server = new Uri(server); } settings.LoginRequired = (this.RequiresAuthorizationCheckBox.State == NSCellStateValue.On); settings.Username = this.ProxyUsername.StringValue; settings.ObfuscatedPassword = Crypto.Obfuscate(this.ProxyPassword.StringValue); this.ProxySettings = settings; ConfigManager.CurrentConfig.Proxy = settings; ConfigManager.CurrentConfig.Notifications = (NotificationsFeaturesButton.State == NSCellStateValue.On) ? true : false; ConfigManager.CurrentConfig.Save(); PerformClose(this); }
public void GetRepositoriesTroughProxy( string cmisServerUrl, string cmisUser, string cmisPassword, string proxyUrl, string proxyUser, string proxyPassword) { if (string.IsNullOrEmpty(proxyUrl)) { Assert.Ignore(); } ServerCredentials credentials = new ServerCredentials { Address = new Uri(cmisServerUrl), UserName = cmisUser, Password = cmisPassword }; ProxySettings proxySettings = new ProxySettings(); proxySettings.Selection = string.IsNullOrEmpty(cmisServerUrl) ? ProxySelection.NOPROXY : ProxySelection.CUSTOM; proxySettings.Server = new Uri(proxyUrl); proxySettings.LoginRequired = !string.IsNullOrEmpty(proxyUser); if (proxySettings.LoginRequired) { proxySettings.Username = proxyUser; proxySettings.ObfuscatedPassword = Crypto.Obfuscate(proxyPassword); } HttpProxyUtils.SetDefaultProxy(proxySettings, true); Assert.That(credentials.GetRepositories(), Is.Not.Empty); }
public void ResetToDefaultProxySettings() { ProxySettings settings = new ProxySettings(); settings.Selection = ProxySelection.SYSTEM; settings.LoginRequired = false; HttpProxyUtils.SetDefaultProxy(settings, true); }
public override void AwakeFromNib() { base.AwakeFromNib(); this.Title = Properties_Resources.EditTitle; this.ProxySettings = ConfigManager.CurrentConfig.Proxy; this.CancelButton.Title = Properties_Resources.DiscardChanges; this.SaveButton.Title = Properties_Resources.SaveChanges; this.RequiresAuthorizationCheckBox.StringValue = Properties_Resources.NetworkProxyLogin; this.ProxyPasswordLabel.StringValue = Properties_Resources.Password; this.ProxyUsernameLabel.StringValue = Properties_Resources.User; this.NotificationsFeaturesButton.Title = Properties_Resources.Notifications; Controller = (this.WindowController as GeneralSettingsController).Controller; this.ProxyServer.Delegate = new TextFieldDelegate(); (this.ProxyServer.Delegate as TextFieldDelegate).StringValueChanged += delegate { Controller.ValidateServer(this.ProxyServer.StringValue); }; Controller.CheckProxyNoneEvent += (check) => { if (check != (NoProxyButton.State == NSCellStateValue.On)) { NoProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } }; Controller.CheckProxySystemEvent += (check) => { if (check != (SystemDefaultProxyButton.State == NSCellStateValue.On)) { SystemDefaultProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } }; Controller.CheckProxyCutomEvent += (check) => { if (check != (ManualProxyButton.State == NSCellStateValue.On)) { ManualProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } ProxyServerLabel.Enabled = check; ProxyServer.Enabled = check; ProxyServerHelp.Enabled = check; CheckAddress(Controller); }; Controller.EnableLoginEvent += (enable) => { RequiresAuthorizationCheckBox.Enabled = enable; if (enable) { Controller.CheckLogin(RequiresAuthorizationCheckBox.State == NSCellStateValue.On); } else { ProxyUsernameLabel.Enabled = false; ProxyUsername.Enabled = false; ProxyPasswordLabel.Enabled = false; ProxyPassword.Enabled = false; } }; Controller.CheckLoginEvent += (check) => { if (check != (RequiresAuthorizationCheckBox.State == NSCellStateValue.On)) { RequiresAuthorizationCheckBox.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } ProxyUsernameLabel.Enabled = check; ProxyUsername.Enabled = check; ProxyPasswordLabel.Enabled = check; ProxyPassword.Enabled = check; }; Controller.UpdateServerHelpEvent += (message) => { ProxyServerHelp.StringValue = message; }; Controller.UpdateSaveEvent += (enable) => { SaveButton.Enabled = enable; }; RefreshStates(); }
public void SetUp() { this.settings = new ProxySettings(); }
public override void AwakeFromNib () { base.AwakeFromNib (); this.Title = Properties_Resources.EditTitle; this.ProxySettings = ConfigManager.CurrentConfig.Proxy; this.CancelButton.Title = Properties_Resources.DiscardChanges; this.SaveButton.Title = Properties_Resources.SaveChanges; this.RequiresAuthorizationCheckBox.StringValue = Properties_Resources.NetworkProxyLogin; this.ProxyPasswordLabel.StringValue = Properties_Resources.Password; this.ProxyUsernameLabel.StringValue = Properties_Resources.User; this.NotificationsFeaturesButton.Title = Properties_Resources.Notifications; Controller = (this.WindowController as GeneralSettingsController).Controller; this.ProxyServer.Delegate = new TextFieldDelegate (); (this.ProxyServer.Delegate as TextFieldDelegate).StringValueChanged += delegate { Controller.ValidateServer(this.ProxyServer.StringValue); }; Controller.CheckProxyNoneEvent += (check) => { if(check != (NoProxyButton.State == NSCellStateValue.On)) { NoProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } }; Controller.CheckProxySystemEvent += (check) => { if(check != (SystemDefaultProxyButton.State == NSCellStateValue.On)) { SystemDefaultProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } }; Controller.CheckProxyCutomEvent += (check) => { if(check != (ManualProxyButton.State == NSCellStateValue.On)) { ManualProxyButton.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } ProxyServerLabel.Enabled = check; ProxyServer.Enabled = check; ProxyServerHelp.Enabled = check; CheckAddress(Controller); }; Controller.EnableLoginEvent += (enable) => { RequiresAuthorizationCheckBox.Enabled = enable; if (enable) { Controller.CheckLogin(RequiresAuthorizationCheckBox.State == NSCellStateValue.On); } else { ProxyUsernameLabel.Enabled = false; ProxyUsername.Enabled = false; ProxyPasswordLabel.Enabled = false; ProxyPassword.Enabled = false; } }; Controller.CheckLoginEvent += (check) => { if (check != (RequiresAuthorizationCheckBox.State == NSCellStateValue.On)) { RequiresAuthorizationCheckBox.State = check ? NSCellStateValue.On : NSCellStateValue.Off; } ProxyUsernameLabel.Enabled = check; ProxyUsername.Enabled = check; ProxyPasswordLabel.Enabled = check; ProxyPassword.Enabled = check; }; Controller.UpdateServerHelpEvent += (message) => { ProxyServerHelp.StringValue = message; }; Controller.UpdateSaveEvent += (enable) => { SaveButton.Enabled = enable; }; RefreshStates(); }
partial void OnSave(NSObject sender) { CmisSync.Lib.Config.ProxySettings settings = this.ProxySettings; if (NoProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.NOPROXY; } else if(SystemDefaultProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.SYSTEM; } else if(ManualProxyButton.State == NSCellStateValue.On) { settings.Selection = ProxySelection.CUSTOM; } string server = Controller.GetServer(this.ProxyServer.StringValue); if (server!=null) { settings.Server = new Uri(server); } settings.LoginRequired = (this.RequiresAuthorizationCheckBox.State == NSCellStateValue.On); settings.Username = this.ProxyUsername.StringValue; settings.ObfuscatedPassword = Crypto.Obfuscate(this.ProxyPassword.StringValue); this.ProxySettings = settings; ConfigManager.CurrentConfig.Proxy = settings; ConfigManager.CurrentConfig.Notifications = (NotificationsFeaturesButton.State == NSCellStateValue.On) ? true : false; ConfigManager.CurrentConfig.Save(); PerformClose(this); }