public MainWindow() { InitializeComponent(); m_nodeComboBox.ItemsSource = m_nodes; m_nodeComboBox.SelectionChanged += m_nodeComboBox_SelectionChanged; m_transferView.ItemsSource = m_transfers; m_session = CSAPI.Create().CreateServerSession(HOST, PORT); using (var result = m_session.Authenticate(USERNAME, PASSWORD)) { if (!result.IsSuccess) { m_errors.Text = "Login failed: " + result.ToString(); m_session.Dispose(); m_session = null; return; } } using (var result = m_session.DataAccess.Brokers.Node.Read(m_session.ModelFactory.CreateAllSelector(), null)) { if (result.IsSuccess) { foreach (INode node in result.Value.Items) { NodeModel nm = new NodeModel() { Name = node.Name, Id = node.Id.ToString(), }; m_nodes.Add(nm); } } else { m_errors.Text = result.ToString(); return; } } }
private void m_loginButton_Click(object sender, RoutedEventArgs e) { m_session = m_api.CreateServerSession(m_host, m_port); bool isAuthenticated = false; try { using (var result = m_session.Authenticate(m_username.Text, m_password.Password)) { if (result.IsSuccess) { DialogResult = true; Close(); isAuthenticated = true; } else { if (result.Result == AuthenticateResultType.AuthFailed) { m_error.Text = "Invalid username/password"; } else if (result.Result == AuthenticateResultType.ServerRefused) { m_error.Text = "Server rejected authentication, could be starting up"; } else { m_error.Text = "Failed login: " + result.ToString(); } } } } finally { if (!isAuthenticated) { m_session.Dispose(); m_session = null; } } }
public MainWindow() { InitializeComponent(); m_nodeComboBox.ItemsSource = m_nodes; m_nodeComboBox.SelectionChanged += m_nodeComboBox_SelectionChanged; m_transferView.ItemsSource = m_transfers; m_session = CSAPI.Create().CreateServerSession(HOST, PORT); using (var result = m_session.Authenticate(USERNAME, PASSWORD)) { if (!result.IsSuccess) { m_errors.Text = "Login failed: " + result.ToString(); m_session.Dispose(); m_session = null; return; } } using (var result = m_session.DataAccess.Brokers.Node.Read(m_session.ModelFactory.CreateAllSelector(), null)) { if (result.IsSuccess) { foreach (INode node in result.Value.Items) { NodeModel nm = new NodeModel() { Name = node.Name, Id = node.Id.ToString(), }; m_nodes.Add(nm); } } else { m_errors.Text = result.ToString(); return; } } }
private static bool Authenticate(IServerSession session) { string ncUser = "******"; string ncPassword = "******"; Console.Write("Authenticating... "); using (var result = session.Authenticate(ncUser, ncPassword)) { if (result.IsSuccess) { Console.WriteLine("success"); return(true); } else { Console.WriteLine("failed: " + result.ToString()); return(false); } } }
private static bool Authenticate(IServerSession session) { string ncUser = "******"; string ncPassword = "******"; Console.Write("Authenticating... "); using (var result = session.Authenticate(ncUser, ncPassword)) { if (result.IsSuccess) { Console.WriteLine("success"); return true; } else { Console.WriteLine("failed: " + result.ToString()); return false; } } }
private void m_loginButton_Click(object sender, RoutedEventArgs e) { m_session = m_api.CreateServerSession(m_host, m_port); bool isAuthenticated = false; try { using (var result = m_session.Authenticate(m_username.Text, m_password.Password)) { if (result.IsSuccess) { DialogResult = true; Close(); isAuthenticated = true; } else { if (result.Result == AuthenticateResultType.AuthFailed) { m_error.Text = "Invalid username/password"; } else if (result.Result == AuthenticateResultType.ServerRefused) { m_error.Text = "Server rejected authentication, could be starting up"; } else { m_error.Text = "Failed login: " + result.ToString(); } } } } finally { if (!isAuthenticated) { m_session.Dispose(); m_session = null; } } }