[英]how to get real time log via perforce api similar to p4v log
我正面臨 perforce api (.net) 的問題,因為我無法實時提取同步日志。
- 我想做什么
我正在嘗試拉實時日志,因為同步是使用
Perforce.P4.Client.SyncFiles()
命令。 類似於 P4V GUI 日志,當我們嘗試同步任何文件時會更新。
- 現在發生了什么
由於僅在命令執行完成后才生成輸出,因此它不是預期的。
還嘗試查看
Perforce.P4.P4Server.RunCommand()
,它確實提供了詳細的報告,但僅在執行命令之后。 看了這個
原因是——
我正在嘗試向我正在使用的工具添加狀態更新,以顯示當前正在同步哪個 Perforce 文件。
請指教。 提前致謝。
-巴拉特
在C ++客戶端API(這是P4V是建立在),客戶端接收一OutputInfo
回調(或OutputStat
在tag
GED模式)對於每個文件,因為它開始同步。
查看.NET 文檔,我認為等效項是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);
}
以及處理錯誤消息或標記輸出的方法:
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.
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.