Class ModelConfigController
High-level controller for ModelConfig persistence and keyed access.
Paths may be file or directory; if a directory is given, the file name modelConfig.json is used.
Dotted keys address JSON nodes, e.g. "calib.mode", "calib.targets.index.threshold".
Inheritance
Namespace: Wss.ModelModule
Assembly: WSS_Core_Interface.dll
Syntax
public sealed class ModelConfigController
Constructors
ModelConfigController(string)
Create or open a model config at path.
If path is a directory, appends modelConfig.json.
Ensures the file exists by saving defaults when first created.
Declaration
public ModelConfigController(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | File path like |
Examples
var mc = new ModelConfigController(@"Configs\"); // uses Configs\modelConfig.json
var mc2 = new ModelConfigController(@"Configs\m.json"); // uses given file directly
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | When |
Methods
GetAllCalibParams()
Return a flat snapshot of scalar values under "calib".
Keys are dotted, e.g., "calib.mode", "calib.targets.index.threshold".
Declaration
public Dictionary<string, string> GetAllCalibParams()
Returns
| Type | Description |
|---|---|
| Dictionary<string, string> | A copy of key/value pairs as strings. |
Examples
var all = mc.GetAllCalibParams();
foreach (var kv in all) Debug.Log($"{kv.Key} = {kv.Value}");
GetCalibMode()
Get the model’s calibration mode from "calib.mode". Throws if missing.
Declaration
public string GetCalibMode()
Returns
| Type | Description |
|---|---|
| string | Calibration mode string, e.g., |
Examples
string mode = mc.GetCalibMode();
GetModelParam<T>(string)
Get a required typed value from a dotted key.
Throws if the key is missing or the value cannot be converted to T.
Declaration
public T GetModelParam<T>(string key)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Dotted key, e.g., |
Returns
| Type | Description |
|---|---|
| T | Value at the key as |
Type Parameters
| Name | Description |
|---|---|
| T | Expected return type. |
Examples
string mode = mc.GetModelParam<string>("calib.mode");
float thr = mc.GetModelParam<float>("calib.targets.index.threshold");
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If |
| KeyNotFoundException | If the key does not exist. |
GetOrDefault<T>(string, T)
Get a typed value or a default when missing. Does not throw on absent keys.
Declaration
public T GetOrDefault<T>(string key, T dflt = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Dotted key, e.g., |
| T | dflt | Fallback value to return when the key is missing. |
Returns
| Type | Description |
|---|---|
| T | Value at the key, or |
Type Parameters
| Name | Description |
|---|---|
| T | Expected return type. |
Examples
int rate = mc.GetOrDefault("calib.sampling.rateHz", 1000);
LoadModelJson()
Reload the current model configuration from its existing path. Reinstantiates the underlying ModelConfig so disk edits are reflected in memory.
Declaration
public void LoadModelJson()
Examples
// external tool edited the JSON on disk:
mc.LoadModelJson(); // refresh memory view
LoadModelJson(string)
Load a model configuration from a new path. If path is a directory,
appends modelConfig.json.
Replaces the active config instance.
Declaration
public void LoadModelJson(string path)
Parameters
| Type | Name | Description |
|---|---|---|
| string | path | File path like |
Examples
mc.LoadModelJson(@"Profiles\UserA\"); // Profiles\UserA\modelConfig.json
mc.LoadModelJson(@"Profiles\AltModel.json"); // specific file
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | When |
SaveModelJson()
Save the current in-memory model configuration to disk. Uses Save(). Call after any Set/Update to persist changes.
Declaration
public void SaveModelJson()
Examples
mc.SetModelParam("calib.mode", "midpoint");
mc.SaveModelJson();
SetCalibMode(string)
Set "calib.mode" and save.
Declaration
public void SetCalibMode(string mode)
Parameters
| Type | Name | Description |
|---|---|---|
| string | mode | Non-empty mode string, e.g., |
Examples
mc.SetCalibMode("midpoint");
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If |
SetModelParam<T>(string, T)
Set a value at the dotted key and immediately save. Use for scalars or small objects that serialize to a JSON value.
Declaration
public void SetModelParam<T>(string key, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Dotted key, e.g., |
| T | value | Value to write. |
Type Parameters
| Name | Description |
|---|---|
| T | Serializable type (e.g., |
Examples
mc.SetModelParam("calib.mode", "midpoint");
mc.SetModelParam("calib.targets.index.threshold", 0.42f);
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If |
TryGetModelParam<T>(string, out T)
Try to get a typed value without throwing.
Declaration
public bool TryGetModelParam<T>(string key, out T value) where T : notnull
Parameters
| Type | Name | Description |
|---|---|---|
| string | key | Dotted key, e.g., |
| T | value | Output value when found and convertible. |
Returns
| Type | Description |
|---|---|
| bool |
|
Type Parameters
| Name | Description |
|---|---|
| T | Expected return type. |
Examples
if (mc.TryGetModelParam("calib.targets.thumb.offset", out float off)) { /* use off */ }
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | If |