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
{
string uri;
string user;
string client;
public MainForm()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void ExitButton_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void ConnectButton_Click(object sender, EventArgs e)
{
// Connection details.
uri = "public.perforce.com:1666";
user = "Paul_Arva";
client = "Paul_Arva_SampleApp";
// Define server, repository and connection.
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;
// Define username and client name.
con.UserName = user;
con.Client = new Client();
con.Client.Name = client;
try
{
// Connect to server.
con.Connect(null);
// Successful connection.
StatusLabel.Text = "Connected";
StatusLabel.ForeColor = Color.Green;
}
catch (P4CommandTimeOutException ex)
{
MessageBox.Show(ex.Message, "Command Timeout");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error");
}
finally
{
if (con.Status == ConnectionStatus.Connected) con.Disconnect();
}
}
}
}