예제 #1
0
        public C1Connection(string hostName, int port, AuthenticationInfo authenticationInfo)
        {
            _hostName = hostName;
            _port = port;
            _authenticationInfo = authenticationInfo;

            throw new NotImplementedException();
        }
예제 #2
0
        public C1Connection(string url, AuthenticationInfo authenticationInfo)
        {
            _isHttpConnection = true;
            _url = url;
            _authenticationInfo = authenticationInfo;

            EndpointAddress = new EndpointAddress(GetServiceUrl());

            Binding = new BasicHttpBinding("BasicHttpBinding_ILogService");
        }
예제 #3
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            bool useAdminPassword = rbnAdminUser.Checked;

            AuthenticationInfo authenticationInfo;

            if (useAdminPassword)
            {
                string login = txtLogin.Text.Trim();
                if (string.IsNullOrEmpty(login))
                {
                    MessageBox.Show("Login cannot be empty");
                    return;
                }

                string password = txtPassword.Text;
                if (string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Password cannot be empty");
                    return;
                }

                authenticationInfo = new AuthenticationInfo(login, password);
            }
            else
            {
                Guid authToken;

                string loggerPassword = txtLoggerPassword.Text;

                if (string.IsNullOrEmpty(loggerPassword)
                    || !TryParseGuid(loggerPassword, out authToken))
                {
                    MessageBox.Show(string.IsNullOrEmpty(loggerPassword) ?
                        "Logger password cannot be empty"
                        : "Logger password should be a valid guid");
                    return;
                }

                authenticationInfo = AuthenticationInfo.FromLoggerPassword(loggerPassword);
            }

            //bool useHttp = rbnHttp.Checked;

            C1Connection connection;

            //if(useHttp)
            {
                string url = txtUrl.Text;

                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show("URL is empty");
                    return;
                }

                connection = new C1Connection(url, authenticationInfo);
            }
            //else
            //{

            //    int portNumber;

            //    if(!int.TryParse(txtPort.Text, out portNumber))
            //    {
            //        MessageBox.Show("Port number is invalid.");
            //        return;
            //    }

            //    string host = txtHost.Text;

            //    if (string.IsNullOrEmpty(host))
            //    {
            //        MessageBox.Show("Host is empty");
            //        return;
            //    }

            //    connection = new C1Connection(host, portNumber, authenticationInfo);
            //}

            bool authenticated;
            try
            {
                authenticated = connection.Authenticate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to establish connection. Exception message: " + ex.Message);
                return;
            }

            if (!authenticated)
            {
                MessageBox.Show("Login or password is not correct or the user does not have administrative rights.");
                return;
            }

            DialogResult = DialogResult.OK;
            CurrentConnection = connection;
            Close();

            UpdateRecentUrlList(txtUrl.Text, connection.AuthenticationInfo.AuthToken);
        }
예제 #4
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            bool useAdminPassword = rbnAdminUser.Checked;

            AuthenticationInfo authenticationInfo;

            if (useAdminPassword)
            {
                string login = txtLogin.Text.Trim();
                if (string.IsNullOrEmpty(login))
                {
                    MessageBox.Show("Login cannot be empty");
                    return;
                }

                string password = txtPassword.Text;
                if (string.IsNullOrEmpty(password))
                {
                    MessageBox.Show("Password cannot be empty");
                    return;
                }

                authenticationInfo = new AuthenticationInfo(login, password);
            }
            else
            {
                Guid authToken;

                string loggerPassword = txtLoggerPassword.Text;

                if (string.IsNullOrEmpty(loggerPassword) ||
                    !TryParseGuid(loggerPassword, out authToken))
                {
                    MessageBox.Show(string.IsNullOrEmpty(loggerPassword) ?
                                    "Logger password cannot be empty"
                                                : "Logger password should be a valid guid");
                    return;
                }

                authenticationInfo = AuthenticationInfo.FromLoggerPassword(loggerPassword);
            }


            //bool useHttp = rbnHttp.Checked;

            C1Connection connection;

            //if(useHttp)
            {
                string url = txtUrl.Text;

                if (string.IsNullOrEmpty(url))
                {
                    MessageBox.Show("URL is empty");
                    return;
                }

                connection = new C1Connection(url, authenticationInfo);
            }
            //else
            //{

            //    int portNumber;

            //    if(!int.TryParse(txtPort.Text, out portNumber))
            //    {
            //        MessageBox.Show("Port number is invalid.");
            //        return;
            //    }

            //    string host = txtHost.Text;

            //    if (string.IsNullOrEmpty(host))
            //    {
            //        MessageBox.Show("Host is empty");
            //        return;
            //    }

            //    connection = new C1Connection(host, portNumber, authenticationInfo);
            //}

            bool authenticated;

            try
            {
                authenticated = connection.Authenticate();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to establish connection. Exception message: " + ex.Message);
                return;
            }

            if (!authenticated)
            {
                MessageBox.Show("Login or password is not correct or the user does not have administrative rights.");
                return;
            }

            DialogResult      = DialogResult.OK;
            CurrentConnection = connection;
            Close();

            UpdateRecentUrlList(txtUrl.Text, connection.AuthenticationInfo.AuthToken);
        }