Perforce P4API.net:如何使用P4回调委托

Perforce P4API.net:如何使用P4回调委托,perforce,p4api.net,Perforce,P4api.net,我正在开发一个小工具,每天在特定时间安排p4同步。 在这个工具中,我想在P4API运行命令时显示它的输出 我可以看到P4API.net有一个P4Callbacks类,它有几个委托:InfoResultsDelegate、TaggedOutputDelegate、LogMessageDelegate、ErrorDelegate 我的问题是:我如何使用这些,我在网上找不到一个这样的例子。一个简短的示例代码将是惊人的 注意:我是一个初学者,以前从未使用过代理。通过示例回答我自己的问题。我最终发现,这是

我正在开发一个小工具,每天在特定时间安排p4同步。 在这个工具中,我想在P4API运行命令时显示它的输出

我可以看到P4API.net有一个P4Callbacks类,它有几个委托:InfoResultsDelegate、TaggedOutputDelegate、LogMessageDelegate、ErrorDelegate

我的问题是:我如何使用这些,我在网上找不到一个这样的例子。一个简短的示例代码将是惊人的


注意:我是一个初学者,以前从未使用过代理。

通过示例回答我自己的问题。我最终发现,这是一个简单的事件

请注意,这仅适用于P4Server。我上次尝试从P4获取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);
}
这两种方法将在执行sync命令时触发

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"]);
}