diff --git a/src/ProxyApi.Tests/EpicClientTests.cs b/src/ProxyApi.Tests/EpicClientTests.cs index 215fba9bcae95ed575a59c3a2c4c12d9dc10b524..0b5cbc316829fdf92a7f6fb087e028eb6a174064 100644 --- a/src/ProxyApi.Tests/EpicClientTests.cs +++ b/src/ProxyApi.Tests/EpicClientTests.cs @@ -4,8 +4,6 @@ using NUnit.Framework; using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.Tests { @@ -15,6 +13,7 @@ namespace Coscine.ProxyApi.Tests private readonly IConfiguration _configuration; private readonly string _prefix; private readonly EpicClient _epicClient; + private readonly string _guid; public EpicClientTests() { @@ -29,38 +28,88 @@ namespace Coscine.ProxyApi.Tests _configuration.GetString("coscine/global/epic/user"), _configuration.GetString("coscine/global/epic/password") ); + _guid = Guid.NewGuid().ToString(); + } + + [TearDown] + public void DeleteCreatedPid() + { + _epicClient.Delete(_guid); + } + + [Test] + public void TestCreate() + { + List<EpicData> list = GetPIDValues("pid/?pid={{pid}}"); + + var epicData = _epicClient.Create(list, _guid.ToString()); + Assert.NotNull(epicData); + Assert.IsTrue(epicData.EpicPid == _prefix + "/" + _guid.ToString()); + + var epicDataList = _epicClient.Get(_guid.ToString()); + Assert.IsTrue(epicDataList.Any()); } [Test] - public void ClientTest() + public void TestUpdate() { - Guid guid = Guid.NewGuid(); + // Use old URL + List<EpicData> list = GetPIDValues("coscine/apps/pidresolve/?pid={{pid}}"); + + var epicData = _epicClient.Create(list, _guid.ToString()); + Assert.NotNull(epicData); + Assert.IsTrue(epicData.EpicPid == _prefix + "/" + _guid.ToString()); + + var epicDataList = _epicClient.Get(_guid.ToString()); + Assert.IsTrue(epicDataList.Any(e => e.ParsedData.ToString().Contains("coscine/apps/pidresolve/?pid="))); + Assert.IsFalse(epicDataList.Any(e => e.ParsedData.ToString().Contains("pid/?pid="))); + + // Use new URL + List<EpicData> listNew = GetPIDValues("pid/?pid={{pid}}"); + _epicClient.Update(_guid.ToString(), listNew); + + var epicDataListNew = _epicClient.Get(_guid.ToString()); + Assert.IsFalse(epicDataListNew.Any(e => e.ParsedData.ToString().Contains("coscine/apps/pidresolve/?pid="))); + Assert.IsTrue(epicDataListNew.Any(e => e.ParsedData.ToString().Contains("pid/?pid="))); + } + + private List<EpicData> GetPIDValues(string subpath) + { + var baseUrl = _configuration.GetStringAndWait( + "coscine/local/app/additional/url", + "https://coscine.rwth-aachen.de" + ); EpicData url = new EpicData { Type = "URL", - ParsedData = "https://app.rwth-aachen.de/resolvehandle/?pid={{pid}}" + ParsedData = _configuration.GetStringAndWait( + "coscine/global/epic/pid/url", + $"{baseUrl}/{subpath}" + ) }; EpicData metaurl = new EpicData { Type = "METAURL", - ParsedData = "https://moped.ecampus.rwth-aachen.de/proxy/api/v2/eScience/Metadata/Download?pid={{pid}}" + ParsedData = _configuration.GetStringAndWait( + "coscine/global/epic/pid/metaurl", + $"{baseUrl}/{subpath}" + ) }; - - List<EpicData> list = new List<EpicData> + EpicData dataurl = new EpicData + { + Type = "DATAURL", + ParsedData = _configuration.GetStringAndWait( + "coscine/global/epic/pid/dataurl", + $"{baseUrl}/{subpath}" + ) + }; + return new List<EpicData> { url, metaurl, + dataurl }; - - var epicData = _epicClient.Create(list, guid.ToString()); - Assert.IsTrue(epicData.EpicPid == _prefix + "/" + guid.ToString()); - - var epicDataList = _epicClient.Get(guid.ToString()); - Assert.IsTrue(epicDataList.Count() > 0); - - _epicClient.Delete(guid.ToString()); } - } } diff --git a/src/ProxyApi.Tests/ValidatorTests.cs b/src/ProxyApi.Tests/ValidatorTests.cs index 8f42213e6f65b789d872b7c99aee4967af06ec9b..3ee99b587c5094326a36317d1688fab24ccfdf6e 100644 --- a/src/ProxyApi.Tests/ValidatorTests.cs +++ b/src/ProxyApi.Tests/ValidatorTests.cs @@ -2,11 +2,6 @@ using Coscine.ProxyApi.TokenValidator; using Coscine.ProxyApi.Utils; using NUnit.Framework; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.Tests { diff --git a/src/ProxyApi/ApiConnector.cs b/src/ProxyApi/ApiConnector.cs index 321c1932eb2407bb897a19d32993ce3092ccdcde..d3957cc75f62bace297bbd97bfad86519b5aab40 100644 --- a/src/ProxyApi/ApiConnector.cs +++ b/src/ProxyApi/ApiConnector.cs @@ -1,13 +1,10 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; -using System.Diagnostics; using System.IO; -using System.Linq; using System.Net; using System.Text; using System.Threading; -using System.Threading.Tasks; -using Newtonsoft.Json; namespace Coscine.ProxyApi { diff --git a/src/ProxyApi/MetadataApiConnector.cs b/src/ProxyApi/MetadataApiConnector.cs index 8266d63157e58300af5dee9a62421130177e2451..a1b73e5ed48c99c52b7c2737bb745a99bae83a15 100644 --- a/src/ProxyApi/MetadataApiConnector.cs +++ b/src/ProxyApi/MetadataApiConnector.cs @@ -1,9 +1,9 @@ -using System.Collections.Generic; +using Coscine.ProxyApi.Utils; +using Newtonsoft.Json; +using System.Collections.Generic; using System.Net; using System.Net.Http; using System.Threading.Tasks; -using Coscine.ProxyApi.Utils; -using Newtonsoft.Json; namespace Coscine.ProxyApi { @@ -41,7 +41,7 @@ namespace Coscine.ProxyApi metadataSet[uri].Add(new PropertyDescription(folderName, propertyType)); } - foreach(var constant in metadataConstants) + foreach (var constant in metadataConstants) { if (!metadataSet.ContainsKey(constant.Key)) { diff --git a/src/ProxyApi/ProxyApi.csproj b/src/ProxyApi/ProxyApi.csproj index c82ab0c4155d2b5ae961a396b07e0ecc0708eab1..ef5d0cb9d2f31a3b380766de157e86df7a65f9c5 100644 --- a/src/ProxyApi/ProxyApi.csproj +++ b/src/ProxyApi/ProxyApi.csproj @@ -9,7 +9,7 @@ <PropertyGroup> <Authors>RWTH Aachen University</Authors> <Company>IT Center, RWTH Aachen University</Company> - <Copyright>2021 IT Center, RWTH Aachen University</Copyright> + <Copyright>2022 IT Center, RWTH Aachen University</Copyright> <Description>ProxyApi is a part of the Coscine group.</Description> <PackageLicenseExpression>MIT</PackageLicenseExpression> <PackageProjectUrl>https://git.rwth-aachen.de/coscine/backend/libraries/ProxyApi</PackageProjectUrl> diff --git a/src/ProxyApi/Settings.cs b/src/ProxyApi/Settings.cs index e09f715b10821446d4b6ecee1131cc2c127a9a54..a96c05e3a0752fe8b31018a1bf16890347912b98 100644 --- a/src/ProxyApi/Settings.cs +++ b/src/ProxyApi/Settings.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coscine.ProxyApi +namespace Coscine.ProxyApi { public static class Settings { private static string oAuth2ContextUrlJson = "https://oauth.campus.rwth-aachen.de/oauth2waitress/oauth2.svc/context2"; - public static string OAuth2ContextUrlJson { + public static string OAuth2ContextUrlJson + { get { return oAuth2ContextUrlJson; } set { oAuth2ContextUrlJson = value; } } diff --git a/src/ProxyApi/TokenValidator/CoscineValidator.cs b/src/ProxyApi/TokenValidator/CoscineValidator.cs index 829ea79a54c2345449304487b712aa97e9011b81..488fa6231f5ef79427a2272dad3a47321f1d3d29 100644 --- a/src/ProxyApi/TokenValidator/CoscineValidator.cs +++ b/src/ProxyApi/TokenValidator/CoscineValidator.cs @@ -1,10 +1,5 @@ using Coscine.Configuration; using Coscine.ProxyApi.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.TokenValidator { diff --git a/src/ProxyApi/TokenValidator/ITokenValidator.cs b/src/ProxyApi/TokenValidator/ITokenValidator.cs index 22910b7c52d61b5a0c1a57ab8dfe6cc9d4ff8425..491696f47c7f4f0a6e0b8e37f248dd2385680937 100644 --- a/src/ProxyApi/TokenValidator/ITokenValidator.cs +++ b/src/ProxyApi/TokenValidator/ITokenValidator.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coscine.ProxyApi.TokenValidator +namespace Coscine.ProxyApi.TokenValidator { public interface ITokenValidator { diff --git a/src/ProxyApi/TokenValidator/MetadataValidator.cs b/src/ProxyApi/TokenValidator/MetadataValidator.cs index 0933ee55535ff702520f929d260439d4ade67c3b..af07e298c3c0c11f026b0926ec3e71dc45908a5e 100644 --- a/src/ProxyApi/TokenValidator/MetadataValidator.cs +++ b/src/ProxyApi/TokenValidator/MetadataValidator.cs @@ -1,10 +1,6 @@ using Coscine.Configuration; using Coscine.ProxyApi.Utils; -using System; using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.TokenValidator { diff --git a/src/ProxyApi/TokenValidator/TokenValidator.cs b/src/ProxyApi/TokenValidator/TokenValidator.cs index f47815629787d74d8e7c4f9816f33090cded4150..6db58d7fbbcc1f0f2748c9943f6d26a6892c8400 100644 --- a/src/ProxyApi/TokenValidator/TokenValidator.cs +++ b/src/ProxyApi/TokenValidator/TokenValidator.cs @@ -1,9 +1,4 @@ using Coscine.ProxyApi.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.TokenValidator { diff --git a/src/ProxyApi/TokenValidator/ValidatorBase.cs b/src/ProxyApi/TokenValidator/ValidatorBase.cs index 3d0a3e093a5f84d1e3e7321be366c99d242a8151..3ff265174313209f53915929feb5476a7c24f9f2 100644 --- a/src/ProxyApi/TokenValidator/ValidatorBase.cs +++ b/src/ProxyApi/TokenValidator/ValidatorBase.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.TokenValidator { diff --git a/src/ProxyApi/Utils/ApiResponse.cs b/src/ProxyApi/Utils/ApiResponse.cs index 5fb68c9768369f6836229a8a7b1042475acd54fe..10ddb50c54e57b8c1189a8b78c8b128cea920ee3 100644 --- a/src/ProxyApi/Utils/ApiResponse.cs +++ b/src/ProxyApi/Utils/ApiResponse.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/ApiResponseFactory.cs b/src/ProxyApi/Utils/ApiResponseFactory.cs index 2c99549a407b5fb1864774cd683a3c314de87d89..537a593006903e6deed8466832f23416452bc651 100644 --- a/src/ProxyApi/Utils/ApiResponseFactory.cs +++ b/src/ProxyApi/Utils/ApiResponseFactory.cs @@ -1,14 +1,10 @@ using Coscine.ProxyApi.Utils.Exceptions; +using Newtonsoft.Json; using System; using System.Collections.Generic; using System.Configuration; -using System.Linq; using System.Security.Cryptography; using System.Text; -using System.Threading.Tasks; -using System.Web; -using Newtonsoft.Json; -using Microsoft.AspNetCore.Http; namespace Coscine.ProxyApi.Utils { @@ -69,7 +65,7 @@ namespace Coscine.ProxyApi.Utils string error = $"Token invalid."; if (scope != null) { - error = $"Token invalid: Token expired or scope '{ scope }' is missing."; + error = $"Token invalid: Token expired or scope '{scope}' is missing."; } return ApiResponseFactory.CreateError<T>(error, 1, data); @@ -80,7 +76,7 @@ namespace Coscine.ProxyApi.Utils string error = $"Token invalid: Permission groups are missing."; if (missingGroups != null) { - error = $"Token invalid: Permission group(s) '{ String.Join(",", missingGroups) }' missing."; + error = $"Token invalid: Permission group(s) '{String.Join(",", missingGroups)}' missing."; } return ApiResponseFactory.CreateError<T>(error, 2, data); diff --git a/src/ProxyApi/Utils/CurrentWebRequest.cs b/src/ProxyApi/Utils/CurrentWebRequest.cs index 4a94666815ffde31c0d918e09194a89f65e615ed..739fca8581af718d41ac5b091438ec52d3b909c7 100644 --- a/src/ProxyApi/Utils/CurrentWebRequest.cs +++ b/src/ProxyApi/Utils/CurrentWebRequest.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; +using System.Net; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/Dynamic.cs b/src/ProxyApi/Utils/Dynamic.cs index eb43f8788554134d17a31fec28c81821a7b90f96..2ea14b1f54e5aed85c42127c0de4c0b9fc26d7cc 100644 --- a/src/ProxyApi/Utils/Dynamic.cs +++ b/src/ProxyApi/Utils/Dynamic.cs @@ -1,8 +1,5 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/EpicClient.cs b/src/ProxyApi/Utils/EpicClient.cs index 013bf739de907e9568c3ff7e41b43f6de5c7a530..0f93f652799eb407ab9eac94dba5942e91f06307 100644 --- a/src/ProxyApi/Utils/EpicClient.cs +++ b/src/ProxyApi/Utils/EpicClient.cs @@ -1,44 +1,35 @@ -using System; +using Microsoft.AspNetCore.WebUtilities; +using Newtonsoft.Json; +using System; using System.Collections.Generic; -using System.IO; using System.Linq; using System.Net; +using System.Net.Http; +using System.Net.Http.Headers; +using System.Text; +using System.Threading.Tasks; using System.Web; namespace Coscine.ProxyApi.Utils { public class EpicClient : IEpicClient { - private readonly RestClient restClient = new RestClient(); + private readonly HttpClient _httpClient = new(); public const int errorPrefix = 12000; - private string ServiceEndpoint - { - get; set; - } + private string ServiceEndpoint { get; set; } - private string User - { - get; set; - } - - private string Password - { - get; set; - } - - public string Prefix - { - get; private set; - } + public string Prefix { get; private set; } public EpicClient(string url, string prefix, string user, string password) { ServiceEndpoint = url; - User = user; - Password = password; Prefix = prefix; + + var byteArray = Encoding.ASCII.GetBytes($"{user}:{password}"); + _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Convert.ToBase64String(byteArray)); + _httpClient.DefaultRequestHeaders.Add("Accept", "application/json, */*"); } private void ReplacePayload(string suffix, List<EpicData> payload) @@ -56,122 +47,115 @@ namespace Coscine.ProxyApi.Utils public EpicData Update(string suffix, List<EpicData> payload) { ReplacePayload(suffix, payload); - return EpicRequestWrapper(() => restClient.HttpJson<EpicData, List<EpicData>>("PUT", new Uri(ServiceEndpoint + suffix), null, payload, User, Password)); + + using var requestContent = new StringContent(JsonConvert.SerializeObject(payload), Encoding.UTF8, "application/json"); + var result = EpicRequestWrapper(() => _httpClient.PutAsync(ServiceEndpoint + suffix, requestContent)); + if (result.IsSuccessStatusCode) + { + var content = result.Content.ReadAsStringAsync().Result; + return JsonConvert.DeserializeObject<EpicData>(content); + } + return null; } public EpicData Create(List<EpicData> payload, string guid = null) { string suffix = guid; - if (guid == null) + if (suffix is null) { suffix = Guid.NewGuid().ToString(); } - ReplacePayload(suffix, payload); return Update(suffix, payload); } - public IEnumerable<EpicData> List(int count, int page) + public IEnumerable<EpicData> Search(string searchUrl, int limit = 0) { - var query = string.Format("limit={0}&page={1}", count, page); - var result = EpicRequestWrapper(() => restClient.HttpRaw("GET", new Uri(ServiceEndpoint), query, null, User, Password)); - var pidList = new List<EpicData>(); - using (var reader = new StreamReader(result)) + + // Handle additional query parameters + var parameters = new Dictionary<string, string>(); + if (!string.IsNullOrWhiteSpace(searchUrl)) { - while (!reader.EndOfStream) - { - pidList.Add(new EpicData() { EpicPid = reader.ReadLine() }); - } + parameters.Add("URL", searchUrl); + } + if (limit > 0) + { + parameters.Add("limit", limit.ToString()); + } + // Build the request URL + var url = new Uri(QueryHelpers.AddQueryString(ServiceEndpoint, parameters)); + // Execute the request + var result = EpicRequestWrapper(() => _httpClient.GetAsync(url)); + if (result is not null && result.IsSuccessStatusCode) + { + var content = result.Content.ReadAsStringAsync().Result; + content.Split('\n').ToList().ForEach(e => pidList.Add(new EpicData() { EpicPid = e })); } return pidList; } - public IEnumerable<EpicData> ListAll(int limit = 1000, int startPage = 1) + public IEnumerable<EpicData> List(int limit = 0, int page = 0) { var pidList = new List<EpicData>(); - var tempList = List(limit, startPage); - while (tempList.Count() > 0) + // Handle additional query parameters + var parameters = new Dictionary<string, string>(); + if (limit > 0) { - pidList.AddRange(tempList); - startPage++; - tempList = List(limit, startPage); + parameters.Add("limit", limit.ToString()); + } + if (page > 0) + { + parameters.Add("page", page.ToString()); + } + // Build the request URL + var url = new Uri(QueryHelpers.AddQueryString(ServiceEndpoint, parameters)); + // Execute the request + var result = EpicRequestWrapper(() => _httpClient.GetAsync(url)); + if (result.IsSuccessStatusCode) + { + var content = result.Content.ReadAsStringAsync().Result; + content.Split('\n').ToList().ForEach(e => pidList.Add(new EpicData() { EpicPid = e })); + } + else + { + Console.WriteLine(); } - return pidList; } - public int CountForKpis(int lastPage, int last, int limit) + public IEnumerable<EpicData> ListAll(int limit = 1000, int startPage = 1) { var pidList = new List<EpicData>(); - int page = lastPage; - var query = string.Format("limit={0}&page={1}", limit, lastPage); - - try - { - var result = EpicRequestWrapper(() => restClient.HttpRaw("GET", new Uri(ServiceEndpoint), query, null, User, Password)); + var tempList = List(limit, startPage); - while (result.Length != 0) - { - using (var reader = new StreamReader(result)) - { - if (page == lastPage) - { - //Go on and find out last counted element - int counter = 1; - var div = (double)last / limit; - double truncate = Math.Truncate(div); - var rest = div - truncate; - int lastElem = (int)(rest * limit); - - while (!reader.EndOfStream) - { - var line = reader.ReadLine(); - - if (counter <= lastElem) - { - //skip - counter++; - continue; - } - else - { - pidList.Add(new EpicData() { EpicPid = line }); - counter++; - } - } - page++; - } - else - { - while (!reader.EndOfStream) - { - pidList.Add(new EpicData() { EpicPid = reader.ReadLine() }); - } - page++; - } - } - query = string.Format("limit={0}&page={1}", limit, page); - result = EpicRequestWrapper(() => restClient.HttpRaw("GET", new Uri(ServiceEndpoint), query, null, User, Password)); - } - } - catch (Exception) //404 Exception + while (tempList.Any()) { - return -1; + pidList.AddRange(tempList); + startPage++; + tempList = List(limit, startPage); } - return pidList.Count(); + + return pidList; } public void Delete(string suffix) { - EpicRequestWrapper(() => restClient.HttpText("DELETE", new Uri(ServiceEndpoint + suffix), null, null, User, Password)); + var result = EpicRequestWrapper(() => _httpClient.DeleteAsync(ServiceEndpoint + suffix)); } public IEnumerable<EpicData> Get(string suffix) { try { - return EpicRequestWrapper(() => restClient.HttpGetJson<List<EpicData>>(new Uri(ServiceEndpoint + suffix), null, User, Password)); + var pidList = new List<EpicData>(); + var result = EpicRequestWrapper(() => _httpClient.GetAsync(ServiceEndpoint + suffix)); + if (result.IsSuccessStatusCode) + { + var content = result.Content.ReadAsStringAsync().Result; + return JsonConvert.DeserializeObject<List<EpicData>>(content); + } + return pidList; } catch (WebException e) { @@ -188,7 +172,7 @@ namespace Coscine.ProxyApi.Utils } // Wrapper for requests to the Epic server since sometimes it gives a 500, however the request was valid - public T EpicRequestWrapper<T>(Func<T> request) + public static HttpResponseMessage EpicRequestWrapper(Func<Task<HttpResponseMessage>> request) { var count = 0; var maxCount = 10; @@ -197,7 +181,8 @@ namespace Coscine.ProxyApi.Utils { try { - return request(); + var requestTask = request(); + return requestTask.Result; } catch (Exception e) { diff --git a/src/ProxyApi/Utils/EpicData.cs b/src/ProxyApi/Utils/EpicData.cs index 58363f5c1558f940bed335f685af4f6638638036..70d88d0f48c87acb8b82db30b9c38c7b6ff9e925 100644 --- a/src/ProxyApi/Utils/EpicData.cs +++ b/src/ProxyApi/Utils/EpicData.cs @@ -1,9 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Collections.Generic; using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/Exceptions/ApiRequestException.cs b/src/ProxyApi/Utils/Exceptions/ApiRequestException.cs index 8ce6430102b0dcddea23bc5773858251485efd83..e2c712fdcb3329659d0b5bea238d27751d88a033 100644 --- a/src/ProxyApi/Utils/Exceptions/ApiRequestException.cs +++ b/src/ProxyApi/Utils/Exceptions/ApiRequestException.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Coscine.ProxyApi.Utils.Exceptions +namespace Coscine.ProxyApi.Utils.Exceptions { public class ApiRequestException : CustomException { diff --git a/src/ProxyApi/Utils/Exceptions/CustomException.cs b/src/ProxyApi/Utils/Exceptions/CustomException.cs index b0e55249b3f5d9a458d190be6b6df8de9e074482..8fed7666edd71212d3ea06dc067e554736fdecb7 100644 --- a/src/ProxyApi/Utils/Exceptions/CustomException.cs +++ b/src/ProxyApi/Utils/Exceptions/CustomException.cs @@ -1,8 +1,4 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Coscine.ProxyApi.Utils.Exceptions { diff --git a/src/ProxyApi/Utils/IEpicClient.cs b/src/ProxyApi/Utils/IEpicClient.cs index 0e247157fe928c184759c60c2083125608f90a26..ff5275cb06c292e76a3df6705151967d472e0704 100644 --- a/src/ProxyApi/Utils/IEpicClient.cs +++ b/src/ProxyApi/Utils/IEpicClient.cs @@ -1,15 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Collections.Generic; namespace Coscine.ProxyApi.Utils { public interface IEpicClient { string Prefix { get; } - int CountForKpis(int lastPage, int last, int limit); EpicData Create(List<EpicData> payload, string guid = null); void Delete(string suffix); IEnumerable<EpicData> Get(string suffix); diff --git a/src/ProxyApi/Utils/IJson.cs b/src/ProxyApi/Utils/IJson.cs index ff012c5f459ff7813a95305201f9301908667831..8e238798a5361323f921fb1fc48415d729df4df8 100644 --- a/src/ProxyApi/Utils/IJson.cs +++ b/src/ProxyApi/Utils/IJson.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/IRestClient.cs b/src/ProxyApi/Utils/IRestClient.cs index 12a7d5c557845ecbc9c42d257d10e49585f8779b..ad70df6332dd3e84e7c8c4a49f2448d7315353b7 100644 --- a/src/ProxyApi/Utils/IRestClient.cs +++ b/src/ProxyApi/Utils/IRestClient.cs @@ -1,9 +1,6 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using System.Xml.Linq; #region DupFinder Exclusion diff --git a/src/ProxyApi/Utils/IWebRequest.cs b/src/ProxyApi/Utils/IWebRequest.cs index ac34c0212a06438f5c70d73a8f5e62cd2665cf20..3af32f15a0c9cc04fb73d60a6a8c8aeca12fd73a 100644 --- a/src/ProxyApi/Utils/IWebRequest.cs +++ b/src/ProxyApi/Utils/IWebRequest.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; +using System.Net; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/Json.cs b/src/ProxyApi/Utils/Json.cs index 0f926c1a10aed954d490a931fe614993b930c893..ed900b52699e972832d6e164bc9004f53567ad9c 100644 --- a/src/ProxyApi/Utils/Json.cs +++ b/src/ProxyApi/Utils/Json.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.IO; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/MockupWebRequest.cs b/src/ProxyApi/Utils/MockupWebRequest.cs index 9223491ef904e03d99d602d23c768e19b51c528a..1fbc76adbe8e7e9c4d134c2867045be1fa4d1960 100644 --- a/src/ProxyApi/Utils/MockupWebRequest.cs +++ b/src/ProxyApi/Utils/MockupWebRequest.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; +using System.Net; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/OAuth2Client.cs b/src/ProxyApi/Utils/OAuth2Client.cs index de86fe67116afd1eb27f1f703c8fa9740b1205c2..b91f644447b56f3f0d2187634fe52f4769078c32 100644 --- a/src/ProxyApi/Utils/OAuth2Client.cs +++ b/src/ProxyApi/Utils/OAuth2Client.cs @@ -1,10 +1,6 @@ -using System; +using Newtonsoft.Json; +using System; using System.Collections.Generic; -using System.Configuration; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; namespace Coscine.ProxyApi.Utils { diff --git a/src/ProxyApi/Utils/RestClient.cs b/src/ProxyApi/Utils/RestClient.cs index 3479f5ad7fa16390ce102c49a36cf150ac408dd7..268931be79104c4f2c6f1cfc459e00d0bf8381b9 100644 --- a/src/ProxyApi/Utils/RestClient.cs +++ b/src/ProxyApi/Utils/RestClient.cs @@ -1,10 +1,7 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; -using System.Text; -using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; using System.Xml.Serialization; @@ -176,15 +173,14 @@ namespace Coscine.ProxyApi.Utils public MemoryStream HttpRaw(string method, Uri endpoint, string query, string body = null, string user = null, string password = null) { - using (var response = HttpRequest(endpoint, query, method, body, user, password)) - using (Stream responseStream = response.GetResponseStream()) - { - var stream = new MemoryStream(); - responseStream.CopyTo(stream); - stream.Flush(); - stream.Position = 0; - return stream; - } + using var response = HttpRequest(endpoint, query, method, body, user, password); + + using Stream responseStream = response.GetResponseStream(); + var stream = new MemoryStream(); + responseStream.CopyTo(stream); + stream.Flush(); + stream.Position = 0; + return stream; } public string HttpText(string method, Uri endpoint, string query, string body = null, string user = null, string password = null, string contentType = "application/json; charset=utf8", string accept = "application/json, */*", string userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64)", Dictionary<string, string> headers = null) diff --git a/src/ProxyApi/Utils/ServiceObject.cs b/src/ProxyApi/Utils/ServiceObject.cs index 628fac82a599547f088d3ad4be111ff8ad5caa4a..157743437d30eeb5e3623975308a3b63f2427ec2 100644 --- a/src/ProxyApi/Utils/ServiceObject.cs +++ b/src/ProxyApi/Utils/ServiceObject.cs @@ -1,9 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.Serialization; -using System.Text; -using System.Threading.Tasks; +using System.Runtime.Serialization; namespace Coscine.ProxyApi.Utils {