public void GetSingleAsset(string assetUri, FilePath outputPath)
        {
            var client = new HttpClient();

            _configuration.Apply(client);

            var response = client.GetAsync(assetUri).Result;

            if (response.StatusCode.Equals(HttpStatusCode.Unauthorized) ||
                response.StatusCode.Equals(HttpStatusCode.Forbidden))
            {
                throw new CakeException("Authorization to ProGet server failed; Credentials were incorrect, or not supplied.");
            }

            if (response.StatusCode.Equals(HttpStatusCode.NotFound))
            {
                throw new CakeException("The asset was not found.");
            }

            using (var streamToReadFrom = response.Content.ReadAsStreamAsync().Result)
                using (var file = new FileStream(outputPath.FullPath, FileMode.CreateNew, FileAccess.Write))
                {
                    streamToReadFrom.CopyTo(file);
                }
        }
Beispiel #2
0
        /// <summary>
        /// Creates a new Asset Directory at the specified path.
        /// </summary>
        /// <param name="directoryUri">The fullly qualified URI to the new directory.</param>
        /// <exception cref="CakeException">Thrown if authorization fails.</exception>
        public void CreateDirectory(string directoryUri)
        {
            var client = new HttpClient();

            _configuration.Apply(client);

            var result = client.SendAsync(new HttpRequestMessage(HttpMethod.Post, directoryUri)).Result;

            if (result.StatusCode.Equals(HttpStatusCode.Unauthorized) || result.StatusCode.Equals(HttpStatusCode.Forbidden))
            {
                throw new CakeException("Authorization to ProGet server failed; Credentials were incorrect, or not supplied.");
            }
        }