.net 如何显示Perforce API执行的文件操作的输出?

.net 如何显示Perforce API执行的文件操作的输出?,.net,perforce,p4api.net,.net,Perforce,P4api.net,我将通过perforce API同步perforce文件我希望每个文件操作都有输出。类似于我们所看到的p4 cmd的输出: //depot/file.txt#1-更新X:\file.txt //depot/file.txt#2-删除为X:\file.txt 以下是用于同步文件的perforce api代码: var repository = new P4.Repository(new P4.Server(new P4.ServerAddress("server:111111"))); rep

我将通过perforce API同步perforce文件我希望每个文件操作都有输出。类似于我们所看到的p4 cmd的输出:

  • //depot/file.txt#1-更新X:\file.txt
  • //depot/file.txt#2-删除为X:\file.txt
以下是用于同步文件的perforce api代码:

var repository = new P4.Repository(new P4.Server(new P4.ServerAddress("server:111111")));
repository.Connection.UserName = "me";
repository.Connection.Connect(new P4.Options());
repository.Connection.Login("password");
repository.Connection.Client = repository.GetClient("client");
var syncFlags = new P4.Options(P4.SyncFilesCmdFlags.Force, 100);
var clientPath = new P4.ClientPath(@"X:\File.txt");

IList<P4.FileSpec> results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(1)) });
P4.VersionSpec downloadedVersion = results.First().Version; // This is #1 as expected

results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(2)) });
downloadedVersion = results.First().Version; // This is #2 as expected

