public async Task PushPackageWithCredentials(string filePath, IPackageMetadata package, bool pushAsUnlisted, bool appendV2ApiToUrl, string username, string password) { var requestUri = CreateRequestUri(appendV2ApiToUrl); // Nuget Server returns Created. VSTS Returns Accepted var expectedStatus = HttpStatusCode.Created | HttpStatusCode.Accepted; var httpRequest = CreatePushRequest(requestUri); ConfigureRequestAuthCredentials(httpRequest, username, password); var multipartRequest = new MultipartWebRequest(); multipartRequest.AddFile(new FileInfo(filePath), package.ToString()); // sending package data asynchronously await multipartRequest.CreateMultipartRequest(httpRequest); // waiting for response asynchronously await EnsureSuccessfulResponse(httpRequest, expectedStatus); if (pushAsUnlisted) { await DeletePackageFromServerWithCredentials(package.Id, package.Version.ToString(), appendV2ApiToUrl, username, password); } }
public async Task PushPackage(string apiKey, string filePath, IPackageMetadata package, bool pushAsUnlisted, bool appendV2ApiToUrl) { string requestUri = CreateRequestUri(appendV2ApiToUrl); HttpWebRequest httpRequest = WebRequest.CreateHttp(requestUri); httpRequest.Method = "PUT"; httpRequest.AllowAutoRedirect = true; httpRequest.KeepAlive = false; httpRequest.Headers.Add(ApiKeyHeader, apiKey); httpRequest.UserAgent = _userAgent; httpRequest.UseDefaultCredentials = true; httpRequest.PreAuthenticate = true; var multipartRequest = new MultipartWebRequest(); multipartRequest.AddFile(new FileInfo(filePath), package.ToString()); // sending package data asynchronously await multipartRequest.CreateMultipartRequest(httpRequest); // waiting for response asynchronously await EnsureSuccessfulResponse(httpRequest, HttpStatusCode.Created); if (pushAsUnlisted) { await DeletePackageFromServer(apiKey, package.Id, package.Version.ToString(), appendV2ApiToUrl); } }
public async Task PushPackage(string apiKey, string filePath, IPackageMetadata package, bool pushAsUnlisted, bool appendV2ApiToUrl) { string requestUri = CreateRequestUri(appendV2ApiToUrl); HttpWebRequest httpRequest = WebRequest.CreateHttp(requestUri); httpRequest.Method = "PUT"; httpRequest.AllowAutoRedirect = true; httpRequest.AllowWriteStreamBuffering = false; httpRequest.KeepAlive = false; httpRequest.Headers.Add(ApiKeyHeader, apiKey); httpRequest.UserAgent = _userAgent; var multipartRequest = new MultipartWebRequest(); multipartRequest.AddFile(new FileInfo(filePath), package.ToString()); // sending package data asynchronously await multipartRequest.CreateMultipartRequest(httpRequest); // waiting for response asynchronously await EnsureSuccessfulResponse(httpRequest, HttpStatusCode.Created); if (pushAsUnlisted) { await DeletePackageFromServer(apiKey, package.Id, package.Version.ToString(), appendV2ApiToUrl); } }