1

I am working on a small tool to schedule p4 sync daily at specific times. In this tool, I want to display the outputs from the P4API while it is running commands.

I can see that the P4API.net has a P4Callbacks class, with several delegates: InfoResultsDelegate, TaggedOutputDelegate, LogMessageDelegate, ErrorDelegate.

My question is: How can I use those, I could not find a single example online of that. A short example code would be amazing !

Note: I am quite a beginner and have never used delegates before.

JulienH
  • 61
  • 3

1 Answers1

0

Answering my own questions by an example. I ended up figuring out by myself, it is a simple event.

Note that this only works with P4Server. My last attempt at getting TaggedOutput from a P4.Connection was unsuccessful, they were never triggered when running a command.

So, here is a code example:

P4Server p4Server = new P4Server(syncPath);
p4Server.TaggedOutputReceived += P4ServerTaggedOutputEvent;
p4Server.ErrorReceived += P4ServerErrorReceived;    
bool syncSuccess = false;
try
{
    P4Command syncCommand = new P4Command(p4Server, "sync", true, syncPath + "\\...");
    P4CommandResult rslt = syncCommand.Run();
    syncSuccess=true;
    //Here you can read the content of the P4CommandResult
    //But it will only be accessible when the command is finished.
}
catch (P4Exception ex) //Will be caught only when the command has completely failed
{
    Console.WriteLine("P4Command failed: " + ex.Message);
}

And the two methods, those will be triggered while the sync command is being executed.

private void P4ServerErrorReceived(uint cmdId, int severity, int errorNumber, string data)
{
    Console.WriteLine("P4ServerErrorReceived:" + data);
}

private void P4ServerTaggedOutputEvent(uint cmdId, int ObjId, TaggedObject Obj)
{
    Console.WriteLine("P4ServerTaggedOutputEvent:" + Obj["clientFile"]);
}
JulienH
  • 61
  • 3