Querying TFS 2015 Source Code Repository CreationTime and LastWriteTime Properties with .Net Framework v4.8 and Visual Studio 2019

  • Thread starter Thread starter HDOlsen
  • Start date Start date
H

HDOlsen

Guest
Hello,

I am trying to filter for source control files that were either created or modified within the last 3 years and that are located in our Team Foundation Server 2015 branches. I am able to access the files of specific branches with the Microsoft.VisualStudio.Services.WebAPI and Microsoft.TeamFoundation.SourceControl.WebApi libraries. The GetItemsAsync() method returns a list of "GitItems" that contain a "path" property that can purportedly be passed as an argument into the System.IO class FileInfo to instantiate an object with the properties I need: CreationTime and LastWriteTime. However the GitItem objects in my program do not include the full file (blob) path that FileClass needs to generate these properties accurately. For instance, in the code below, the variable lastWriteTime returns 12/31/1600 7:00:00 PM. The CreationTime property returns the same. I would like not to have to use another source control .Net library. Thanks.


using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using Microsoft.VisualStudio.Services.Common;
using Microsoft.VisualStudio.Services.Client;
using Microsoft.TeamFoundation.SourceControl.WebApi;
using Microsoft.VisualStudio.Services.WebApi;

namespace VSS_Rest_API
{
class Program
{
const string teamCollection = "http://tfs.infosys.com:8080/tfs/TRSA/";
const string teamProject = "PHBs";


static void Main(string[] args)
{
VssCredentials creds = new VssClientCredentials();
creds.Storage = new VssClientCredentialStorage();

VssConnection connection = new VssConnection(new Uri(teamCollection), creds);

// Get a GitHttpClient to talk to the Git endpoints
GitHttpClient gitClient = connection.GetClient<GitHttpClient>();

// Get data about a specific repository
var repositories = gitClient.GetRepositoriesAsync(teamProject).Result;

GitVersionDescriptor descriptor = new GitVersionDescriptor()
{
VersionType = GitVersionType.Branch,
Version = "develop",
VersionOptions = GitVersionOptions.None
};

foreach (var repository in repositories)
{

var branches = gitClient.GetBranchesAsync(repository.Id).Result;
var items = gitClient.GetItemsAsync(repository.Id, recursionLevel: VersionControlRecursionType.Full, versionDescriptor: descriptor, includeContentMetadata: true).Result;

foreach (var item in items)
{
var fullPath = Path.GetFullPath(item.Path);
FileInfo file = new FileInfo(fullPath);
DateTime lastWriteTime = file.LastWriteTime;
}
Console.WriteLine(repository.Name);
}
}
}
}

Continue reading...
 
Back
Top