Example connecting to P4 Authentication Service
You can use P4 API for .NET to log in to a P4 Server which is also connected to a P4 Authentication Service.
Create a new C# Console Application project and paste the following code into Program.cs:
Copy
using System;
using System.Collections.Generic;
using System.Text;
using Perforce.P4;
namespace Sandbox
{
class Program
{
static void Main(string[] args)
{
var P4USER = "your_perforce_username";
var P4PORT = "perforce.company.com:1666";
var P4CLIENT = "your_local_workspace_name";
var P4PASSWD = "";
//When logging into a P4 Server connected
//to P4 Authentication Service, set
//P4PASSWD to a blank string
Console.WriteLine("Sandbox testing");
Perforce.P4.Server srv = new Perforce.P4.Server(new ServerAddress(P4PORT));
Perforce.P4.Repository p4 = new Perforce.P4.Repository(srv);
p4.Connection.UserName = P4USER;
p4.Connection.SetClient(P4CLIENT);
p4.Connection.Connect(new Perforce.P4.Options());
p4.Connection.Login(P4PASSWD,new Perforce.P4.Options());
// Get info and print it.
P4Command cmd = new P4Command(p4, "info", true, null);
P4CommandResult rslt = cmd.Run();
foreach (var item in rslt.TaggedOutput)
{
foreach (string key in item.Keys)
{
Console.WriteLine("{0}: {1}", key, item[key]);
}
}
p4.Connection.Disconnect();
Console.ReadKey();
}
}
}