Rich,
At some point I will be listening to edit events, but it is not enabled at present.
Pasted below is a sample class that I wrote as I was learning to use the API for geodatabases, which were largely based on snippets of codes from the SDK examples. Looking around the forums, the somewhat slow geoprocessing operations doesn't seem to be an uncommon issue, but I really just wanted to confirm that what I am seeing is the expected behavior at present so I can figure out the next steps to workaround the issue. As someone new to the ESRI SDK, I also wanted to make sure I'm not doing something in a boneheaded way that is causing the issue in first place.
Thanks,
Matt
public enum GeoDBStatus
{
CreationInProgress = 0,
Created = 1,
Error = 2
}
public static class GeoDatabaseUtilities
{
public static async Task<bool> AddVectorToDB(string geodatabase_path, string LayerName, string GeometryType="POINT", int EPSG=4326)
{
var sr = ArcGIS.Core.Geometry.SpatialReferenceBuilder.CreateSpatialReference(EPSG);
bool r = await ExecuteToolAsync("CreateFeatureclass_management", Geoprocessing.MakeValueArray(geodatabase_path, LayerName, GeometryType, null, null, null, sr));
return r;
}
public static async Task<bool> AddDataTable(string geodatabase_path, string TableName)
{
return await ExecuteToolAsync("CreateTable_management", Geoprocessing.MakeValueArray(geodatabase_path, TableName));
}
public static async Task<bool> AddFields(string path, IEnumerable<Tuple<string, string>> fields)
{
return await ExecuteToolAsync("AddFields_management", Geoprocessing.MakeValueArray(path, string.Join(";", fields.Select(x => x.Item1 + " " + x.Item2))));
}
public static async Task<GeoDBStatus> Create(string directory, string name)
{
var result = await ExecuteToolAsync("CreateFileGDB_management", Geoprocessing.MakeValueArray(directory, name, "Current"));
if (result)
return GeoDBStatus.Created;
else
return GeoDBStatus.Error;
}
public static async Task<bool> ExecuteToolAsync(string tool, IReadOnlyList<string> parameters, Dictionary<string, string> Environments = null)
{
try
{
return await ArcGIS.Desktop.Framework.Threading.Tasks.QueuedTask.Run(async () =>
{
var cts = new CancellationTokenSource();
var results = await Geoprocessing.ExecuteToolAsync(tool, parameters, Environments, cts.Token, (eventName, o) =>
{
System.Diagnostics.Debug.WriteLine($@"GP event: {eventName} {o}");
}, GPExecuteToolFlags.GPThread);
return true;
});
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
return false;
}
}
}