/// <summary> /// loads the proxy server settings from the registry /// </summary> private void LoadSettings() { var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); this.Address = proxyServerConfiguration.Address; this.Port = proxyServerConfiguration.Port; this.UserName = proxyServerConfiguration.UserName; this.Password = proxyServerConfiguration.Password; }
public void Verify_that_when_registry_key_does_not_exist_defaultsettings_are_returned() { var result = ProxyServerConfigurationManager.Read(); Assert.AreEqual("proxy.cdp4.org", result.Address); Assert.AreEqual("8888", result.Port); Assert.IsNull(result.UserName); Assert.IsNull(result.Password); }
public void Verify_that_proxysettings_can_be_written_and_read() { ProxyServerConfigurationManager.Write(this.proxyServerConfiguration); var result = ProxyServerConfigurationManager.Read(); Assert.AreEqual(this.proxyServerConfiguration.Address, result.Address); Assert.AreEqual(this.proxyServerConfiguration.Port, result.Port); Assert.AreEqual(this.proxyServerConfiguration.UserName, result.UserName); Assert.AreEqual(this.proxyServerConfiguration.Password, result.Password); }
/// <summary> /// saves the proxy server settings from the registry /// </summary> private void SaveSettings() { var proxyServerConfiguration = new ProxyServerConfiguration { Address = this.Address, Port = this.Port, UserName = this.UserName, Password = this.Password }; ProxyServerConfigurationManager.Write(proxyServerConfiguration); }
/// <summary> /// Executes the Ok Command /// </summary> /// <param name="openModel">Indicates whether to proceed to opening model</param> /// <returns> /// The <see cref="Task"/>. /// </returns> private async Task ExecuteOk(bool openModel) { // when no trailing slash is provided it can lead to loss of nested paths // see https://stackoverflow.com/questions/22543723/create-new-uri-from-base-uri-and-relative-path-slash-makes-a-difference // for consistency, all uri's are now appended, cannot rely on user getting it right. if (this.SelectedDataSourceKind.DalType == DalType.Web && !this.Uri.EndsWith("/")) { this.Uri += "/"; } var providedUri = new Uri(this.Uri); if (this.IsSessionOpen(this.Uri, this.UserName)) { this.ErrorMessage = $"A session with the username {this.UserName} already exists"; } else { ProxySettings proxySettings = null; if (this.isProxyEnabled) { var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); var proxyUri = new Uri($"http://{proxyServerConfiguration.Address}:{proxyServerConfiguration.Port}"); proxySettings = new ProxySettings(proxyUri, proxyServerConfiguration.UserName, proxyServerConfiguration.Password); } var credentials = new Credentials(this.UserName, this.Password, providedUri, proxySettings); var dal = this.dals.Single(x => x.Metadata.Name == this.selectedDataSourceKind.Name); var dalInstance = (IDal)Activator.CreateInstance(dal.Value.GetType()); this.IsBusy = true; this.session = dalInstance.CreateSession(credentials); try { this.LoadingMessage = "Opening Session..."; await this.session.Open(); this.DialogResult = new DataSourceSelectionResult(true, this.session, openModel); } catch (Exception ex) { this.ErrorMessage = ex.Message; } finally { this.IsBusy = false; } } }
/// <summary> /// updates the proxy server address and port /// </summary> private void UpdateProxyAddressProperty() { if (this.IsProxyEnabled) { var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); this.ProxyUri = proxyServerConfiguration.Address; this.ProxyPort = proxyServerConfiguration.Port; } else { this.ProxyUri = string.Empty; this.ProxyPort = string.Empty; } }
/// <summary> /// Executes the Ok Command /// </summary> /// <returns> /// The <see cref="Task"/>. /// </returns> private async Task ExecuteOk() { var providedUri = new Uri(this.Uri); if (this.IsSessionOpen(this.Uri, this.UserName)) { this.ErrorMessage = $"A session with the username {this.UserName} already exists"; } else { ProxySettings proxySettings = null; if (this.isProxyEnabled) { var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); var proxyUri = new Uri($"http://{proxyServerConfiguration.Address}:{proxyServerConfiguration.Port}"); proxySettings = new ProxySettings(proxyUri, proxyServerConfiguration.UserName, proxyServerConfiguration.Password); } var credentials = new Credentials(this.UserName, this.Password, providedUri, proxySettings); var dal = this.dals.Single(x => x.Metadata.Name == this.selectedDataSourceKind.Name); var dalInstance = (IDal)Activator.CreateInstance(dal.Value.GetType()); this.IsBusy = true; this.session = new Session(dalInstance, credentials); try { this.LoadingMessage = "Opening Session..."; await this.session.Open(); this.DialogResult = new DataSourceSelectionResult(true, this.session); } catch (Exception ex) { this.ErrorMessage = ex.Message; } finally { this.IsBusy = false; } } }
public void Verify_that_when_ok_executed_registry_is_written_and_result_is_true() { var vm = new ProxyServerViewModel(); vm.Address = "192.168.0.100"; vm.Port = "1234"; vm.UserName = "******"; vm.Password = "******"; vm.OkCommand.Execute(null); Assert.AreEqual(true, vm.DialogResult.Result.Value); var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); Assert.AreEqual("192.168.0.100", proxyServerConfiguration.Address); Assert.AreEqual("1234", proxyServerConfiguration.Port); Assert.AreEqual("John", proxyServerConfiguration.UserName); Assert.AreEqual("Doe", proxyServerConfiguration.Password); }
public void Verify_that_when_cancel_executed_registry_is_not_written_and_result_is_false() { var vm = new ProxyServerViewModel(); vm.Address = "test.cdp4.org"; vm.Port = "1234"; vm.UserName = "******"; vm.Password = "******"; vm.CancelCommand.Execute(null); Assert.AreEqual(false, vm.DialogResult.Result.Value); var proxyServerConfiguration = ProxyServerConfigurationManager.Read(); Assert.AreNotEqual("test.cdp4.org", proxyServerConfiguration.Address); Assert.AreNotEqual("1234", proxyServerConfiguration.Port); Assert.AreNotEqual("John", proxyServerConfiguration.UserName); Assert.AreNotEqual("Doe", proxyServerConfiguration.Password); }