As a developer I can use ArcPy (Python) or ArcObjects (.NET) to develop some extensions or tools for ArcGIS platform. But I need to handle some events. When a user connected to an Enterprise geodatabase and create an object in database table, can I handle the events of CREATE, UPDATE or DELETE? Is this possible?
-
3INSERT, UPDATE, and DELETE are database events, not application events. Furthermore, in a versioned geodatabase, they are all modeled as INSERTs. The only way for an application to perceive database events is to control how they are requested.– VinceCommented Jun 10, 2019 at 14:15
-
1If you're still looking for an answer to this question you can determine if the IEditor.EditWorkspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace in the OnStartEditing event then wire the events for OnCreateFeature, OnChangeFeature and OnDeleteFeature from IEditEvents resources.arcgis.com/en/help/arcobjects-net/componenthelp/… which are the corresponding events in ArcMap. I should have some working C# or VB.net code if you're interested. I would have responded earlier but I was in hospital around the time you asked this question.– Michael StimsonCommented Jun 18, 2019 at 4:53
-
Thanks @MichaelStimson, I am still looking for an answer, yes. Should I create an extension for your solution? If you have some code can you share as an asnwer?– bartelomaCommented Jun 24, 2019 at 6:46
1 Answer
This is from working code, in this example 'timer save' a window pops up when a time has elapsed reminding the user to save, so I only use OnStartEditing and OnStopEditing events; It is important to note that this occurs in the form load event as there is an attached form:
private void TimerSaveForm_Load(object sender, EventArgs e)
{
vSaveEditsWarn = DateTime.Now;
this.FormClosing += new FormClosingEventHandler(TimerSaveForm_FormClosing); // to cleanup events
IEditor pED = pApplication.FindExtensionByName("ESRI Object Editor") as IEditor;
((IEditEvents_Event)pED).OnStartEditing += new IEditEvents_OnStartEditingEventHandler(TimerSaveForm_OnStartEditing);
((IEditEvents_Event)pED).OnStopEditing += new IEditEvents_OnStopEditingEventHandler(TimerSaveForm_OnStopEditing);
TimerSaveForm.CheckForIllegalCrossThreadCalls = false;
this.TopMost = true; // ensure this form isn't lost under another window'
}
void TimerSaveForm_OnStopEditing(bool save)
{
vTimer.Stop(); // System.Timers.Timer object
StartStopButton.Text = "Start";
this.BackColor = System.Drawing.SystemColors.Control;
this.Text = "Auto SaveEdits";
}
void TimerSaveForm_OnStartEditing()
{
vTimer.Start(); // System.Timers.Timer object
StartStopButton.Text = "Stop";
this.BackColor = System.Drawing.SystemColors.Control;
}
If you're writing a tool without a form you can wire it from the tool directly in the initializer. From the sounds of it you want to capture the On Start/Stop to grab your edit workspace then potentially OnCreateFeature, OnChangeFeature and OnDeleteFeature, which are wired in the same manner as the code shown.
When you start typing the event intelisense should finish the rest for you and offer to create the function wired to the event, I advise you to say yes and yes, not because I'm lazy but it saves mistyping and ensures that the event is correctly associated with the function.. if you try to create the function first Visual Studio may not recognize the association which will lead to hours of frustration trying to work out why an event isn't firing even though everything is spelled correctly.
Unwiring the events is a little counter intuitive, it's almost identical to the wiring but use -=
instead of +=
:
((IEditEvents_Event)pED).OnStartEditing -= new IEditEvents_OnStartEditingEventHandler(TimerSaveForm_OnStartEditing);
-
I want to run this code as a listener. I do not want to set it in a form or a tool. I want to add a listener extension on my arcmap.. Commented Jun 24, 2019 at 8:18
-
gis.stackexchange.com/questions/148586/… - this will load the listener as soon as ArcMap is started.. you will want to create an application extension rather than an ITool as your active tool changes but the extension stays active resources.esri.com/help/900/ArcGISExplorer/sdk/doc/… should point you in the right direction. Commented Jun 25, 2019 at 1:34