refactor: rename ScadaLink → ZB.MOM.WW.ScadaBridge (code + projects + namespaces)
Solution + 23 src projects + 26 test projects renamed; folders, csproj, namespaces, and ScadaLinkDbContext/ScadaBridgeDbContext class updated. ActorSystem "scadalink" → "scadabridge", Akka seed-node URLs migrated. SQL roles/logins, LDAP domains, CLI command name, and CLI config dir (~/.scadalink → ~/.scadabridge) also renamed. Build green; 5 Host.Tests fail awaiting SQL login rename in next commit. Pre-existing StaleTagMonitor timing flakes unchanged. Rename script committed at tools/rename-to-scadabridge.sh.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||||
|
||||
namespace ZB.MOM.WW.ScadaBridge.DeploymentManager;
|
||||
|
||||
/// <summary>
|
||||
/// WP-4: State transition matrix for instance lifecycle.
|
||||
///
|
||||
/// State | Deploy | Disable | Enable | Delete
|
||||
/// ----------|--------|---------|--------|-------
|
||||
/// NotDeploy | OK | NO | NO | OK
|
||||
/// Enabled | OK | OK | NO | OK
|
||||
/// Disabled | OK* | NO | OK | OK
|
||||
///
|
||||
/// * Deploy on a Disabled instance also enables it.
|
||||
/// Delete removes the instance record entirely; it is valid from any state.
|
||||
/// </summary>
|
||||
public static class StateTransitionValidator
|
||||
{
|
||||
/// <summary>Returns true when a deploy operation is allowed from the given state.</summary>
|
||||
/// <param name="currentState">The current instance state.</param>
|
||||
public static bool CanDeploy(InstanceState currentState) =>
|
||||
currentState is InstanceState.NotDeployed or InstanceState.Enabled or InstanceState.Disabled;
|
||||
|
||||
/// <summary>Returns true when a disable operation is allowed from the given state.</summary>
|
||||
/// <param name="currentState">The current instance state.</param>
|
||||
public static bool CanDisable(InstanceState currentState) =>
|
||||
currentState == InstanceState.Enabled;
|
||||
|
||||
/// <summary>Returns true when an enable operation is allowed from the given state.</summary>
|
||||
/// <param name="currentState">The current instance state.</param>
|
||||
public static bool CanEnable(InstanceState currentState) =>
|
||||
currentState == InstanceState.Disabled;
|
||||
|
||||
/// <summary>Returns true when a delete operation is allowed from the given state.</summary>
|
||||
/// <param name="currentState">The current instance state.</param>
|
||||
public static bool CanDelete(InstanceState currentState) =>
|
||||
currentState is InstanceState.NotDeployed or InstanceState.Enabled or InstanceState.Disabled;
|
||||
|
||||
/// <summary>
|
||||
/// Returns a human-readable error message if the transition is invalid, or null if valid.
|
||||
/// </summary>
|
||||
/// <param name="currentState">The current instance state.</param>
|
||||
/// <param name="operation">The operation name to validate (e.g. "deploy", "disable", "enable", "delete").</param>
|
||||
public static string? ValidateTransition(InstanceState currentState, string operation)
|
||||
{
|
||||
var allowed = operation.ToLowerInvariant() switch
|
||||
{
|
||||
"deploy" => CanDeploy(currentState),
|
||||
"disable" => CanDisable(currentState),
|
||||
"enable" => CanEnable(currentState),
|
||||
"delete" => CanDelete(currentState),
|
||||
_ => false
|
||||
};
|
||||
|
||||
if (allowed) return null;
|
||||
|
||||
return $"Operation '{operation}' is not allowed when instance is in state '{currentState}'.";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user