/// <summary> /// performs the real action /// </summary> /// <param name="options"></param> /// <returns></returns> private static Result PerformAction(UploaderOptions options) { // filenamen lesen var filePaths = Filehelper.GetFilePaths(options.SourceFolder, out var ret); if (ret != null) { return(ret); } // http client initialisieren HttpUploader uploader; try { uploader = new HttpUploader(options); } catch (Exception) { ret = new Result(EExitCode.INVALID_PARAMS, $"Check {options.RepositoryUrl} and {options.GroupId } and {options.ArtifactId} and {options.Revision} "); return(ret); } // upload ret = uploader.UploadAsync(filePaths).GetAwaiter().GetResult(); if (ret != null) { // remove uploaded files ret = uploader.RemoveAsync(filePaths).GetAwaiter().GetResult(); } return(ret ?? new Result(EExitCode.SUCCESS, "")); }
public void TestConstruction() { // perform var result = new UploaderOptions(); // test Assert.Equal(Environment.CurrentDirectory, result.SourceFolder); }
/// <summary> /// Initialisiert den HTTP Client /// </summary> /// <param name="options"></param> /// <returns>HttpClient</returns> private HttpClient InitHttpClient(UploaderOptions options) { HttpClient ret = null; ret = new HttpClient { BaseAddress = new Uri(options.RepositoryUrl + options.GroupId + URL_DELIMETER + options.ArtifactId + URL_DELIMETER + options.Revision) }; string authparam = options.Username + ":" + options.Password; byte[] bytes = Encoding.UTF8.GetBytes(authparam); var base64String = Convert.ToBase64String(bytes); ret.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", base64String); return(ret); }
public void TestConstructionEmpty() { sourceOptions = new UploaderOptions(); Assert.Throws <UriFormatException>(() => new HttpUploader(sourceOptions)); }
/// <summary> /// Konstruktor /// </summary> /// <param name="options"></param> public HttpUploader(UploaderOptions options) { _options = options ?? throw new ArgumentNullException(nameof(options)); _httpCLient = InitHttpClient(_options); }