1

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

- 我想做什么

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

- 现在发生了什么

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

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

原因是——

我正在尝试向我正在使用的工具添加状态更新,该工具显示当前正在同步哪个 Perforce 文件。

请指教。提前致谢。

-巴拉特

4

2 回答 2

2

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

查看.NET 文档,我认为等价物是P4CallBacks.InfoResultsDelegateP4CallBacks.TaggedOutputDelegate处理诸如此类的事件P4Server.InfoResultsReceived

于 2018-01-25T00:33:05.737 回答
1

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

首先,您应该使用 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.
}
于 2020-04-10T17:51:59.217 回答