forked from Jumoo/Our.Umbraco.MaintenanceMode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Jumoo#44 from craigagnew/v10-load-balanced
V10 load balanced
- Loading branch information
Showing
29 changed files
with
514 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.Configurations | ||
{ | ||
public enum StorageMode | ||
{ | ||
FileSystem = 0, | ||
Database = 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
Our.Umbraco.MaintenanceMode/Factories/IStorageProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using Our.Umbraco.MaintenanceMode.Configurations; | ||
using Our.Umbraco.MaintenanceMode.Providers; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.Factories | ||
{ | ||
public interface IStorageProviderFactory | ||
{ | ||
StorageMode StorageMode { get; } | ||
IStorageProvider GetProvider(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
Our.Umbraco.MaintenanceMode/Factories/StorageProviderFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using Microsoft.Extensions.Options; | ||
using Our.Umbraco.MaintenanceMode.Configurations; | ||
using Our.Umbraco.MaintenanceMode.Providers; | ||
using Umbraco.Cms.Core.Sync; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.Factories | ||
{ | ||
public class StorageProviderFactory : IStorageProviderFactory | ||
{ | ||
private readonly Configurations.MaintenanceModeSettings _maintenanceModeSettings; | ||
private readonly IServiceProvider _serviceProvider; | ||
private readonly IServerRoleAccessor _serverRoleAccessor; | ||
|
||
public StorageProviderFactory( | ||
IOptions<Configurations.MaintenanceModeSettings> maintenanceModeSettings, | ||
IServiceProvider serviceProvider, | ||
IServerRoleAccessor serverRoleAccessor) | ||
{ | ||
_maintenanceModeSettings = maintenanceModeSettings.Value; | ||
_serviceProvider = serviceProvider; | ||
_serverRoleAccessor = serverRoleAccessor; | ||
} | ||
|
||
//public StorageMode StorageMode => this._maintenanceModeSettings?.StorageMode ?? StorageMode.FileSystem; | ||
public StorageMode StorageMode | ||
{ | ||
get | ||
{ | ||
return _maintenanceModeSettings?.StorageMode ?? _serverRoleAccessor.CurrentServerRole switch | ||
{ | ||
// check server role to see if umbraco thinks it's load balanced | ||
ServerRole.Subscriber or ServerRole.SchedulingPublisher => StorageMode.Database, | ||
_ => StorageMode.FileSystem, | ||
}; | ||
} | ||
} | ||
|
||
public IStorageProvider GetProvider() => StorageMode switch | ||
{ | ||
StorageMode.Database => (IStorageProvider)_serviceProvider.GetService(typeof(DatabaseStorageProvider)), | ||
_ => (IStorageProvider)_serviceProvider.GetService(typeof(FileSystemStorageProvider)) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
Our.Umbraco.MaintenanceMode/Migrations/InitialMigration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using Microsoft.Extensions.Options; | ||
using Our.Umbraco.MaintenanceMode.Configurations; | ||
using Our.Umbraco.MaintenanceMode.Models.Schema; | ||
using Umbraco.Cms.Infrastructure.Migrations; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.Migrations | ||
{ | ||
public sealed class InitialMigration : MigrationBase | ||
{ | ||
public const string Key = "maintenance-mode-init"; | ||
|
||
private readonly MaintenanceModeSettings _maintenanceModeSettings; | ||
|
||
public InitialMigration( | ||
IMigrationContext context, | ||
IOptions<MaintenanceModeSettings> maintenanceModeSettings | ||
) : base(context) | ||
{ | ||
} | ||
|
||
protected override void Migrate() | ||
{ | ||
if (!TableExists(nameof(MaintenanceModeSchema))) | ||
{ | ||
Create.Table<MaintenanceModeSchema>().Do(); | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Our.Umbraco.MaintenanceMode/Models/Schema/MaintenanceModeSchema.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
using System; | ||
using System.ComponentModel.DataAnnotations; | ||
using NPoco; | ||
using Umbraco.Cms.Infrastructure.Persistence.DatabaseAnnotations; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.Models.Schema | ||
{ | ||
[TableName(TableName)] | ||
[PrimaryKey(nameof(Id), AutoIncrement = false)] | ||
[ExplicitColumns] | ||
public class MaintenanceModeSchema | ||
{ | ||
public const string TableName = "MaintenanceModeConfig"; | ||
|
||
[Column(nameof(Id))] | ||
[PrimaryKeyColumn(AutoIncrement = false)] | ||
public int Id { get; set; } | ||
|
||
[Column(nameof(Value))] | ||
[SpecialDbType(SpecialDbTypes.NTEXT)] | ||
public string Value { get; set; } | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...aco.MaintenanceMode/NotificationHandlers/Application/UmbracoApplicationStartingHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using Umbraco.Cms.Core.Events; | ||
using Umbraco.Cms.Core.Migrations; | ||
using Umbraco.Cms.Core.Notifications; | ||
using Umbraco.Cms.Core.Services; | ||
using Umbraco.Cms.Core; | ||
using Umbraco.Cms.Infrastructure.Migrations.Upgrade; | ||
using Umbraco.Cms.Infrastructure.Migrations; | ||
using Our.Umbraco.MaintenanceMode.Migrations; | ||
using Umbraco.Cms.Infrastructure.Scoping; | ||
|
||
namespace Our.Umbraco.MaintenanceMode.NotificationHandlers.Application | ||
{ | ||
public class UmbracoApplicationStartingHandler : INotificationHandler<UmbracoApplicationStartingNotification> | ||
{ | ||
private readonly IScopeProvider _scopeProvider; | ||
private readonly IMigrationPlanExecutor _migrationPlanExecutor; | ||
private readonly IKeyValueService _keyValueService; | ||
private readonly IRuntimeState _runtimeState; | ||
|
||
public UmbracoApplicationStartingHandler(IScopeProvider scopeProvider, | ||
IMigrationPlanExecutor migrationPlanExecutor, | ||
IKeyValueService keyValueService, | ||
IRuntimeState runtimeState) | ||
{ | ||
_scopeProvider = scopeProvider; | ||
_migrationPlanExecutor = migrationPlanExecutor; | ||
_keyValueService = keyValueService; | ||
_runtimeState = runtimeState; | ||
} | ||
|
||
public void Handle(UmbracoApplicationStartingNotification notification) | ||
{ | ||
if (_runtimeState.Level < RuntimeLevel.Run) return; | ||
|
||
var plan = new MigrationPlan(MaintenanceMode.PackageAlias); | ||
|
||
plan.From(string.Empty) | ||
.To<InitialMigration>(InitialMigration.Key); | ||
|
||
var upgrader = new Upgrader(plan); | ||
|
||
upgrader.Execute(_migrationPlanExecutor, _scopeProvider, _keyValueService); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.