如何通过类似于P4V日志的Perforce API获取实时日志



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

- 我想做什么

我正在尝试提取实时日志,因为使用
Perforce.P4.Client.SyncFiles()命令。类似于P4V GUI日志,当我们尝试同步任何文件时会更新。

- 现在发生了什么

  • 由于输出仅在命令完成执行后生成,因此它不是预期目的。

  • 还尝试查看Perforce.P4.P4Server.RunCommand()确实提供详细报告,但仅在命令执行后。 调查了这个

理由是 ——

我正在

尝试向我正在处理的工具添加状态更新,以显示当前正在同步的Perforce文件。

请指教。提前谢谢。

-巴拉特

在C++客户端 API(这是构建 P4V 的基础(中,客户端在开始同步时会收到每个文件的OutputInfo回调(或tag ged 模式下的OutputStat(。

查看 .NET 文档,我认为等效项是处理P4Server.InfoResultsReceived等事件的P4CallBacks.InfoResultsDelegateP4CallBacks.TaggedOutputDelegate

我最终遇到了同样的问题,我很难让它工作,所以我将分享我找到的解决方案:

首先,您应该使用 P4Server 类而不是 Perforce.P4.Connection。它们是两个类或多或少做同样的事情,但是当我尝试使用 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.
}

最新更新