Hi Sean Jones,
Things are working pretty good now. I've moved the code into a new ArcGIS Pro Module Add-In, just to narrow down where things were going wrong. In my Module1.cs I have the following:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Threading.Tasks;
using ArcGIS.Core.CIM;
using ArcGIS.Core.Data;
using ArcGIS.Core.Geometry;
using ArcGIS.Desktop.Catalog;
using ArcGIS.Desktop.Core;
using ArcGIS.Desktop.Editing;
using ArcGIS.Desktop.Extensions;
using ArcGIS.Desktop.Framework;
using ArcGIS.Desktop.Framework.Contracts;
using ArcGIS.Desktop.Framework.Dialogs;
using ArcGIS.Desktop.Framework.Threading.Tasks;
using ArcGIS.Desktop.Mapping;
using ArcGIS.Desktop.Editing.Events;
namespace RowChanged_TEST
{
internal class Module1 : Module
{
private static Module1 _this = null;
public static Module1 Current
{
get
{
return _this ?? (_this = (Module1)FrameworkApplication.FindModule("RowChanged_TEST_Module"));
}
}
#region Overrides
protected override bool CanUnload()
{
return true;
}
protected override bool Initialize()
{
var eceToken = EditCompletedEvent.Subscribe(onEce);
return true;
}
protected Task onEce(EditCompletedEventArgs args)
{
QueuedTask.Run(() =>
{
var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
var layerTable = featLayer.GetTable();
var rowChangeToken = RowChangedEvent.Subscribe(OnRowChanged, layerTable);
});
return Task.FromResult(0);
}
private Guid _currentRowChangedGuid = Guid.Empty;
protected void OnRowChanged(RowChangedEventArgs args)
{
var row = args.Row;
if (_currentRowChangedGuid == args.Guid)
return;
row["COMMENTS"] = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
row["CONDITION"] = DateTime.Now.ToString();
_currentRowChangedGuid = Guid.Empty;
}
#endregion Overrides
}
It's all working well. One issue I am having is getting past this line:
var featLayer = MapView.Active.GetSelectedLayers().First() as FeatureLayer;
Unless I have a layer selected in the Table of Contents, I get an error....as expected I suppose. This was just a copy/paste from the API Reference Guide, so I'll have to refine it a bit. I guess I should be getting the layers edited through the EditCompletedEventArgs??
Another issue, is that whenever I run the code it never works the first time. For example, I'll make some edits (with a layer in the TOC selected), the code runs, but doesn't do anything....no errors....it just doesn't work. Then I immediatley do another edit, and everything works as expected. I'm not really sure what might be going on, but I've created a few other tools where I have seen this behaviour before. Do you see anything in my code that might be causing this? Have you ever heard of network or back-end DB configuration that might be causing this problem??
Thanks for your help!