public static BuildHttpClient GetBuildClient(this TfsOptions configuration) { var connection = GetVssConnection(new Uri(configuration.ServerUrl), configuration.Token); var settings = new VssHttpRequestSettings(); return(new BuildHttpClient(connection.Uri, connection.Credentials, settings)); }
public VssConnection( Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : this(baseUrl, new VssHttpMessageHandler(credentials, settings), null) { }
public TaskAgentHttpClient( Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
public TaskAgentHttpClient( Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings, params DelegatingHandler[] handlers) : base(baseUrl, credentials, settings, handlers) { }
/// <summary> /// Initializes a new instance of the <see cref="ItemBuildCacheHttpClient"/> class. /// </summary> public ItemBuildCacheHttpClient( Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings requestSettings, params DelegatingHandler[] handlers) : base(baseUrl, credentials, requestSettings, handlers) { }
/// <summary> /// /// </summary> /// <param name="managedType"></param> /// <returns></returns> private async Task <Object> GetClientInstanceAsync( Type managedType, Guid serviceIdentifier, CancellationToken cancellationToken, VssHttpRequestSettings settings, DelegatingHandler[] handlers) { CheckForDisposed(); ILocationService locationService = await GetServiceAsync <ILocationService>(cancellationToken).ConfigureAwait(false); ILocationDataProvider locationData = await locationService.GetLocationDataAsync(serviceIdentifier, cancellationToken).ConfigureAwait(false); if (locationData == null) { throw new VssServiceException(WebApiResources.ServerDataProviderNotFound(serviceIdentifier)); } String serviceLocationString = await locationData.LocationForCurrentConnectionAsync( ServiceInterfaces.LocationService2, LocationServiceConstants.SelfReferenceIdentifier, cancellationToken).ConfigureAwait(false); // This won't ever be null because of compat code in ServerDataProvider Uri clientBaseUri = new Uri(serviceLocationString); VssHttpClientBase toReturn = null; if (settings != null) { toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, Credentials, settings, handlers); } else { toReturn = (VssHttpClientBase)Activator.CreateInstance(managedType, clientBaseUri, m_pipeline, false /* disposeHandler */); } ApiResourceLocationCollection resourceLocations = await locationData.GetResourceLocationsAsync(cancellationToken).ConfigureAwait(false); toReturn.SetResourceLocations(resourceLocations); return(toReturn); }
public FileContainerServer( Uri projectCollectionUrl, VssCredentials credential, Guid projectId, long containerId, string containerPath) { _projectCollectionUrl = projectCollectionUrl; _credential = credential; _projectId = projectId; _containerId = containerId; _containerPath = containerPath; // default file upload request timeout to 300 seconds // TODO: Load from .ini file. VssHttpRequestSettings fileUploadRequestSettings = new VssHttpRequestSettings(); fileUploadRequestSettings.SendTimeout = TimeSpan.FromSeconds(300); FileContainerHttpClient = new FileContainerHttpClient( _projectCollectionUrl, _credential, fileUploadRequestSettings, new VssHttpRetryMessageHandler(3)); }
public FileContainerServer( Uri projectCollectionUrl, VssCredentials credential, Guid projectId, long containerId, string containerPath) { _projectCollectionUrl = projectCollectionUrl; _credential = credential; _projectId = projectId; _containerId = containerId; _containerPath = containerPath; // default file upload request timeout to 300 seconds // TODO: Load from .ini file. VssHttpRequestSettings fileUploadRequestSettings = new VssHttpRequestSettings(); fileUploadRequestSettings.SendTimeout = TimeSpan.FromSeconds(300); FileContainerHttpClient = new FileContainerHttpClient( _projectCollectionUrl, _credential, fileUploadRequestSettings, new VssHttpRetryMessageHandler(3)); }
public FileContainerHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
public LocationHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
internal VssBuildClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings, ILogger logger) : base(baseUrl, credentials, settings) { this.logger = logger; }
public async static Task <AttachmentReference> CreateAttachmentChunkedAsync(WorkItemTrackingHttpClient client, VssConnection connection, MemoryStream uploadStream, int chunkSizeInBytes) { // it's possible for the attachment to be empty, if so we can't used the chunked upload and need // to fallback to the normal upload path. if (uploadStream.Length == 0) { return(await CreateAttachmentAsync(client, uploadStream)); } var requestSettings = new VssHttpRequestSettings { SendTimeout = TimeSpan.FromMinutes(5) }; var httpClient = new HttpClient(new VssHttpMessageHandler(connection.Credentials, requestSettings)); // first create the attachment reference. // can't use the WorkItemTrackingHttpClient since it expects either a file or a stream. var attachmentReference = await RetryHelper.RetryAsync(async() => { var request = new HttpRequestMessage(HttpMethod.Post, $"{connection.Uri}/_apis/wit/attachments?uploadType=chunked&api-version=3.2"); var response = await httpClient.SendAsync(request); if (response.IsSuccessStatusCode) { return(await response.Content.ReadAsAsync <AttachmentReference>()); } else { var exceptionResponse = await response.Content.ReadAsAsync <ExceptionResponse>(); throw new Exception(exceptionResponse.Message); } }, 5); // now send up each chunk var totalNumberOfBytes = uploadStream.Length; // if number of chunks divides evenly, no need to add an extra chunk var numberOfChunks = ClientHelpers.GetBatchCount(totalNumberOfBytes, chunkSizeInBytes); for (var i = 0; i < numberOfChunks; i++) { var chunkBytes = new byte[chunkSizeInBytes]; // offset is always 0 since read moves position forward var chunkLength = uploadStream.Read(chunkBytes, 0, chunkSizeInBytes); var result = await RetryHelper.RetryAsync(async() => { // manually create the request since the WorkItemTrackingHttpClient does not support chunking var content = new ByteArrayContent(chunkBytes, 0, chunkLength); content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); content.Headers.ContentLength = chunkLength; content.Headers.ContentRange = new ContentRangeHeaderValue(i *chunkSizeInBytes, i *chunkSizeInBytes + chunkLength - 1, totalNumberOfBytes); var chunkRequest = new HttpRequestMessage(HttpMethod.Put, $"{connection.Uri}/_apis/wit/attachments/" + attachmentReference.Id + "?uploadType=chunked&api-version=3.2") { Content = content }; var chunkResponse = await httpClient.SendAsync(chunkRequest); if (!chunkResponse.IsSuccessStatusCode) { // there are two formats for the exception, so detect both. var responseContentAsString = await chunkResponse.Content.ReadAsStringAsync(); var criticalException = JsonConvert.DeserializeObject <CriticalExceptionResponse>(responseContentAsString); var exception = JsonConvert.DeserializeObject <ExceptionResponse>(responseContentAsString); throw new Exception(criticalException.Value?.Message ?? exception.Message); } return(chunkResponse.StatusCode); }, 5); } return(attachmentReference); }
public PackagingHttpClient(Uri url, VssCredentials credentials, VssHttpRequestSettings settings, params DelegatingHandler[] handlers) : base(url, credentials, settings, handlers) { _uri = url; }
public PipelinesHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
/// <summary> /// Creates a new instance of the GenericHttpClient class /// </summary> public GenericHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings, params DelegatingHandler[] handlers) : base(SetHost(baseUrl), credentials, settings, handlers) { }
public PackagingHttpClient(Uri url, VssCredentials credentials, VssHttpRequestSettings settings) : base(url, credentials, settings) { _uri = url; }
public AzureConnection(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
/// <summary> /// Creates a new instance of the GenericHttpClient class /// </summary> public GenericHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(SetHost(baseUrl), credentials, settings) { }
public PipelinesHttpClientBase(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings, params DelegatingHandler[] handlers) : base(baseUrl, credentials, settings, handlers) { }
/// <summary> /// Initializes a new instance of the <see cref="ServiceHooksHttpClient"/> class. /// </summary> /// <param name="baseUrl">The base url.</param> /// <param name="credentials">The credentials.</param> /// <param name="settings">The request settings.</param> public ServiceHooksHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
public CaptainHookGraphHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings) : base(baseUrl, credentials, settings) { }
public CaptainHookGraphHttpClient(Uri baseUrl, VssCredentials credentials, VssHttpRequestSettings settings, params DelegatingHandler[] handlers) : base(baseUrl, credentials, settings, handlers) { }
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); } }