results = repository.Connection.Client.SyncFiles(syncFlags, new[] { new P4.FileSpec(clientPath, new P4.Revision(0)) });
downloadedVersion = results.First().Version; // File is really deleted and I hoped for #0, but it's #2!
var repository=new P4.repository(new P4.Server(new P4.ServerAddress(“Server:111111”));
repository.Connection.UserName=“me”;
repository.Connection.Connect(新的P4.Options());
repository.Connection.Login(“密码”);
repository.Connection.Client=repository.GetClient(“客户端”);
var syncFlags=new P4.Options(P4.SyncFilesCmdFlags.Force,100);
var clientPath=new P4.clientPath(@“X:\File.txt”);
IList results=repository.Connection.Client.SyncFiles(syncFlags,new[]{new P4.FileSpec(clientPath,new P4.Revision(1))});
P4.VersionSpec downloadedVersion=results.First().Version;//这是意料之中的1
结果=repository.Connection.Client.SyncFiles(syncFlags,new[]{new P4.FileSpec(clientPath,new P4.Revision(2))});
downloadedVersion=results.First().Version;//这是预期的#2
结果=repository.Connection.Client.SyncFiles(syncFlags,new[]{new P4.FileSpec(clientPath,new P4.Revision(0))});
downloadedVersion=results.First().Version;//文件真的被删除了,我希望是#0,但它是#2!

如何获取文件已删除的信息?我尝试使用SyncFiles output进行此操作,但删除文件的信息不正确。还有其他方法吗?

Client.SyncFiles函数为您提供了受影响文件的详细列表,但不包括sync命令的其余输出。如果您只是想知道该文件是否已被删除,那么将clientFile放在本地计算机上就可以了

如果您想要完整输出,使用P4Server接口是更好的选择:


如果在“taged”设置为true的情况下调用RunCommand(),它将提供从“p4-Ztag(command)”中获得的所有数据,并通过gettaggeOutput()访问结果。在不使用“tagged”选项的情况下运行它,将为您提供作为最终用户看到的格式化消息,可通过GetInfoMessages()访问。

Client.SyncFiles函数为您提供受影响文件的整洁列表,但不包括sync命令的其余输出。如果您只是想知道该文件是否已被删除,那么将clientFile放在本地计算机上就可以了

如果您想要完整输出,使用P4Server接口是更好的选择:


如果在“taged”设置为true的情况下调用RunCommand(),它将提供从“p4-Ztag(command)”中获得的所有数据,并通过gettaggeOutput()访问结果。在不使用“tagged”选项的情况下运行它,将为您提供作为最终用户看到的格式化消息,可通过GetInfoMessages()访问。

Client.SyncFiles函数为您提供受影响文件的整洁列表,但不包括sync命令的其余输出。如果您只是想知道该文件是否已被删除,那么将clientFile放在本地计算机上就可以了

如果您想要完整输出,使用P4Server接口是更好的选择:


如果在“taged”设置为true的情况下调用RunCommand(),它将提供从“p4-Ztag(command)”中获得的所有数据,并通过gettaggeOutput()访问结果。在不使用“tagged”选项的情况下运行它,将为您提供作为最终用户看到的格式化消息,可通过GetInfoMessages()访问。

Client.SyncFiles函数为您提供受影响文件的整洁列表,但不包括sync命令的其余输出。如果您只是想知道该文件是否已被删除,那么将clientFile放在本地计算机上就可以了

如果您想要完整输出,使用P4Server接口是更好的选择:


如果在“taged”设置为true的情况下调用RunCommand(),它将提供从“p4-Ztag(command)”中获得的所有数据,并通过gettaggeOutput()访问结果。不使用“tagged”(标记)选项运行它将为您提供作为最终用户看到的格式化消息,可通过GetInfoMessages()访问。

以下是我找到的解决方案:

repository.Connection.TaggedOutputReceived += Connection_TaggedOutputReceived;


static void Connection_TaggedOutputReceived(uint cmdId, int ObjId, P4.TaggedObject t)
{
    string action, oldAction, haveRevStr, depotFile;

    t.TryGetValue("action", out action);
    t.TryGetValue("oldAction", out oldAction);
    t.TryGetValue("haveRev", out haveRevStr);
    t.TryGetValue("depotFile", out depotFile);

    if (haveRevStr == null || haveRevStr == "none")
        haveRevStr = string.Empty;
    else
        haveRevStr = "#" + haveRevStr;

    if (string.IsNullOrEmpty(oldAction))
        oldAction = string.Empty;
    else
        oldAction = oldAction + " ";

    if (depotFile != null && action != null)
        Console.Out.WriteLine("{0}{1} - {2}{3}", depotFile, haveRevStr, oldAction, action);
}

。。。repository.Connection还包含要钩住的其他有趣委托:.CommandEcho、.Errorreceived、.InfoResultReceived、.TextResultsReceived

以下是我找到的解决方案:

repository.Connection.TaggedOutputReceived += Connection_TaggedOutputReceived;


static void Connection_TaggedOutputReceived(uint cmdId, int ObjId, P4.TaggedObject t)
{
    string action, oldAction, haveRevStr, depotFile;

    t.TryGetValue("action", out action);
    t.TryGetValue("oldAction", out oldAction);
    t.TryGetValue("haveRev", out haveRevStr);
    t.TryGetValue("depotFile", out depotFile);

    if (haveRevStr == null || haveRevStr == "none")
        haveRevStr = string.Empty;
    else
        haveRevStr = "#" + haveRevStr;

    if (string.IsNullOrEmpty(oldAction))
        oldAction = string.Empty;
    else
        oldAction = oldAction + " ";

    if (depotFile != null && action != null)
        Console.Out.WriteLine("{0}{1} - {2}{3}", depotFile, haveRevStr, oldAction, action);
}

。。。repository.Connection还包含要钩住的其他有趣委托:.CommandEcho、.Errorreceived、.InfoResultReceived、.TextResultsReceived

以下是我找到的解决方案:

repository.Connection.TaggedOutputReceived += Connection_TaggedOutputReceived;


static void Connection_TaggedOutputReceived(uint cmdId, int ObjId, P4.TaggedObject t)
{
    string action, oldAction, haveRevStr, depotFile;

    t.TryGetValue("action", out action);
    t.TryGetValue("oldAction", out oldAction);
    t.TryGetValue("haveRev", out haveRevStr);
    t.TryGetValue("depotFile", out depotFile);

    if (haveRevStr == null || haveRevStr == "none")
        haveRevStr = string.Empty;
    else
        haveRevStr = "#" + haveRevStr;

    if (string.IsNullOrEmpty(oldAction))
        oldAction = string.Empty;
    else
        oldAction = oldAction + " ";

    if (depotFile != null && action != null)
        Console.Out.WriteLine("{0}{1} - {2}{3}", depotFile, haveRevStr, oldAction, action);
}

。。。repository.Connection还包含要钩住的其他有趣委托:.CommandEcho、.Errorreceived、.InfoResultReceived、.TextResultsReceived

以下是我找到的解决方案:

repository.Connection.TaggedOutputReceived += Connection_TaggedOutputReceived;


static void Connection_TaggedOutputReceived(uint cmdId, int ObjId, P4.TaggedObject t)
{
    string action, oldAction, haveRevStr, depotFile;

    t.TryGetValue("action", out action);
    t.TryGetValue("oldAction", out oldAction);
    t.TryGetValue("haveRev", out haveRevStr);
    t.TryGetValue("depotFile", out depotFile);

    if (haveRevStr == null || haveRevStr == "none")
        haveRevStr = string.Empty;
    else
        haveRevStr = "#" + haveRevStr;

    if (string.IsNullOrEmpty(oldAction))
        oldAction = string.Empty;
    else
        oldAction = oldAction + " ";

    if (depotFile != null && action != null)
        Console.Out.WriteLine("{0}{1} - {2}{3}", depotFile, haveRevStr, oldAction, action);
}

。。。repository.Connection还包含其他要挂接的有趣委托:.CommandEcho、.Errorreceived、.InfoResultReceived、.TextResultsReceived

请注意,“同步文件#0”与同步已通过删除修订显式删除的文件并不完全相同。此外,也许“新P4.Revision(0)”没有达到您预期的效果。查看服务器的命令日志(服务器上的P4LOG文件),并查看服务器上记录的实际“p4 sync”命令。特别是,服务器是否将最终命令注册为“p4 sync”或“p4 sync#0”?非常感谢您的评论。不幸的是,我没有在我的服务器上查看P4LOG文件的权限和可能性。但我看到P4.Revision(0)确实删除了我客户端中的文件,并且P4.Revision(1)添加了它。所以它起作用了。请注意,P4.Revision(0)并不是我期望的唯一用法。我的应用程序可以在没有我的文件的情况下同步到标签,在这种情况下,文件也需要删除。我用了雷维斯