From 79ee20a45bcb39fb92036b68efcc30ed36d5ef91 Mon Sep 17 00:00:00 2001 From: Bjarke Berg Date: Thu, 20 Feb 2020 08:33:28 +0100 Subject: [PATCH] Post merge - Move files into correct locations --- .../Repositories/InstallationRepository.cs | 14 +++++++++++--- .../Repositories/UpgradeCheckRepository.cs | 17 +++++++++++++---- .../Services}/IUpgradeService.cs | 0 .../{ => Services}/UpgradeService.cs | 2 +- .../Editors/UpdateCheckController.cs | 11 +++-------- .../HttpContextAccessorExtensions.cs | 4 ++-- src/Umbraco.Web/Umbraco.Web.csproj | 12 ------------ 7 files changed, 30 insertions(+), 30 deletions(-) rename src/{Umbraco.Infrastructure/Services/Implement => Umbraco.Abstractions/Services}/IUpgradeService.cs (100%) rename src/Umbraco.Abstractions/{ => Services}/UpgradeService.cs (91%) diff --git a/src/Umbraco.Abstractions/Persistence/Repositories/InstallationRepository.cs b/src/Umbraco.Abstractions/Persistence/Repositories/InstallationRepository.cs index 49fbfe096b..01c91fe051 100644 --- a/src/Umbraco.Abstractions/Persistence/Repositories/InstallationRepository.cs +++ b/src/Umbraco.Abstractions/Persistence/Repositories/InstallationRepository.cs @@ -1,15 +1,21 @@ using System.Net.Http; -using System.Net.Http.Formatting; +using System.Text; using System.Threading.Tasks; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; namespace Umbraco.Core.Persistence.Repositories.Implement { - internal class InstallationRepository : IInstallationRepository + public class InstallationRepository : IInstallationRepository { + private readonly IJsonSerializer _jsonSerializer; private static HttpClient _httpClient; private const string RestApiInstallUrl = "https://our.umbraco.com/umbraco/api/Installation/Install"; + public InstallationRepository(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } public async Task SaveInstallLogAsync(InstallLog installLog) { @@ -18,7 +24,9 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (_httpClient == null) _httpClient = new HttpClient(); - await _httpClient.PostAsync(RestApiInstallUrl, installLog, new JsonMediaTypeFormatter()); + var content = new StringContent(_jsonSerializer.Serialize(installLog), Encoding.UTF8, "application/json"); + + await _httpClient.PostAsync(RestApiInstallUrl, content); } // this occurs if the server for Our is down or cannot be reached catch (HttpRequestException) diff --git a/src/Umbraco.Abstractions/Persistence/Repositories/UpgradeCheckRepository.cs b/src/Umbraco.Abstractions/Persistence/Repositories/UpgradeCheckRepository.cs index 365e8ba481..b20c6d26b9 100644 --- a/src/Umbraco.Abstractions/Persistence/Repositories/UpgradeCheckRepository.cs +++ b/src/Umbraco.Abstractions/Persistence/Repositories/UpgradeCheckRepository.cs @@ -1,16 +1,22 @@ using System.Net.Http; -using System.Net.Http.Formatting; +using System.Text; using System.Threading.Tasks; using Semver; using Umbraco.Core.Models; +using Umbraco.Core.Serialization; namespace Umbraco.Core.Persistence.Repositories.Implement { - internal class UpgradeCheckRepository : IUpgradeCheckRepository + public class UpgradeCheckRepository : IUpgradeCheckRepository { + private readonly IJsonSerializer _jsonSerializer; private static HttpClient _httpClient; private const string RestApiUpgradeChecklUrl = "https://our.umbraco.com/umbraco/api/UpgradeCheck/CheckUpgrade"; + public UpgradeCheckRepository(IJsonSerializer jsonSerializer) + { + _jsonSerializer = jsonSerializer; + } public async Task CheckUpgradeAsync(SemVersion version) { @@ -19,8 +25,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement if (_httpClient == null) _httpClient = new HttpClient(); - var task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, new CheckUpgradeDto(version), new JsonMediaTypeFormatter()); - var result = await task.Content.ReadAsAsync(); + var content = new StringContent(_jsonSerializer.Serialize(new CheckUpgradeDto(version)), Encoding.UTF8, "application/json"); + + var task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl,content); + var json = await task.Content.ReadAsStringAsync(); + var result = _jsonSerializer.Deserialize(json); return result ?? new UpgradeResult("None", "", ""); } diff --git a/src/Umbraco.Infrastructure/Services/Implement/IUpgradeService.cs b/src/Umbraco.Abstractions/Services/IUpgradeService.cs similarity index 100% rename from src/Umbraco.Infrastructure/Services/Implement/IUpgradeService.cs rename to src/Umbraco.Abstractions/Services/IUpgradeService.cs diff --git a/src/Umbraco.Abstractions/UpgradeService.cs b/src/Umbraco.Abstractions/Services/UpgradeService.cs similarity index 91% rename from src/Umbraco.Abstractions/UpgradeService.cs rename to src/Umbraco.Abstractions/Services/UpgradeService.cs index 8116c0e738..ead5270b41 100644 --- a/src/Umbraco.Abstractions/UpgradeService.cs +++ b/src/Umbraco.Abstractions/Services/UpgradeService.cs @@ -6,7 +6,7 @@ using Umbraco.Core.Services; namespace Umbraco.Core { - internal class UpgradeService : IUpgradeService + public class UpgradeService : IUpgradeService { private readonly IUpgradeCheckRepository _upgradeCheckRepository; diff --git a/src/Umbraco.Web/Editors/UpdateCheckController.cs b/src/Umbraco.Web/Editors/UpdateCheckController.cs index d422a49825..8518938a32 100644 --- a/src/Umbraco.Web/Editors/UpdateCheckController.cs +++ b/src/Umbraco.Web/Editors/UpdateCheckController.cs @@ -42,16 +42,11 @@ namespace Umbraco.Web.Editors _umbracoVersion.Current.Build, _umbracoVersion.Comment); var result = await _upgradeService.CheckUpgrade(version); - return new UpgradeCheckResponse(result.UpgradeType, result.Comment, result.UpgradeUrl); + return new UpgradeCheckResponse(result.UpgradeType, result.Comment, result.UpgradeUrl, _umbracoVersion); } - catch (System.Net.WebException) + catch { - //this occurs if the server is down or cannot be reached - return null; - } - catch (System.Web.Services.Protocols.SoapException) - { - //this occurs if the server has a timeout + //We don't want to crash due to this return null; } } diff --git a/src/Umbraco.Web/HttpContextAccessorExtensions.cs b/src/Umbraco.Web/HttpContextAccessorExtensions.cs index 4c2dcf0a0d..2076510ce0 100644 --- a/src/Umbraco.Web/HttpContextAccessorExtensions.cs +++ b/src/Umbraco.Web/HttpContextAccessorExtensions.cs @@ -1,4 +1,4 @@ -using System.IO; +using System; using System.Web; namespace Umbraco.Web @@ -9,7 +9,7 @@ namespace Umbraco.Web { var httpContext = httpContextAccessor.HttpContext; - if(httpContext is null) throw new IOException("HttpContext is null"); + if(httpContext is null) throw new InvalidOperationException("HttpContext is null"); return httpContext; } diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index de01bdb2fc..c73ccb5b3d 100755 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -647,13 +647,6 @@ - - True - True - Reference.map - - - Component @@ -685,11 +678,6 @@ Mvc\web.config - - Reference.map - - - Reference.map SettingsSingleFileGenerator Settings.Designer.cs