Creating Repositories - abstraction + implementation which use HttpClient and call the endpoints. Registering the Repositories in repositories' composition
This commit is contained in:
@@ -47,6 +47,8 @@ namespace Umbraco.Core.Composing.CompositionExtensions
|
||||
composition.RegisterUnique<IScriptRepository, ScriptRepository>();
|
||||
composition.RegisterUnique<IStylesheetRepository, StylesheetRepository>();
|
||||
composition.RegisterUnique<IContentTypeCommonRepository, ContentTypeCommonRepository>();
|
||||
composition.RegisterUnique<IInstallationRepository, InstallationRepository>();
|
||||
composition.RegisterUnique<IUpgradeCheckRepository, UpgradeCheckRepository>();
|
||||
|
||||
return composition;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IInstallationRepository
|
||||
{
|
||||
Task SaveInstall(InstallLog installLog);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
using System.Threading.Tasks;
|
||||
using Semver;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories
|
||||
{
|
||||
public interface IUpgradeCheckRepository
|
||||
{
|
||||
Task<UpgradeResult> CheckUpgrade(SemVersion version);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class InstallationRepository : IInstallationRepository
|
||||
{
|
||||
private static HttpClient _httpClient;
|
||||
private const string RestApiInstallUrl = "https://our.umbraco.com/umbraco/api/Installation/Install";
|
||||
|
||||
|
||||
public async Task SaveInstall(InstallLog installLog)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_httpClient == null)
|
||||
_httpClient = new HttpClient();
|
||||
|
||||
var jsonObj = JsonConvert.SerializeObject(installLog);
|
||||
var content = new StringContent(jsonObj, Encoding.UTF8, "application/json");
|
||||
await _httpClient.PostAsync(RestApiInstallUrl, content);
|
||||
}
|
||||
// this occurs if the server for Our is down or cannot be reached
|
||||
catch (HttpRequestException)
|
||||
{ }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Semver;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class UpgradeCheckRepository : IUpgradeCheckRepository
|
||||
{
|
||||
private static HttpClient _httpClient;
|
||||
private const string RestApiUpgradeChecklUrl = "https://our.umbraco.com/umbraco/api/UpgradeCheck/CheckUpgrade";
|
||||
|
||||
|
||||
public async Task<UpgradeResult> CheckUpgrade(SemVersion version)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (_httpClient == null)
|
||||
_httpClient = new HttpClient();
|
||||
|
||||
var jsonObj = new { VersionMajor = version.Major, VersionMinor = version.Minor, VersionPatch = version.Patch, VersionComment = version.Prerelease };
|
||||
var json = JsonConvert.SerializeObject(jsonObj);
|
||||
var content = new StringContent(json, Encoding.UTF8, "application/json");
|
||||
|
||||
var task = await _httpClient.PostAsync(RestApiUpgradeChecklUrl, content);
|
||||
var jsonResponse = await task.Content.ReadAsStringAsync();
|
||||
var result = JsonConvert.DeserializeObject<UpgradeResult>(jsonResponse);
|
||||
|
||||
return result ?? new UpgradeResult("None", "", "");
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
// this occurs if the server for Our is down or cannot be reached
|
||||
return new UpgradeResult("None", "", "");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -131,12 +131,21 @@
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\ContentTypeDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyDataDto80.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_0_0\Models\PropertyTypeDto80.cs" />
|
||||
<Compile Include="Models\InstallLog.cs" />
|
||||
<Compile Include="Persistence\Repositories\IInstallationRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\InstallationRepository.cs" />
|
||||
<Compile Include="Services\Implement\InstallationService.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_6_0\AddMainDomLock.cs" />
|
||||
<Compile Include="Models\UpgradeResult.cs" />
|
||||
<Compile Include="Persistence\Repositories\Implement\UpgradeCheckRepository.cs" />
|
||||
<Compile Include="Persistence\Repositories\IUpgradeCheckRepository.cs" />
|
||||
<Compile Include="Runtime\IMainDomLock.cs" />
|
||||
<Compile Include="Runtime\MainDomSemaphoreLock.cs" />
|
||||
<Compile Include="Runtime\SqlMainDomLock.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_6_0\MissingContentVersionsIndexes.cs" />
|
||||
<Compile Include="Migrations\Upgrade\V_8_7_0\MissingDictionaryIndex.cs" />
|
||||
<Compile Include="Services\IInstallationService.cs" />
|
||||
<Compile Include="Services\IUpgradeService.cs" />
|
||||
<Compile Include="SystemLock.cs" />
|
||||
<Compile Include="Attempt.cs" />
|
||||
<Compile Include="AttemptOfTResult.cs" />
|
||||
@@ -1552,6 +1561,7 @@
|
||||
<Compile Include="UdiType.cs" />
|
||||
<Compile Include="UdiTypeConverter.cs" />
|
||||
<Compile Include="UpgradeableReadLock.cs" />
|
||||
<Compile Include="UpgradeService.cs" />
|
||||
<Compile Include="UriExtensions.cs" />
|
||||
<Compile Include="VersionExtensions.cs" />
|
||||
<Compile Include="WaitHandleExtensions.cs" />
|
||||
|
||||
Reference in New Issue
Block a user