/*
* Copyright (c) 2009 Craig Sutherland
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
using System.Windows.Forms;
using FastForward.WinCore;
using ThoughtWorks.CruiseControl.Remote.Monitor;
using ThoughtWorks.CruiseControl.Remote;
using System.Collections.Generic;
using ThoughtWorks.CruiseControl.Remote.Messages;
using System;
namespace FastForward.Monitor
{
///
/// Allows the user to login to a server.
///
public partial class LoginForm
: Form
{
#region Constructors
///
/// Initialise a new .
///
public LoginForm(ServerList servers)
{
InitializeComponent();
// Add all the servers
foreach (var serverItem in servers.Servers)
{
server.Items.Add(new ServerDisplay { Server = serverItem });
}
server.SelectedIndex = 0;
}
#endregion
#region Event handlers
#region okButton_Click()
///
/// The OK button has been clicked.
///
///
///
private void okButton_Click(object sender, System.EventArgs e)
{
var selectedServer = (server.SelectedItem as ServerDisplay).Server;
statusLabel.Text = "Attempting to login to the server...";
Application.DoEvents();
// Attempt to login
try
{
if (selectedServer.Login(userName.Text, password.Text))
{
// Refresh the display
selectedServer.Refresh();
DialogResult = DialogResult.OK;
Close();
}
else
{
// Tell the user the login failed
statusLabel.Text = "Login failed on the remote server.";
}
}
catch (Exception error)
{
statusLabel.Text = "An error occurred while logging in: " + error.Message;
}
}
#endregion
#endregion
#region Private classes
#region ServerDisplay
private class ServerDisplay
{
#region Public properties
#region Server
///
/// The associated server.
///
public Server Server { get; set; }
#endregion
#endregion
#region Public methods
#region ToString()
///
/// Returns the name of the server.
///
///
public override string ToString()
{
return this.Server.GetDisplayName();
}
#endregion
#endregion
}
#endregion
#endregion
}
}