mirror of https://github.com/Squidex/squidex.git
4 changed files with 63 additions and 230 deletions
@ -1,47 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using Microsoft.Extensions.FileProviders; |
|
||||
using Microsoft.Extensions.Hosting; |
|
||||
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment; |
|
||||
|
|
||||
namespace Squidex.Config.Orleans |
|
||||
{ |
|
||||
public sealed class EnvironmentWrapper : IHostingEnvironment |
|
||||
{ |
|
||||
private readonly IWebHostEnvironment nested; |
|
||||
|
|
||||
public string EnvironmentName |
|
||||
{ |
|
||||
get => nested.EnvironmentName; |
|
||||
set => nested.EnvironmentName = value; |
|
||||
} |
|
||||
|
|
||||
public string ApplicationName |
|
||||
{ |
|
||||
get => nested.ApplicationName; |
|
||||
set => nested.ApplicationName = value; |
|
||||
} |
|
||||
|
|
||||
public string ContentRootPath |
|
||||
{ |
|
||||
get => nested.ContentRootPath; |
|
||||
set => nested.ContentRootPath = value; |
|
||||
} |
|
||||
|
|
||||
public IFileProvider ContentRootFileProvider |
|
||||
{ |
|
||||
get => nested.ContentRootFileProvider; |
|
||||
set => nested.ContentRootFileProvider = value; |
|
||||
} |
|
||||
|
|
||||
public EnvironmentWrapper(IWebHostEnvironment nested) |
|
||||
{ |
|
||||
this.nested = nested; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,51 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System.Threading; |
|
||||
using System.Threading.Tasks; |
|
||||
using Microsoft.Extensions.Hosting; |
|
||||
using Microsoft.Extensions.Logging; |
|
||||
using Orleans.Hosting; |
|
||||
using Squidex.Config.Startup; |
|
||||
using Squidex.Infrastructure; |
|
||||
using Squidex.Infrastructure.Log; |
|
||||
|
|
||||
namespace Squidex.Config.Orleans |
|
||||
{ |
|
||||
public sealed class SiloHost : SafeHostedService |
|
||||
{ |
|
||||
private readonly ISiloHost silo; |
|
||||
|
|
||||
public SiloHost(ISiloHost silo, ISemanticLog log, IApplicationLifetime lifetime) |
|
||||
: base(lifetime, log) |
|
||||
{ |
|
||||
this.silo = silo; |
|
||||
} |
|
||||
|
|
||||
protected override async Task StartAsync(ISemanticLog log, CancellationToken ct) |
|
||||
{ |
|
||||
var watch = ValueStopwatch.StartNew(); |
|
||||
try |
|
||||
{ |
|
||||
await silo.StartAsync(ct); |
|
||||
} |
|
||||
finally |
|
||||
{ |
|
||||
var elapsedMs = watch.Stop(); |
|
||||
|
|
||||
log.LogInformation(w => w |
|
||||
.WriteProperty("message", "Silo started") |
|
||||
.WriteProperty("elapsedMs", elapsedMs)); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
protected override async Task StopAsync(ISemanticLog log, CancellationToken ct) |
|
||||
{ |
|
||||
await silo.StopAsync(); |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,73 +0,0 @@ |
|||||
// ==========================================================================
|
|
||||
// Squidex Headless CMS
|
|
||||
// ==========================================================================
|
|
||||
// Copyright (c) Squidex UG (haftungsbeschraenkt)
|
|
||||
// All rights reserved. Licensed under the MIT license.
|
|
||||
// ==========================================================================
|
|
||||
|
|
||||
using System; |
|
||||
using System.Collections.Generic; |
|
||||
using Microsoft.Extensions.Configuration; |
|
||||
using Microsoft.Extensions.DependencyInjection; |
|
||||
using Orleans; |
|
||||
using Orleans.Hosting; |
|
||||
using Squidex.Infrastructure; |
|
||||
using HostingBuilderContext = Microsoft.Extensions.Hosting.HostBuilderContext; |
|
||||
using WebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment; |
|
||||
|
|
||||
namespace Squidex.Config.Orleans |
|
||||
{ |
|
||||
public sealed class SiloServiceBuilder : ISiloBuilder |
|
||||
{ |
|
||||
private readonly HostingBuilderContext context = new HostingBuilderContext(new Dictionary<object, object>()); |
|
||||
private readonly List<Action<HostingBuilderContext, ISiloBuilder>> configureSiloDelegates = new List<Action<HostingBuilderContext, ISiloBuilder>>(); |
|
||||
private readonly List<Action<HostingBuilderContext, IServiceCollection>> configureServicesDelegates = new List<Action<HostingBuilderContext, IServiceCollection>>(); |
|
||||
|
|
||||
public IDictionary<object, object> Properties |
|
||||
{ |
|
||||
get { return context.Properties; } |
|
||||
} |
|
||||
|
|
||||
public SiloServiceBuilder(IConfiguration config, WebHostEnvironment environment) |
|
||||
{ |
|
||||
context.Configuration = config; |
|
||||
context.HostingEnvironment = new EnvironmentWrapper(environment); |
|
||||
} |
|
||||
|
|
||||
public void Build(IServiceCollection serviceCollection) |
|
||||
{ |
|
||||
foreach (var configurationDelegate in configureSiloDelegates) |
|
||||
{ |
|
||||
configurationDelegate(context, this); |
|
||||
} |
|
||||
|
|
||||
serviceCollection.AddHostedService<SiloHost>(); |
|
||||
|
|
||||
this.ConfigureDefaults(); |
|
||||
this.ConfigureApplicationParts(parts => parts.ConfigureDefaults()); |
|
||||
|
|
||||
foreach (var configurationDelegate in configureServicesDelegates) |
|
||||
{ |
|
||||
configurationDelegate(context, serviceCollection); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
public ISiloBuilder ConfigureSilo(Action<HostingBuilderContext, ISiloBuilder> configureDelegate) |
|
||||
{ |
|
||||
Guard.NotNull(configureDelegate, nameof(configureDelegate)); |
|
||||
|
|
||||
configureSiloDelegates.Add(configureDelegate); |
|
||||
|
|
||||
return this; |
|
||||
} |
|
||||
|
|
||||
public ISiloBuilder ConfigureServices(Action<HostingBuilderContext, IServiceCollection> configureDelegate) |
|
||||
{ |
|
||||
Guard.NotNull(configureDelegate, nameof(configureDelegate)); |
|
||||
|
|
||||
configureServicesDelegates.Add(configureDelegate); |
|
||||
|
|
||||
return this; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
Loading…
Reference in new issue