1

I am facing issue with perforce api (.net), as i am unable to pull sync logs in real time.

- What am I trying to do

I am trying to pull real time logs as Sync is triggered using the
Perforce.P4.Client.SyncFiles() command. Similar to the P4V GUI Logs, which update when we try to sync any files.

- What is happening now

  • As the output is generated only after the command is done execution its not something intended for.

  • Also tried looking into Perforce.P4.P4Server.RunCommand() which does provide detailed report but only after the execution of the command. Looked into this

Reason is -

I am trying to add a status update to the Tool i am working on which shows which Perforce file is currently being sync'd.

Please advise. Thanks in Advance.

-Bharath

  • 1
    This comment sounds very useful: "... the repository.Connection contains also other interesting delegates to hook: .CommandEcho, .Errorreceived, .InfoResultReceived," Did you try those? I'd expect `InfoResultReceived` to be what you're looking for. – Samwise Jan 24 '18 at 23:35

2 Answers2

2

In the C++ client API (which is what P4V is built on), the client receives an OutputInfo callback (or OutputStat in tagged mode) for each file as it begins syncing.

Looking over the .NET documentation I think the equivalents are the P4CallBacks.InfoResultsDelegate and P4CallBacks.TaggedOutputDelegate which handle events like P4Server.InfoResultsReceived etc.

Samwise
  • 68,105
  • 3
  • 30
  • 44
  • Thanks @sam. InfoResultsReceived gives information like, user logged in and client workspace created(saved) but doesnt provide when files are being sync'd. – Bharath Metpally Jan 31 '18 at 13:11
  • Quick Update, TaggedOutput delegate gives raw information, which we can format and get the intended output. downside is, it also prints out lot of other p4 actions. – Bharath Metpally Jan 31 '18 at 13:53
  • Sadly, the new API 2018.x has broken the TaggedOutput, It doesnt error, but it also doesnt output . Please suggest. – Bharath Metpally Feb 06 '19 at 07:15
1

I ended up with the same issue, and I struggled quite a bit to get it to work, so I will share the solution I found:

First, you should use the P4Server class instead of the Perforce.P4.Connection. They are two classes doing more or less the same thing, but when I tried using the P4.Connection.TaggedOutputReceived events, I simply got nothing back. So instead I tried with the P4Server.TaggedOutputReceived, and there, finally, I got the TaggedOutput just like I wanted.

So, here is a small example:

P4Server p4Server = new P4Server(cwdPath); //In my case I use P4Config, so no need to set user or to login, but you can do all that with the p4Server here.
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 failed
{
    Console.WriteLine("P4Command failed: " + ex.Message);
}

And the method to handle the error messages or the taggedOutput:

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"]); //Write the synced file name.
    //Note that I used this only for a 'Sync' command, for other commands, I guess there might not be any Obj["clientFile"], so you should check for that.
}
JulienH
  • 61
  • 3