Initial import of the CBDDC codebase with docs and tests. Add a .NET-focused gitignore to keep generated artifacts out of source control.
Some checks failed
CI / verify (push) Has been cancelled
Some checks failed
CI / verify (push) Has been cancelled
This commit is contained in:
59
src/ZB.MOM.WW.CBDDC.Core/Network/StaticPeerNodeConfigurationProvider.cs
Executable file
59
src/ZB.MOM.WW.CBDDC.Core/Network/StaticPeerNodeConfigurationProvider.cs
Executable file
@@ -0,0 +1,59 @@
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ZB.MOM.WW.CBDDC.Core.Network;
|
||||
|
||||
/// <summary>
|
||||
/// Provides peer node configuration from an in-memory static source.
|
||||
/// </summary>
|
||||
public class StaticPeerNodeConfigurationProvider : IPeerNodeConfigurationProvider
|
||||
{
|
||||
private PeerNodeConfiguration _configuration = new();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the current peer node configuration.
|
||||
/// </summary>
|
||||
public PeerNodeConfiguration Configuration
|
||||
{
|
||||
get => _configuration;
|
||||
set
|
||||
{
|
||||
if (_configuration != value)
|
||||
{
|
||||
_configuration = value;
|
||||
OnConfigurationChanged(_configuration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="StaticPeerNodeConfigurationProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="configuration">The initial peer node configuration.</param>
|
||||
public StaticPeerNodeConfigurationProvider(PeerNodeConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the peer node configuration changes.
|
||||
/// </summary>
|
||||
public event PeerNodeConfigurationChangedEventHandler? ConfigurationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the current peer node configuration.
|
||||
/// </summary>
|
||||
/// <returns>A task whose result is the current configuration.</returns>
|
||||
public Task<PeerNodeConfiguration> GetConfiguration()
|
||||
{
|
||||
return Task.FromResult(Configuration);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raises the <see cref="ConfigurationChanged"/> event.
|
||||
/// </summary>
|
||||
/// <param name="newConfig">The new peer node configuration.</param>
|
||||
protected virtual void OnConfigurationChanged(PeerNodeConfiguration newConfig)
|
||||
{
|
||||
ConfigurationChanged?.Invoke(this, newConfig);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user