如何通过 perforce api 获取实时日志,类似于 p4v 日志

how to get real time log via perforce api similar to p4v log

我遇到了 perforce api (.net) 的问题,因为我无法实时提取同步日志。

- 我想做什么

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.

- 现在发生了什么

  • 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

原因是 -

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.

请指教。提前致谢。

-巴拉斯

在 C++ 客户端 API(P4V 的构建基础)中,客户端收到一个 OutputInfo 回调(或 OutputStattagged 模式)对于开始同步的每个文件。

查看 .NET documentation 我认为等效项是 P4CallBacks.InfoResultsDelegateP4CallBacks.TaggedOutputDelegate,它们处理 P4Server.InfoResultsReceived 等事件

我遇到了同样的问题,我费了很大的劲才让它起作用,所以我将分享我找到的解决方案:

首先,您应该使用 P4Server class 而不是 Perforce.P4.Connection。它们是两个 class 做着或多或少相同的事情,但是当我尝试使用 P4.Connection.TaggedOutputReceived 事件时,我什么也没得到。所以我尝试使用 P4Server.TaggedOutputReceived,最后,我得到了我想要的 TaggedOutput。

所以,这是一个小例子:

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);
}

以及处理错误消息或标记输出的方法:

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.
}