public Task <SourceRepository> FetchAllFiles(BuildConfig config) { return(Task.Run(async() => { if (this.Conn != null) { this.Client = Conn.GetClient <TfvcHttpClient>(); List <TfvcItem> files = await Client.GetItemsAsync(config.RootFolder, VersionControlRecursionType.Full); SourceRepository repo = new SourceRepository(); repo.Files.AddRange(files.Where(x => x.DeletionId == 0).Select(x => new TFSWebFileItem(x, Conn, config, Client))); repo.LatestVersion = files .Select(x => x.ChangesetVersion) .OrderByDescending(x => x) .FirstOrDefault() .ToString(); return repo; } SourceRepository result = new SourceRepository(); result.LatestVersion = Server.GetLatestChangesetId().ToString(); List <ISourceItem> list = result.Files; var items = Server.GetItems(config.RootFolder, VersionSpec.Latest, RecursionType.Full, DeletedState.Any, ItemType.Any); foreach (var item in items.Items) { if (item.DeletionId == 0) { list.Add(new TFS2015FileItem(item, config)); } } return result; })); }
public static async Task <List <TfvcItem> > GetFoldersAsync(this TfvcHttpClient source, string projectName, string basePath, bool recursive, CancellationToken cancellationToken) { Logger.Debug($"Getting folders for '{basePath}', Recursion = {recursive}..."); var level = recursive ? VersionControlRecursionType.Full : VersionControlRecursionType.None; var items = await source.GetItemsAsync(projectName, scopePath : basePath, recursionLevel : level, includeLinks : false, cancellationToken : cancellationToken).ConfigureAwait(false) ?? new List <TfvcItem>(); return(items.Where(i => i.IsFolder).ToList()); }
public TfvcItem DownloadItem() { VssConnection connection = this.Context.Connection; TfvcHttpClient tfvcClient = connection.GetClient <TfvcHttpClient>(); // get the items in the root of the project string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; string scopePath = $"$/{projectName}/"; List <TfvcItem> items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result; foreach (TfvcItem item in items) { if (!item.IsFolder) { Console.WriteLine("You can download file contents for {0} at {1}", item.Path, item.Url); return(item); } } Console.WriteLine("No files found in the root."); return(null); }
public IEnumerable <TfvcItem> ListItems() { VssConnection connection = this.Context.Connection; TfvcHttpClient tfvcClient = connection.GetClient <TfvcHttpClient>(); // get just the items in the root of the project string projectName = ClientSampleHelpers.FindAnyProject(this.Context).Name; string scopePath = $"$/{projectName}/"; List <TfvcItem> items = tfvcClient.GetItemsAsync(scopePath: scopePath, recursionLevel: VersionControlRecursionType.OneLevel).Result; foreach (TfvcItem item in items) { Console.WriteLine("{0} {1} #{3} {2}", item.ChangeDate, item.IsFolder ? "<DIR>" : " ", item.Path, item.ChangesetVersion); } if (items.Count() == 0) { Console.WriteLine("No items found."); } return(items); }
private static async Task DownloadAsync(string tfsUrl, string destinationFolder, string scope, Func <TfvcItem, bool> filter) { int maxConcurrency = 8; ServicePointManager.DefaultConnectionLimit = maxConcurrency; var baseUrl = new Uri(tfsUrl); VssClientCredentials vssClientCredentials = new VssClientCredentials(); vssClientCredentials.Storage = new VssClientCredentialStorage(); var vssHttpRequestSettings = new VssHttpRequestSettings(); vssHttpRequestSettings.SendTimeout = TimeSpan.FromMilliseconds(-1); var client = new TfvcHttpClient(baseUrl, vssClientCredentials, vssHttpRequestSettings); try { var items = await client.GetItemsAsync(scopePath : scope, recursionLevel : VersionControlRecursionType.Full, includeLinks : false).ConfigureAwait(false); var files = items.Where(filter).OrderBy(_ => _.Path).ToList(); var transformBlock = new TransformBlock <TfvcItem, TfvcItem>(async item => { if (item.IsFolder) { var fullPath = GetFullPath(destinationFolder, item.Path); if (!Directory.Exists(fullPath)) { Directory.CreateDirectory(fullPath); } } else { var fullPath = GetFullPath(destinationFolder, item.Path); var folderPath = Path.GetDirectoryName(fullPath); if (folderPath != null && !Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } using (var stream = await client.GetItemContentAsync(item.Path)) using (var fs = File.Create(fullPath)) { await stream.CopyToAsync(fs).ConfigureAwait(false); } } return(item); }, new ExecutionDataflowBlockOptions { MaxDegreeOfParallelism = maxConcurrency }); var writePathBlock = new ActionBlock <TfvcItem>(c => { var index = files.IndexOf(c); Console.WriteLine($"{index}/{files.Count}: {c.Path}"); }); transformBlock.LinkTo(writePathBlock, new DataflowLinkOptions { PropagateCompletion = true }); foreach (var item in files) { transformBlock.Post(item); } transformBlock.Complete(); await transformBlock.Completion.ConfigureAwait(false); } catch (Exception ex) { Console.WriteLine(ex); } }