Class ScoreRuntime
Mutable in-memory state for score metrics during a session or run. Manages N metrics addressed by ScoreKey.
Inherited Members
Namespace: Serenity.Score.Domain.Entities
Assembly: Serenity.Score.Domain.dll
Syntax
public class ScoreRuntime
Constructors
ScoreRuntime()
Declaration
public ScoreRuntime()
Properties
Count
Gets the number of registered metrics.
Declaration
public int Count { get; }
Property Value
| Type | Description |
|---|---|
| int |
Methods
Add(ScoreKey, float)
Adds a delta to the specified metric.
Declaration
public void Add(ScoreKey key, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | delta | The amount to add. |
Divide(ScoreKey, float)
Divides the specified metric by a divisor.
Declaration
public void Divide(ScoreKey key, float divisor)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | divisor | The divisor. Must not be zero. |
Multiply(ScoreKey, float)
Multiplies the specified metric by a factor.
Declaration
public void Multiply(ScoreKey key, float factor)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | factor | The multiplication factor. |
Register(ScoreKey, ScoreValue)
Registers a metric with an initial value. Overwrites if key already exists.
Declaration
public void Register(ScoreKey key, ScoreValue initialValue)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| ScoreValue | initialValue | The initial score value. |
Reset(ScoreKey)
Resets the specified metric to zero.
Declaration
public void Reset(ScoreKey key)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
ResetAll()
Resets all registered metrics to zero.
Declaration
public void ResetAll()
Set(ScoreKey, float)
Sets the specified metric to an exact value.
Declaration
public void Set(ScoreKey key, float amount)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | amount | The new amount. |
Subtract(ScoreKey, float)
Subtracts a delta from the specified metric.
Declaration
public void Subtract(ScoreKey key, float delta)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| float | delta | The amount to subtract. |
ToSnapshot()
Creates an immutable snapshot of the current metric state.
Declaration
public ScoreSnapshot ToSnapshot()
Returns
| Type | Description |
|---|---|
| ScoreSnapshot | A read-only snapshot of all current metrics. |
TryGet(ScoreKey, out ScoreValue)
Gets the current value of a metric.
Declaration
public bool TryGet(ScoreKey key, out ScoreValue value)
Parameters
| Type | Name | Description |
|---|---|---|
| ScoreKey | key | The metric key. |
| ScoreValue | value | The current score value, if found. |
Returns
| Type | Description |
|---|---|
| bool | True if the metric exists; otherwise false. |