public static async Task <QueryHierarchyItem> AddFolderAsync(this WorkItemTrackingHttpClient source, TeamProject project, QueryPath folderPath, CancellationToken cancellationToken) { var folder = await source.GetFolderAsync(project, folderPath.FullPath, cancellationToken).ConfigureAwait(false); if (folder != null) { return(folder); } //Ensure the parent folder exists, unless it is a root path cancellationToken.ThrowIfCancellationRequested(); if (folderPath.Parent != null && !folderPath.Parent.IsRoot) { await source.AddFolderAsync(project, folderPath.Parent, cancellationToken).ConfigureAwait(false); } var query = new QueryHierarchyItem() { Name = folderPath.Name, IsFolder = true }; cancellationToken.ThrowIfCancellationRequested(); return(await source.CreateQueryAsync(query, project.Id, folderPath.Parent?.FullPath, cancellationToken : cancellationToken).ConfigureAwait(false)); }