我面临perforce api(.net)的问题,因为我无法实时提取同步日志。
-我想做什么
我正在尝试提取实时日志,因为使用
Perforce.P4.Client.SyncFiles()
命令。与P4V GUI日志类似,当我们尝试同步任何文件时会更新。
-现在发生了什么
由于仅在执行完命令后才生成输出,因此它不是想要的。
也尝试查看
Perforce.P4.P4Server.RunCommand()
,该报告确实提供了详细的报告,但仅在命令执行之后。调查this
原因是-
我正在尝试向我正在使用的工具添加状态更新,以显示当前正在同步哪个Perforce文件。
请告知。在此先感谢。
-巴拉斯
在C ++客户端API(P4V的构建基础)中,客户端开始同步时,每个文件都会收到OutputInfo
回调(或OutputStat
ged模式下的tag
。
查看.NET documentation,我认为等效的是P4CallBacks.InfoResultsDelegate
和P4CallBacks.TaggedOutputDelegate
,它们处理诸如P4Server.InfoResultsReceived
等事件。
我最终遇到了同样的问题,为了使它正常工作我付出了很多努力,所以我将分享我找到的解决方案:
首先,应使用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);
}
以及处理错误消息或tagdOutput的方法:
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.
}