I am trying to get the OnEditCompleted event and do some checks (is the operation allowed) and actions (calc some default values).
The basic code is below. I have a few questions:
1) Do I need to get the OnRowCreated event too or this event is covering the same operations. Keep in mind that I have to check features added by GP tools (like append).
2) From my debug it looks that even this event is called multiply times with no reason - what can I do about it?
3) I could not find the way to abort the transaction. I could not find something like RowChangedEventArgs.CancelEdit
I used EditCompletedEventArgs.FromException but it create Exception and does not end transaction.
Thanks
Mody
protected Task onEditCompleted(EditCompletedEventArgs args)
{
// check features one by one
string message = "";
Dictionary<MapMember, List<long>> createSelset = args.Creates.ToDictionary();
foreach (var v in createSelset)
{
QueryFilter queryFilter = new QueryFilter();
queryFilter.ObjectIDs = v.Value;
FeatureLayer featureLayer = v.Key as FeatureLayer;
using (FeatureClass featureClass = featureLayer.GetFeatureClass())
{
using (RowCursor cursor = featureLayer.GetFeatureClass().Search(queryFilter))
{
Feature currentFeat = null;
while (cursor.MoveNext())
{
currentFeat = (Feature)cursor.Current;
bool res = CheckFeatureCreate(currentFeat, out message);
if (res == false)
{
return Task.FromException(new Exception(message));
}
res = HandleFeatureCreate(currentFeat);
if (res == false)
{
return Task.FromException(new Exception("Problem with calc values"));
}
}
}
}
}