Skip to content

Updated C# and Java snippets for new SzConfig and SzConfigManager #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 12 additions & 29 deletions csharp/runner/SnippetRunner/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -246,35 +246,21 @@ SortedDictionary<string, SortedDictionary<string, string>> snippetsMap
// check if we need to configure sources
if (properties.ContainsKey(SourceKeyPrefix + 0))
{
SzConfig config = env.GetConfig();
IntPtr handle = config.CreateConfig();
string? snippetConfig = null;
try
SzConfig config = configMgr.CreateConfig();
for (int index = 0;
properties.ContainsKey(SourceKeyPrefix + index);
index++)
{
for (int index = 0;
properties.ContainsKey(SourceKeyPrefix + index);
index++)
{
string sourceKey = SourceKeyPrefix + index;
string source = properties[sourceKey];
source = source.Trim();
Console.WriteLine("Adding data source: " + source);
config.AddDataSource(handle, source);
}
snippetConfig = config.ExportConfig(handle);

}
finally
{
config.CloseConfig(handle);
string sourceKey = SourceKeyPrefix + index;
string source = properties[sourceKey];
source = source.Trim();
Console.WriteLine("Adding data source: " + source);
config.AddDataSource(source);
}
string snippetConfig = config.Export();

// register the config
long configID = configMgr.AddConfig(snippetConfig, snippet);

// set the default config to the snippet config
configMgr.SetDefaultConfigID(configID);

configMgr.SetDefaultConfig(snippetConfig);
}
else
{
Expand Down Expand Up @@ -657,10 +643,7 @@ static string SetupTempRepository(InstallLocations senzingInstall)
SzEnvironment env = SzCoreEnvironment.NewBuilder().Settings(settings).Build();
try
{
SzConfigManager configMgr = env.GetConfigManager();

long configID = configMgr.AddConfig(baseConfig, "Default Config");
configMgr.SetDefaultConfigID(configID);
env.GetConfigManager().SetDefaultConfig(baseConfig);

}
catch (Exception)
Expand Down
2 changes: 1 addition & 1 deletion csharp/runner/SnippetRunner/SnippetRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.1" />
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
39 changes: 14 additions & 25 deletions csharp/snippets/configuration/AddDataSources/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@

try
{
// get the config and config manager from the environment
SzConfig config = env.GetConfig();
// get the config manager from the environment
SzConfigManager configMgr = env.GetConfigManager();

// setup a loop to handle race-condition conflicts on
Expand All @@ -39,35 +38,25 @@
{
// get the current default config ID and associated config JSON
long configID = configMgr.GetDefaultConfigID();
string configDefinition = configMgr.GetConfig(configID);

// prepare an in-memory config to be modified and get the handle
IntPtr configHandle = config.ImportConfig(configDefinition);
string? modifiedConfig = null;
try
{
// create an array of the data sources to add
string[] dataSources = { "CUSTOMERS", "EMPLOYEES", "WATCHLIST" };

// loop through the array and add each data source
foreach (string dataSource in dataSources)
{
config.AddDataSource(configHandle, dataSource);
}

// export the modified config to JSON text
modifiedConfig = config.ExportConfig(configHandle);
// get the SzConfig for the config ID
SzConfig config = configMgr.CreateConfig(configID);

// create an array of the data sources to add
string[] dataSources = { "CUSTOMERS", "EMPLOYEES", "WATCHLIST" };

}
finally
// loop through the array and add each data source
foreach (string dataSource in dataSources)
{
config.CloseConfig(configHandle);
config.AddDataSource(dataSource);
}

// add the modified config to the repository with a comment
long newConfigID = configMgr.AddConfig(
modifiedConfig, "Added truth set data sources");
// prepare an in-memory config to be modified and get the handle
string modifiedConfig = config.Export();

// add the modified config to the repository with a comment
long newConfigID = configMgr.RegisterConfig(modifiedConfig);

try
{
// replace the default config
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
26 changes: 6 additions & 20 deletions csharp/snippets/configuration/InitDefaultConfig/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,16 @@

try
{
// get the config and config manager from the environment
SzConfig config = env.GetConfig();
// get the config and config from the environment
SzConfigManager configMgr = env.GetConfigManager();

// prepare an in-memory config to be modified and get the handle
IntPtr configHandle = config.CreateConfig();
string? configDefinition = null;

try
{
configDefinition = config.ExportConfig(configHandle);

}
finally
{
config.CloseConfig(configHandle);
}
// prepare a config to be modified
SzConfig config = configMgr.CreateConfig();
string configDefinition = config.Export();

// add the modified config to the repository with a comment
long configID = configMgr.AddConfig(
configDefinition, "Initial configuration");

// replace the default config
configMgr.SetDefaultConfigID(configID);
configMgr.SetDefaultConfig(configDefinition);

}
catch (SzException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/deleting/DeleteViaLoop/DeleteViaLoop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/information/GetLicense/GetLicense.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/information/GetVersion/GetVersion.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@
try
{
SzProduct product = env.GetProduct();
SzConfig config = env.GetConfig();
SzConfigManager configMgr = env.GetConfigManager();
SzDiagnostic diagnostic = env.GetDiagnostic();
SzEngine engine = env.GetEngine();

Console.WriteLine(product);
Console.WriteLine(config);
Console.WriteLine(configMgr);
Console.WriteLine(diagnostic);
Console.WriteLine(engine);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/loading/LoadRecords/LoadRecords.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/loading/LoadViaLoop/LoadViaLoop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions csharp/snippets/loading/LoadViaQueue/LoadViaQueue.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta.2.0" />
<ItemGroup>
<PackageReference Include="Senzing.Sdk" Version="4.0.0-beta*" />
</ItemGroup>

</Project>
Loading
Loading