How to create a new Coded Value Domain .Net SDK without using Geoprocessing.ExecuteToolAsync

625
2
06-23-2020 05:10 AM
PierreMasson
Occasional Contributor

I tried to create a new domain and using Geoprocessing.ExecuteToolAsync but the performance and stability his erratic at best.

THis takes many minutes to run and 1 time out of 2 it will display error messages...

Is there something in the SDK where it would be more conventionnal to add something has simple as this?


public async Task<bool> ExecuteAddDomainTool(string sdeConnectionFilePath, Dictionary<object, string> dicDom)
{
try
{
List<object> ps = new List<object>();
ps.Add(sdeConnectionFilePath);
ps.Add("myNewDomain");
ps.Add(string.Empty);
ps.Add("SHORT");
ps.Add("CODED");
ps.Add("DEFAULT");
ps.Add("DEFAULT");

var parameters = Geoprocessing.MakeValueArray(ps.ToArray());

var env = Geoprocessing.MakeEnvironmentArray(workspace: mainModule.Current.sdeConnectionFilePath);
var cts = new System.Threading.CancellationTokenSource();

bool addSuccess = true;

var results = Geoprocessing.ExecuteToolAsync("management.CreateDomain",
parameters, env, cts.Token, (eventName, o) =>
{
// MessageBox.Show($"{eventName}: {((IGPMessage[])o).First().Type.ToString()} {((IGPMessage[])o).First().Text}");
switch (eventName)
{
case "OnValidate":
break;
case "OnMessage":
if (((IGPMessage)o).Type == GPMessageType.Error)
{
addSuccess = false;
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(((IGPMessage)o).Text,
resPwndAddField.aboutToCreateNewDomainMsgTitle,
MessageBoxButton.OK,
MessageBoxImage.Error);
}
break;
case "OnProgressMessage":
//MessageBox.Show($"{eventName}: {o} %");
break;
case "OnProgressPos":
if (Convert.ToDouble(o) == -1)
pbValue = 100;
else
pbValue = Convert.ToDouble(o);
break;
default:
break;
}
});
await results;

foreach (KeyValuePair<object, string> kv in dicDom)
{
ps = new List<object>();
ps.Add(mainModule.Current.sdeConnectionFilePath);
ps.Add("myNewDomain");
ps.Add(kv.Key);
ps.Add(kv.Value);

parameters = Geoprocessing.MakeValueArray(ps.ToArray());

cts = new System.Threading.CancellationTokenSource();

results = Geoprocessing.ExecuteToolAsync("management.AddCodedValueToDomain",
parameters, env, cts.Token, (eventName, o) =>
{

switch (eventName)
{
case "OnValidate":
break;
case "OnMessage":
if (((IGPMessage)o).Type == GPMessageType.Error)
{
addSuccess = false;
ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(((IGPMessage)o).Text,
resPwndAddField.aboutToCreateNewDomainMsgTitle,
MessageBoxButton.OK,
MessageBoxImage.Error);
}
break;
case "OnProgressMessage":
// MessageBox.Show($"{eventName}: {o} %");
break;
case "OnProgressPos":
if (Convert.ToDouble(o) == -1)
pbValue = 100;
else
pbValue = Convert.ToDouble(o);
break;
default:
break;
}
});
await results;
}

return addSuccess;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
return false;
}

0 Kudos
2 Replies
RichRuh
Esri Regular Contributor

Adding DDL (data definition language) operations such as creating domains is on our long-term roadmap for the Pro SDK.

For now, using Geoprocessing‌ is the only technique to do this.  I would post in that group to figure out why you are sometimes getting errors.

--Rich

0 Kudos
PierreMasson
Occasional Contributor

I'm not getting error anymore but the best time for creating a domain with 4 values is 1m49s...

0 Kudos