Interface SzConfig
Defines the C# interface that encapsulates and represents a Senzing configuration and provides functions to operate on that configuration.
public interface SzConfig
Examples
Create from template configuration:
// How to create an SzConfig instance representing the template configuration
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// create the config from the template
SzConfig config = configMgr.CreateConfig();
// do something with the SzConfig
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to create new SzConfig from the template.", e);
}
Create from configuration definition:
// How to create an SzConfig instance representing a specified config definition
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// obtain a JSON config definition (varies by application)
string configDefinition = ReadConfigFile();
// create the config using the config definition
SzConfig config = configMgr.CreateConfig(configDefinition);
// do something with the SzConfig
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to create a new SzConfig from a definition.", e);
}
Create from registered configuration ID:
// How to get a config definition by its configuration ID
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the config manager
SzConfigManager configMgr = env.GetConfigManager();
// get a valid configuration ID (will vary by application)
long configID = configMgr.GetDefaultConfigID();
// get the config definition for the config ID
SzConfig config = configMgr.CreateConfig(configID);
// do something with the SzConfig
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to Create SzConfig from config ID.", e);
}
Remarks
The Senzing config functions provide means to create, manipulate and export Senzing JSON configurations.
An SzConfig
instance is typically obtained from an
SzConfigManager instance via one of the following methods:
Methods
AddDataSource(string)
Adds a new data source that is identified by the specified data source code to this configuration. An exception is thrown if the data source already exists in the configuration.
string AddDataSource(string dataSourceCode)
Parameters
dataSourceCode
stringThe data source code for the new data source.
Returns
- string
The JSON
string
describing the data source was added to the configuration.
Examples
Usage:
// How to add data sources to an in-memory config
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// get an SzConfig object (varies by application)
SzConfig config = configMgr.CreateConfig();
// add data sources to the config
config.AddDataSource("CUSTOMERS");
config.AddDataSource("EMPLOYEES");
config.AddDataSource("WATCHLIST");
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to add data sources.", e);
}
Exceptions
- SzException
If a failure occurs.
- See Also
DeleteDataSource(string)
Deletes the data source identified by the specified data source code from this configuration.
void DeleteDataSource(string dataSourceCode)
Parameters
dataSourceCode
stringThe data source code that identifies the data source to delete from the configuration.
Examples
Usage:
// How to delete a data source from an in-memory config
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// get an SzConfig object (varies by application)
SzConfig config = configMgr.CreateConfig();
// delete the data source from the config
config.DeleteDataSource("CUSTOMERS");
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to delete data source.", e);
}
Exceptions
- SzException
If a failure occurs.
Export()
Obtains the configuration definition (typically formatted as JSON) for this configuration.
string Export()
Returns
- string
The configuration definition (typically formatted as JSON).
Examples
Usage:
// How to export config JSON from a config handle
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// get an SzConfig object (varies by application)
SzConfig config = configMgr.CreateConfig();
// export the config
String configDefinition = config.Export();
. . .
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to export configuration.", e);
}
Remarks
NOTE: Typically, an implementations ToString()
function
will be implemented to return the result from this function.
Exceptions
- SzException
If a failure occurs.
- See Also
GetDataSources()
Extracts the data sources from this configuration and returns the JSON text describing the data sources from the configuration.
string GetDataSources()
Returns
- string
The JSON
string
describing the data sources found in the configuration.
Examples
Usage:
// How to get the data sources from an in-memory config
try
{
// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();
// get the SzConfigManager instance
SzConfigManager configMgr = env.GetConfigManager();
// get an SzConfig object (varies by application)
SzConfig config = configMgr.CreateConfig();
// get the data sources
String sourcesJson = config.GetDataSources();
// do something with the returned JSON (e.g.: parse it and extract values)
JsonObject? jsonObj = JsonNode.Parse(sourcesJson)?.AsObject();
JsonArray? jsonArr = jsonObj?["DATA_SOURCES"]?.AsArray();
// iterate over the data sources
if (jsonArr != null)
{
for (int index = 0; index < jsonArr.Count; index++)
{
JsonObject? sourceObj = jsonArr[index]?.AsObject();
string? dataSourceCode = sourceObj?["DSRC_CODE"]?.GetValue<string>();
. . .
}
}
}
catch (SzException e)
{
// handle or rethrow the exception
LogError("Failed to get data sources.", e);
}
Remarks
The format of the JSON response is as follows:
{
"DATA_SOURCES": [
{
"DSRC_ID": 1,
"DSRC_CODE": "TEST"
},
{
"DSRC_ID": 2,
"DSRC_CODE": "SEARCH"
}
]
}
Exceptions
- SzException
If a failure occurs.