/// <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;
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 5
0
        /// <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;
                }
            }
        }
Ejemplo n.º 6
0
        /// <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;
            }
        }
Ejemplo n.º 7
0
        /// <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;
                }
            }
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }