private FtpUrlInfo _validatePathSub()
        {
            FtpUrlInfo url = new FtpUrlInfo(ProjectConfiguration.DatabasePath);

            url.Host = _tbHostname.Text;

            if (String.IsNullOrEmpty(url.Host))
            {
                throw new Exception("Unrocognized url host name.");
            }

            var res = Uri.CheckHostName(url.Host);

            if (res == UriHostNameType.Unknown)
            {
                throw new Exception("Unrocognized url host name.");
            }

            int ival;

            Int32.TryParse(_tbPort.Text, out ival);
            url.Port = ival;

            if (ival <= 0)
            {
                throw new Exception("Unrocognized port number (must be above 0).");
            }

            ConnectionType status = (ConnectionType)Enum.Parse(typeof(ConnectionType), _cbProtocol.SelectedValue.ToString());

            if (status == ConnectionType.Ftp)
            {
                url.Scheme = "ftp";
            }
            else if (status == ConnectionType.Sftp)
            {
                url.Scheme = "sftp";
            }
            else
            {
                throw new Exception("Unrocognized url scheme (sftp, ftp, ...).");
            }

            url.Path = _tbPath.Text;

            if (url.Path.Contains(":"))
            {
                throw new Exception("Unrocognized symbol in the server's path.");
            }

            return(url);
        }
        public FtpLogin()
            : base("Ftp Server Login", "sftp.png", SizeToContent.Height, ResizeMode.NoResize)
        {
            InitializeComponent();

            if (ProjectConfiguration.FtpUsername == "")
            {
                ProjectConfiguration.FtpUsername = "******";
            }

            Binder.Bind(_tbUsername, () => ProjectConfiguration.FtpUsername);
            Binder.Bind(_tbPassword, () => ProjectConfiguration.FtpPassword);

            _cbProtocol.ItemsSource = Enum.GetValues(typeof(ConnectionType));

            FtpUrlInfo url;

            _cbProtocol.SelectedIndex = 0;

            try {
                url              = new FtpUrlInfo(ProjectConfiguration.DatabasePath);
                _tbPort.Text     = url.Port > -1 ? url.Port.ToString(CultureInfo.InvariantCulture) : "22";
                _tbHostname.Text = String.IsNullOrEmpty(url.Host) ? "127.0.0.1" : url.Host;

                if (url.Scheme == "sftp")
                {
                    _cbProtocol.SelectedIndex = 0;
                }
                else if (url.Scheme == "ftp")
                {
                    _cbProtocol.SelectedIndex = 1;
                }

                _tbPath.Text = url.Path;

                if (url.Path.Contains(":"))
                {
                    _tbPath.Text = DefaultPath;
                }
            }
            catch {
                _tbPort.Text              = "22";
                _tbHostname.Text          = "127.0.0.1";
                _cbProtocol.SelectedIndex = 0;
                _tbPath.Text              = DefaultPath;
            }

            PreviewKeyDown += new KeyEventHandler(_dropEdit_PreviewKeyDown);

            _tbUsername.Loaded += delegate {
                _tbUsername.SelectAll();
                _tbUsername.Focus();
            };

            _tbHostname.GotFocus += _tb_GotFocus;
            _tbPassword.GotFocus += _tb_GotFocus;
            _tbPath.GotFocus     += _tb_GotFocus;
            _tbPort.GotFocus     += _tb_GotFocus;
            _tbUsername.GotFocus += _tb_GotFocus;

            _cbProtocol.SelectionChanged += new SelectionChangedEventHandler(_cbProtocol_SelectionChanged);
        }