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; using System.Diagnostics; using System.IO; namespace SampleApp { public partial class MainForm : Form { string uri; string user; string clientName; string password; string clientMapFile = "ClientMap.txt"; 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) { ConnectToServer(); } public void ConnectToServer() { // Connection details. uri = "public.perforce.com:1666"; uri = @"rsh:c:\test\p4d.exe -r C:\test -L log -i"; user = "Paul_Arva"; clientName = "Paul_Arva_SampleApp"; password = "Perpass1"; // 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 = clientName; try { // Connect to server. con.Connect(null); // Successful connection. StatusLabel.Text = "Connected"; StatusLabel.ForeColor = Color.Green; // Login to server. Credential cred = con.Login(password, null, null); LoginLabel.Text = "Logged in"; LoginLabel.ForeColor = Color.Green; // Get client spec. Client client = rep.GetClient(clientName); // Show client mapping file. if (!System.IO.File.Exists(clientMapFile)) { System.IO.File.Create(clientMapFile); } TextWriter tw = new StreamWriter(clientMapFile); tw.WriteLine(client.ViewMap.ToString()); tw.Close(); Process clientMapProcess = Process.Start(clientMapFile); } 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(); } } } }