AnsweredAssumed Answered

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

Question asked by pmasson on Jun 23, 2020
Latest reply on Jun 23, 2020 by pmasson

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;
}

 

Outcomes