Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检查本地文件是否为tfs中的最新版本?_C#_Tfs_Tfs Sdk - Fatal编程技术网

C# 如何检查本地文件是否为tfs中的最新版本?

C# 如何检查本地文件是否为tfs中的最新版本?,c#,tfs,tfs-sdk,C#,Tfs,Tfs Sdk,我希望能够查询TfsTeamProjectCollection并确定服务器上是否有更新版本的文件。我希望能够做到这一点,而不是实际获取文件 这在什么地方可能吗?到目前为止,我已经画了一些空白的地方 谢谢。最简单的方法是在工作区版本和最新版本之间切换;如果它们不同,则服务器上存在更新的最新版本。例如: versionControlServer.QueryHistory( serverPath, VersionSpec.Latest, 0, RecursionType

我希望能够查询TfsTeamProjectCollection并确定服务器上是否有更新版本的文件。我希望能够做到这一点,而不是实际获取文件

这在什么地方可能吗?到目前为止,我已经画了一些空白的地方

谢谢。

最简单的方法是在工作区版本和最新版本之间切换;如果它们不同,则服务器上存在更新的最新版本。例如:

versionControlServer.QueryHistory(
    serverPath,
    VersionSpec.Latest,
    0,
    RecursionType.Full,
    new WorkspaceVersionSpec(workspace),
    versionFrom,
    null,
    Int32.MaxValue,
    true,
    true);

这是检查给定文件是否为最新文件的另一种方法

string file_path = @"your_file_path";

WorkspaceInfo info = Workstation.Current.GetLocalWorkspaceInfo(file_path);

Workspace ws = info.GetWorkspace(new TfsTeamProjectCollection(info.ServerUri));

GetStatus status = ws.Get( new GetRequest(
                                          new ItemSpec ( file_path, RecursionType.Full ), 
                                          VersionSpec.Latest ), 
                            GetOptions.Preview );

if(status.NoActionNeeded)
     MessegeBox.Show("Latest");
else
     MessegeBox.Show("Not Latest");
步骤

1)我们需要获取包含文件路径的
工作区。我们使用

获取包含包含指定文件的工作区属性的对象

我们可以使用这个
WorkspaceInfo
对象通过使用

2)现在我们需要对workspace对象执行
Get
操作

第二个参数有六个可能的成员值。每个人都有自己的目标

因为你不需要下载文件

我们将使用成员值
预览
,该值
在不修改磁盘的情况下执行get。

3)Get
操作返回一个对象,该对象表示
工作区的状态。Get
操作

这包含有关在处理
Get
操作时发生了多少操作、冲突、错误等的信息

GetStatus
对象有许多属性。我们使用名为
NoActionNeeded
的属性,该属性获取一个标志,指示是否未发生故障和操作


如果未发生任何操作或错误,则标志值将为True。即,该文件已经是最新版本。否则,标志将为False,这意味着该文件不是TFS中可用的最新版本。

//我们必须指定已映射到本地工作区的文件,以便在此处进行比较

            var serverPath = workspace.GetServerItemForLocalItem(Vars.sLocalPath);
            var serverVersion = new DiffItemVersionedFile(versionControlServer, serverPath, VersionSpec.Latest);
            var localVersion = new DiffItemLocalFile(Vars.sLocalPath, System.Text.Encoding.UTF8.CodePage, DateTime.Now, false);

            try
            {
                using (var stream = new MemoryStream())
                using (var writer = new StreamWriter(stream))
                {
                    var diffOptions = new DiffOptions
                    {
                        Flags = DiffOptionFlags.EnablePreambleHandling,
                        OutputType = DiffOutputType.Unified,
                        TargetEncoding = System.Text.Encoding.UTF8,
                        SourceEncoding = System.Text.Encoding.UTF8,
                        StreamWriter = writer
                    };

                    Difference.DiffFiles(versionControlServer, serverVersion, localVersion, diffOptions, serverPath, true);
                    writer.Flush();

                    diff = System.Text.Encoding.UTF8.GetString(stream.ToArray());
                    if (diff != "")
                    {
                        newutils.WriteLogFile("Vars.enumExitCode.Success");
                        iRtnCode = (int)Vars.enumExitCode.Success;
                        return iRtnCode;
                    }
                }
            }
            catch (Exception)
            {

            }