-
Notifications
You must be signed in to change notification settings - Fork 328
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 #385 from MUnique/config-hot-reload
🔥 Configuration Hot Reload
- Loading branch information
Showing
265 changed files
with
3,592 additions
and
319 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 @@ | ||
// <copyright file="CloneableAttribute.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.Annotations; | ||
|
||
/// <summary> | ||
/// Classes marked with this attribute will get a generic Clonable-Interface | ||
/// implemented by a code generator. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] | ||
public sealed class CloneableAttribute : Attribute | ||
{ | ||
} |
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,12 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>netstandard2.0</TargetFramework> | ||
<LangVersion>latest</LangVersion> | ||
<Nullable>enable</Nullable> | ||
<WarningsAsErrors>nullable;CS4014;VSTHRD110;VSTHRD100</WarningsAsErrors> | ||
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
|
||
</Project> |
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,10 @@ | ||
// <copyright file="ConfigurationChangeArguments.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.Dapr.Common; | ||
|
||
/// <summary> | ||
/// Arguments for the change notifications of <see cref="ConfigurationChangePublisher"/>. | ||
/// </summary> | ||
public record class ConfigurationChangeArguments(Type Type, Guid Id, object? Configuration); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
// <copyright file="ConfigurationChangeController.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.GameServer.Host; | ||
|
||
using global::Dapr; | ||
using Microsoft.AspNetCore.Mvc; | ||
using MUnique.OpenMU.Dapr.Common; | ||
using MUnique.OpenMU.Interfaces; | ||
using MUnique.OpenMU.Persistence.EntityFramework; | ||
|
||
/// <summary> | ||
/// The API controller which handles the calls of the <see cref="ConfigurationChangePublisher"/> | ||
/// from other services, such as the AdminPanel. | ||
/// It forwards the changes to a <see cref="IConfigurationChangeListener"/>, so | ||
/// that the caches are updated and the game logic can react to that. | ||
/// </summary> | ||
[ApiController] | ||
[Route("")] | ||
public class ConfigurationChangeController : ControllerBase | ||
{ | ||
private readonly IConfigurationChangeListener _changeListener; | ||
|
||
/// <summary> | ||
/// Initializes a new instance of the <see cref="ConfigurationChangeController" /> class. | ||
/// </summary> | ||
/// <param name="changeListener">The change listener.</param> | ||
public ConfigurationChangeController(IConfigurationChangeListener changeListener) | ||
{ | ||
this._changeListener = changeListener; | ||
} | ||
|
||
/// <summary> | ||
/// Called when a configuration got added on the admin panel. | ||
/// </summary> | ||
/// <param name="arguments">The message arguments.</param> | ||
[HttpPost(nameof(IConfigurationChangePublisher.ConfigurationAddedAsync))] | ||
[Topic("pubsub", nameof(IConfigurationChangePublisher.ConfigurationAddedAsync))] | ||
public ValueTask ConfigurationAddedAsync([FromBody] ConfigurationChangeArguments arguments) | ||
{ | ||
return this._changeListener.ConfigurationAddedAsync(arguments.Type, arguments.Id, arguments.Configuration!, null, null); | ||
} | ||
|
||
/// <summary> | ||
/// Called when a configuration got added on the admin panel. | ||
/// </summary> | ||
/// <param name="arguments">The message arguments.</param> | ||
[HttpPost(nameof(IConfigurationChangePublisher.ConfigurationChangedAsync))] | ||
[Topic("pubsub", nameof(IConfigurationChangePublisher.ConfigurationChangedAsync))] | ||
public ValueTask ConfigurationChangedAsync([FromBody] ConfigurationChangeArguments arguments) | ||
{ | ||
return this._changeListener.ConfigurationChangedAsync(arguments.Type, arguments.Id, arguments.Configuration!, null); | ||
} | ||
|
||
/// <summary> | ||
/// Called when a configuration got removed on the admin panel. | ||
/// </summary> | ||
/// <param name="arguments">The message arguments.</param> | ||
[HttpPost(nameof(IConfigurationChangePublisher.ConfigurationRemovedAsync))] | ||
[Topic("pubsub", nameof(IConfigurationChangePublisher.ConfigurationRemovedAsync))] | ||
public ValueTask ConfigurationRemovedAsync([FromBody] ConfigurationChangeArguments arguments) | ||
{ | ||
return this._changeListener.ConfigurationRemovedAsync(arguments.Type, arguments.Id, null, null); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// <copyright file="AssignableExtensions.cs" company="MUnique"> | ||
// Licensed under the MIT License. See LICENSE file in the project root for full license information. | ||
// </copyright> | ||
|
||
namespace MUnique.OpenMU.DataModel; | ||
|
||
using MUnique.OpenMU.DataModel.Configuration; | ||
|
||
/// <summary> | ||
/// Extensions for <see cref="IAssignable{T}"/>. | ||
/// </summary> | ||
public static class AssignableExtensions | ||
{ | ||
/// <summary> | ||
/// Assigns a collection to another one, resolving the objects to the ones | ||
/// which are contained in the given <see cref="GameConfiguration"/>. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the collection elements.</typeparam> | ||
/// <param name="collection">The target collection.</param> | ||
/// <param name="other">The other collection.</param> | ||
/// <param name="gameConfiguration">The game configuration.</param> | ||
public static void AssignCollection<T>(this ICollection<T> collection, ICollection<T> other, GameConfiguration gameConfiguration) | ||
where T : class | ||
{ | ||
var newItems = collection.Except(other).ToList(); | ||
var oldItems = other.Except(collection).ToList(); | ||
|
||
oldItems.ForEach(i => collection.Remove(i)); | ||
newItems.ForEach(i => collection.Add( | ||
gameConfiguration.GetObjectOfConfig(i) | ||
?? (i as ICloneable<T>)?.Clone(gameConfiguration) | ||
?? (i as ICloneable)?.Clone() as T | ||
?? i)); | ||
} | ||
|
||
/// <summary> | ||
/// Assigns a collection to another one. | ||
/// </summary> | ||
/// <typeparam name="T">The type of the collection values.</typeparam> | ||
/// <param name="collection">The target collection.</param> | ||
/// <param name="other">The other collection.</param> | ||
public static void AssignCollection<T>(this ICollection<T> collection, ICollection<T> other) | ||
where T : struct | ||
{ | ||
var newItems = collection.Except(other).ToList(); | ||
var oldItems = other.Except(collection).ToList(); | ||
|
||
oldItems.ForEach(i => collection.Remove(i)); | ||
newItems.ForEach(collection.Add); | ||
} | ||
} |
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.