Table of Contents

Interface SzEnvironment

Namespace
Senzing.Sdk
Assembly
Senzing.Sdk.dll

Provides a factory interface for obtaining the references to the Senzing SDK singleton instances that have been initialized.

public interface SzEnvironment

Examples

Usage:

// get the settings (varies by application)
string settings = GetSettings();

// get the instance name (varies by application)
string instanceName = GetInstanceName();

// construct the environment
SzEnvironment env = SzCoreEnvironment.NewBuilder()
                                     .InstanceName(instanceName)
                                     .Settings(settings)
                                     .VerboseLogging(false)
                                     .Build();

// use the environment for some time (usually as long as the application is running)
. . .

// destroy the environment when done (sometimes in a finally block)
env.Destroy();

Methods

Destroy()

Destroys this SzEnvironment and invalidates any SDK singleton references that has previously provided.

void Destroy()

Examples

Usage:

// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();

// check if already destroyed
if (!env.IsDestroyed())
{
    // destroy the environment
    env.Destroy();
}

Remarks

If this instance has already been destroyed then this method has no effect.

GetActiveConfigID()

Gets the currently active configuration ID for this SzEnvironment.

long GetActiveConfigID()

Returns

long

The currently active configuration ID.

Examples

Usage:

// How to get the active config ID for the SzEnvironment
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    // get the active config ID
    long activeConfigID = env.GetActiveConfigID();

    // do something with the active config ID (varies by application)
    SzConfigManager configMgr = env.GetConfigManager();

    long defaultConfigID = configMgr.GetDefaultConfigID();

    if (activeConfigID != defaultConfigID)
    {
        // reinitialize the environment with the default config ID                    
        env.Reinitialize(defaultConfigID);
    }

}
catch (SzException e)
{
    // handle or rethrow the exception
    LogError("Failed to verify the active config ID.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure in obtaining the active config ID.

GetConfigManager()

Provides a reference to the SzConfigManager instance associated with this SzEnvironment.

SzConfigManager GetConfigManager()

Returns

SzConfigManager

The SzConfigManager instance associated with this SzEnvironment.

Examples

Usage:

// How to obtain an SzConfigManager instance
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    // get the config manager
    SzConfigManager configMgr = env.GetConfigManager();

    . . .

}
catch (SzException e)
{
    // handle or rethrow the exception
    LogError("Failed to get SzConfigManager.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure in obtaining or initializing the SzConfigManager instance.

GetDiagnostic()

Provides a reference to the SzDiagnostic instance associated with this SzEnvironment.

SzDiagnostic GetDiagnostic()

Returns

SzDiagnostic

The SzDiagnostic instance associated with this SzEnvironment.

Examples

Usage:

// How to obtain an SzDiagnostic instance
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    SzDiagnostic diagnostic = env.GetDiagnostic();

    . . .

}
catch (SzException e)
{
    // handle or rethrow the exception
    LogError("Failed to get SzDiagnostic.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure in obtaining or initializing the SzDiagnostic instance.

GetEngine()

Provides a reference to the SzEngine instance associated with this SzEnvironment.

SzEngine GetEngine()

Returns

SzEngine

The SzEngine instance associated with this SzEnvironment.

Examples

Usage:

// How to obtain an SzEngine instance
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    // get the engine
    SzEngine engine = env.GetEngine();

    . . .

}
catch (SzException e)
{
    // handle or rethrow the exception
    LogError("Failed to get SzEngine.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure in obtaining or initializing the SzEngine instance.

GetProduct()

Provides a reference to the SzProduct singleton associated with this SzEnvironment.

SzProduct GetProduct()

Returns

SzProduct

The SzProduct instance associated with this SzEnvironment

Examples

Usage:

// How to obtain an SzProduct instance
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    // get the product from the environment
    SzProduct product = env.GetProduct();

    . . .

}
catch (SzException e)
{
    // handle or rethrow the exception (varies by application)
    LogError("Failed to get SzProduct.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure in obtaining or initializing the SzProduct instance.

IsDestroyed()

Checks if this instance has had its Destroy() method called.

bool IsDestroyed()

Returns

bool

true if this instance has had its Destroy()
method called, otherwise false.

Examples

Usage:

// obtain the SzEnvironment (varies by application)
SzEnvironment env = GetEnvironment();

// check if already destroyed
if (!env.IsDestroyed())
{
    // destroy the environment
    env.Destroy();
}

Reinitialize(long)

Reinitializes the SzEnvironment with the specified configuration ID.

void Reinitialize(long configID)

Parameters

configID long

The configuration ID with which to initialize.

Examples

Usage:

// How to get the active config ID for the SzEnvironment
try
{
    // obtain the SzEnvironment (varies by application)
    SzEnvironment env = GetEnvironment();

    // get the active config ID
    long activeConfigID = env.GetActiveConfigID();

    // do something with the active config ID (varies by application)
    SzConfigManager configMgr = env.GetConfigManager();

    long defaultConfigID = configMgr.GetDefaultConfigID();

    if (activeConfigID != defaultConfigID)
    {
        // reinitialize the environment with the default config ID                    
        env.Reinitialize(defaultConfigID);
    }

}
catch (SzException e)
{
    // handle or rethrow the exception
    LogError("Failed to verify the active config ID.", e);
}

Exceptions

InvalidOperationException

If this SzEnvironment instance has been destroyed.

SzException

If there was a failure reinitializing.