我正在使用 TFS SDK,并且我有一种方法可以获取最新版本的项目。但是当我调用方法时,它总是重新下载文件。这也需要很长时间。
我试过了,我得到了changeSet,我比较了特别的项目。如果项目有变化,请下载。但是这种方式也需要很长时间。
这是我的第一个没有检查 changeSet 的代码
ItemSet items = sourceControl.GetItems(itemPath, VersionSpec.Latest, RecursionType.Full);
foreach (Item item in items.Items)
{
localName = item.ServerItem.ToString();
localName = localName.Substring(2, (localName.Length - 2)).Replace("/", "\\");
switch (item.ItemType)
{
case ItemType.Any:
throw new ArgumentOutOfRangeException("ItemType returned was Any; expected File or Folder.");
case ItemType.File:
item.DownloadFile("D:\\WORK\\Tries\\"+localName);
break;
case ItemType.Folder:
Directory.CreateDirectory("D:\\WORK\\Tries\\"+localName);
break;
}
}
那是我检查变更集的新代码
ItemSet items = sourceControl.GetItems(itemPath, VersionSpec.Latest, RecursionType.Full);
foreach (Item item in items.Items)
{
localName = item.ServerItem.ToString();
localName = localName.Substring(2, (localName.Length - 2)).Replace("/", "\\");
var histories = sourceControl.QueryHistory(itemPath, VersionSpec.Latest, 0, RecursionType.OneLevel, null, null, null, Int32.MaxValue, true, false, true);
bool check = false;
foreach (Changeset history in histories)
{
foreach (Change change in history.Changes)
{
if (change.Item.Equals(item))
check = true;
}
}
switch (item.ItemType)
{
case ItemType.Any:
throw new ArgumentOutOfRangeException("ItemType returned was Any; expected File or Folder.");
case ItemType.File:
if(check)
item.DownloadFile("D:\\WORK\\Tries\\"+localName);
break;
case ItemType.Folder:
if(!Directory.Exists("D:\\WORK\\Tries\\" + localName))
Directory.CreateDirectory("D:\\WORK\\Tries\\"+localName);
break;
}
}
有人有建议吗?谢谢。
编辑:我以这种方式解决了问题:
String ServerFolder = itemPath; // start with "$/ + serverFolder path"
itemPath = itemPath.Substring(2, (itemPath.Length - 2)).Replace("/", "\\");
String LocalFolder = @"D:\WORK\"+itemPath;
WorkingFolder workfolder = new WorkingFolder(ServerFolder, LocalFolder);
workspace.CreateMapping(workfolder);
workspace.Get(VersionSpec.Latest,GetOptions.Overwrite);