[英]P4API.net: how to use P4Callbacks delegates
我正在開發一個小工具,可以在特定時間每天安排 p4 同步。 在這個工具中,我想在運行命令時顯示來自 P4API 的輸出。
我可以看到 P4API.net 有一個 P4Callbacks 類,有幾個委托:InfoResultsDelegate、TaggedOutputDelegate、LogMessageDelegate、ErrorDelegate。
我的問題是:我如何使用這些,我在網上找不到一個例子。 一個簡短的示例代碼會很棒!
注意:我是一個初學者,以前從未使用過委托。
通過一個例子回答我自己的問題。 我最終自己弄清楚了,這是一個簡單的事件。
請注意,這僅適用於 P4Server。 我最后一次嘗試從 P4.Connection 獲取 TaggedOutput 失敗了,它們在運行命令時從未被觸發。
所以,這是一個代碼示例:
P4Server p4Server = new P4Server(syncPath);
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 completely 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"]);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.