using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Perforce.P4;
namespace SampleApp
{
public partial class MainForm : Form
{
// Server details.
Server server;
Repository rep;
Connection con;
Credential cred;
// Connection details.
string uri;
string userName;
string clientName;
string password;
// State constants.
const string LOGGEDIN = "Logged In";
const string LOGGEDOUT = "Logged Out";
const string CONNECTED = "Connected";
const string DISCONNECTED = "Disconnected";
public MainForm()
{
InitializeComponent();
}
private void MainForm_Load(object sender, EventArgs e)
{
SetLoggedOut();
}
private void ExitButton_Click(object sender, EventArgs e)
{
// Release connection.
if (con.Status == ConnectionStatus.Connected) con.Disconnect();
Application.Exit();
}
private void ConnectButton_Click(object sender, EventArgs e)
{
try
{
SetLoggedOut();
ResultTextBox.Clear();
uri = ServerTextBox.Text.Trim();
Utilities utils = new Utilities();
con = utils.ConnectToServer(uri, out server, out rep);
ConnectionLabel.Text = CONNECTED;
ConnectionLabel.ForeColor = Color.Green;
userName = UserTextBox.Text.Trim();
clientName = ClientTextBox.Text.Trim();
password = PasswordTextBox.Text.Trim();
utils.LoginToServer(con, userName, clientName, password, out cred);
LoginLabel.Text = LOGGEDIN;
LoginLabel.ForeColor = Color.Green;
SetLoggedIn();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Application Error");
Disconnect();
}
}
private void SetLoggedIn()
{
GetButton.Enabled = true;
SubmitButton.Enabled = true;
ConnectionLabel.Text = CONNECTED;
ConnectionLabel.ForeColor = Color.Green;
LoginLabel.Text = LOGGEDIN;
LoginLabel.ForeColor = Color.Green;
Application.DoEvents();
}
private void SetLoggedOut()
{
GetButton.Enabled = false;
SubmitButton.Enabled = false;
ResultTextBox.Clear();
ConnectionLabel.Text = DISCONNECTED;
ConnectionLabel.ForeColor = Color.Red;
LoginLabel.Text = LOGGEDOUT;
LoginLabel.ForeColor = Color.Red;
Application.DoEvents();
}
private void SubmitButton_Click(object sender, EventArgs e)
{
try
{
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Application Error");
Disconnect();
}
}
private void GetButton_Click(object sender, EventArgs e)
{
try
{
Utilities utils = new Utilities();
Client client = utils.GetClientMap(clientName, rep);
// Display spec.
ResultTextBox.Clear();
ResultTextBox.Text = client.ViewMap.ToString();
SubmitButton.Enabled = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Application Error");
Disconnect();
}
}
private void Disconnect()
{
if (con.Status == ConnectionStatus.Connected) con.Disconnect();
SetLoggedOut();
}
}
}