如何将文件从TFS直接读入内存(即,不想从文件系统读入内存)?
如何将文件的最新版本从TFS加载到计算机内存中?我不想将TFS的最新版本放到磁盘上,然后将文件从磁盘加载到内存中。可以使用以下方法解决此问题: VersionControlServer.GetItem方法(字符串)如何将文件从TFS直接读入内存(即,不想从文件系统读入内存)?,tfs,Tfs,如何将文件的最新版本从TFS加载到计算机内存中?我不想将TFS的最新版本放到磁盘上,然后将文件从磁盘加载到内存中。可以使用以下方法解决此问题: VersionControlServer.GetItem方法(字符串) Item.DownloadFile方法 完整方法: private static byte[] GetFile(string tfsLocation, string fileLocation) { // Get a
Item.DownloadFile方法
完整方法:
private static byte[] GetFile(string tfsLocation, string fileLocation)
{
// Get a reference to our Team Foundation Server.
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tfsLocation));
// Get a reference to Version Control.
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
// Listen for the Source Control events.
versionControl.NonFatalError += OnNonFatalError;
versionControl.Getting += OnGetting;
versionControl.BeforeCheckinPendingChange += OnBeforeCheckinPendingChange;
versionControl.NewPendingChange += OnNewPendingChange;
var item = versionControl.GetItem(fileLocation);
using (var stm = item.DownloadFile())
{
return ReadFully(stm);
}
}
private static byte[]GetFile(string-tfsLocation,string-fileLocation)
{
/获取对我们的Team Foundation服务器的引用。
TfsatmProjectCollection tpc=新的TfsatmProjectCollection(新Uri(tfsLocation));
//获取对版本控制的引用。
VersionControlServer versionControl=tpc.GetService();
//侦听源代码管理事件。
versionControl.NonCatalError+=OnNonCatalError;
versionControl.Getting+=OnGetting;
versionControl.BeforeCheckinPendingChange+=OnBeforeCheckinPendingChange;
versionControl.NewPendingChange+=OnNewPendingChange;
var item=versionControl.GetItem(fileLocation);
使用(var stm=item.DownloadFile())
{
准备返回(stm);
}
}
能够使用以下方法解决:
VersionControlServer.GetItem方法(字符串)Item.DownloadFile方法
完整方法:
private static byte[] GetFile(string tfsLocation, string fileLocation)
{
// Get a reference to our Team Foundation Server.
TfsTeamProjectCollection tpc = new TfsTeamProjectCollection(new Uri(tfsLocation));
// Get a reference to Version Control.
VersionControlServer versionControl = tpc.GetService<VersionControlServer>();
// Listen for the Source Control events.
versionControl.NonFatalError += OnNonFatalError;
versionControl.Getting += OnGetting;
versionControl.BeforeCheckinPendingChange += OnBeforeCheckinPendingChange;
versionControl.NewPendingChange += OnNewPendingChange;
var item = versionControl.GetItem(fileLocation);
using (var stm = item.DownloadFile())
{
return ReadFully(stm);
}
}
private static byte[]GetFile(string-tfsLocation,string-fileLocation)
{
/获取对我们的Team Foundation服务器的引用。
TfsatmProjectCollection tpc=新的TfsatmProjectCollection(新Uri(tfsLocation));
//获取对版本控制的引用。
VersionControlServer versionControl=tpc.GetService();
//侦听源代码管理事件。
versionControl.NonCatalError+=OnNonCatalError;
versionControl.Getting+=OnGetting;
versionControl.BeforeCheckinPendingChange+=OnBeforeCheckinPendingChange;
versionControl.NewPendingChange+=OnNewPendingChange;
var item=versionControl.GetItem(fileLocation);
使用(var stm=item.DownloadFile())
{
准备返回(stm);
}
}
大多数情况下,我希望以(正确编码的)字符串形式获取内容,因此我采用@morpheus answer并对其进行了修改以实现以下目的:
private static string GetFile(VersionControlServer vc, string fileLocation)
{
var item = vc.GetItem(fileLocation);
var encoding = Encoding.GetEncoding(item.Encoding);
using (var stream = item.DownloadFile())
{
int size = (int)item.ContentLength;
var bytes = new byte[size];
stream.Read(bytes, 0, size);
return encoding.GetString(bytes);
}
}
大多数情况下,我希望以(正确编码的)字符串形式获取内容,因此我采用@morpheus answer并对其进行了修改,以实现以下目的:
private static string GetFile(VersionControlServer vc, string fileLocation)
{
var item = vc.GetItem(fileLocation);
var encoding = Encoding.GetEncoding(item.Encoding);
using (var stream = item.DownloadFile())
{
int size = (int)item.ContentLength;
var bytes = new byte[size];
stream.Read(bytes, 0, size);
return encoding.GetString(bytes);
}
}
从命令行?从API?从命令行?来自API?