首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >P4API.net:如何使用P4Callbacks委托

P4API.net:如何使用P4Callbacks委托
EN

Stack Overflow用户
提问于 2020-03-13 17:07:35
回答 1查看 74关注 0票数 0

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

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

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

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

EN

回答 1

Stack Overflow用户

发布于 2020-04-11 01:31:28

通过一个例子回答我自己的问题。我最终自己弄明白了,这是一件简单的事情。

请注意,这只适用于P4Server。我最后一次尝试从P4Connection获取TaggedOutput是不成功的,它们在运行命令时从未被触发。

因此,下面是一个代码示例:

代码语言:javascript
复制
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命令时触发。

代码语言:javascript
复制
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"]);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60667597

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档