简体   繁体   English

如何从指定工作区中特定日期修改的TFS获取文件列表?

[英]How to get a list of files from TFS modified on a certain date in the specified workspace?

I have to create a list of files that were modified(checked out or checked in) on a specified date. 我必须创建一个在指定日期修改(签出或签入)的文件列表。

I have user name and their workspace name given as parameters to my function. 我有用户名和他们的工作区名称作为我的函数的参数。

Any suggestions? 有什么建议么?

I think you want to do a combination of VersionControlServer.QueryHistory for figuring out the changes to files on a particular date combined with VersionControlServer.QueryWorkspaces to get hold of the workspace to pull out the working folder mappings that you'll want to query for the recursive history on. 我想你想组合使用VersionControlServer.QueryHistory来确定特定日期文件的变化,并结合VersionControlServer.QueryWorkspaces来获取工作空间,以提取你想要查询的工作文件夹映射。递归历史。

I'm pretty sure you cannot tell which workspace a particular changeset came from though without doing something funky with a custom check-in policies to get that information into the changeset in the first place. 我很确定你无法分辨出特定变更集来自哪个工作区,而没有使用自定义签入策略做一些时髦的事情,以便首先将这些信息放入变更集中。 That is to say, I do not know of a way to tell two changes apart from the same developer who happen to change them on two different workspaces. 也就是说,我不知道一种方法可以告诉两个变化,而不是同一个开发人员碰巧在两个不同的工作空间上更改它们。 So what might be easier is to find out if you can remove the workspace requirement and simply return the files change by a particular user on a particular date using a single call to QueryHistory? 那么可能更容易的是找出是否可以删除工作空间要求,只需使用一次QueryHistory调用,在特定日期返回特定用户的文件更改?

This what I ended up doing(I have left only the code related to the question): 这就是我最终做的事情(我只留下了与问题相关的代码):

Thank Martin for the directions! 感谢Martin的指示!

void GetPastTFSChangesByDate()
    {
        using (TfsTeamProjectCollection tfsServer = new TfsTeamProjectCollection(_tfsServerUri))
        {
            tfsServer.Authenticate();

            if (tfsServer != null)
            {
                VersionControlServer vcServer = tfsServer.GetService(typeof (VersionControlServer)) as VersionControlServer;

                if (vcServer != null)
                {
                    var usersWorkspaces = vcServer.QueryWorkspaces(null, vcServer.AuthorizedUser, Environment.MachineName).ToList();

                    List<ChangedTFSItem> foundPastChanges = null;

                    if (_isSearchForPastChangesOn)
                    {
                        var allPastChangesets = vcServer.QueryHistory(@"C:\TFS",
                                                                      VersionSpec.Latest,
                                                                      0,
                                                                      RecursionType.Full,
                                                                      Environment.UserName,
                                                                      null,
                                                                      null,
                                                                      3000,
                                                                      true,
                                                                      false).Cast<Changeset>()
                            .Where(x => x.Committer.Contains(Environment.UserName));


                        _foundPastChanges = allPastChangesets
                            .SelectMany(x => x.Changes)
                            .Where(x => x.Item.CheckinDate.Date == _searchDate.Date) // Check-in date filter.
                            .DistinctBy(x => x.Item.ServerItem, x => x.Item.ServerItem.GetHashCode())
                            .Select(x => new ChangedTFSItem()
                                             {
                                                 FileName = "Uknown",
                                                 LocalItem = "Uknown",
                                                 ServerItem = x.Item.ServerItem,
                                                 ChangeTypeName = "",
                                                 ChangeDate = x.Item.CheckinDate.ToString(),
                                                 Workspace = "Uknown"
                                             }).ToList();

                        //Matching those foundPastChanges to the workspace corresponding file locations. 
                        if (usersWorkspaces.Any())
                        {
                            foreach (var item in foundPastChanges)
                            {
                                usersWorkspaces.ForEach(ws =>
                                                            {
                                                                item.LocalItem = ws.GetLocalItemForServerItem(item.ServerItem);
                                                                item.Workspace = ws.Name;
                                                            });

                                item.FileName = Path.GetFileName(item.ServerItem);
                            }
                        }
                    }
                }
            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM