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