private bool Unregister() { //Careful here - events have to be unregistered on the same //thread they were registered on...hence the use of the //Queued Task QueuedTask.Run(() => { //One kvp per layer....of which there is only one in the sample //out of the box but you can add others and register for events foreach (var kvp in _rowevents) { RowCreatedEvent.Unsubscribe(kvp.Value[0]); RowChangedEvent.Unsubscribe(kvp.Value[1]); RowDeletedEvent.Unsubscribe(kvp.Value[2]); kvp.Value.Clear(); } _rowevents.Clear(); //Editing and Edit Completed. EditCompletingEvent.Unsubscribe(_editevents[0]); EditCompletedEvent.Unsubscribe(_editevents[1]); _editevents.Clear(); }); return(false); }
private bool Register() { var layers = MapView.Active.Map.GetLayersAsFlattenedList().OfType <FeatureLayer>(); QueuedTask.Run(() => { foreach (var fl in layers) { var fc = fl.GetFeatureClass(); var tokens = new List <SubscriptionToken>(); //These events are fired once ~per feature~, //per table tokens.Add(RowCreatedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); tokens.Add(RowChangedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); tokens.Add(RowDeletedEvent.Subscribe((rc) => RowEventHandler(rc), fc)); _rowevents[fl.Name] = tokens; } //This event is fired once per edit execute //Note: This event won't fire if the edits were cancelled _editevents.Add(EditCompletingEvent.Subscribe((ec) => { RecordEvent("EditCompletingEvent", ""); //can also cancel edit in the completing event... //cancels everything (that is cancealable) // //you'll need to modify the RowEventHandler() to prevent if //from doing the cancel or this will never get called if (_cancelEdit) { ec.CancelEdit($"EditCompletingEvent, edit cancelled"); AddEntry("*** edits cancelled"); AddEntry("---------------------------------"); } })); //This event is fired after all the edits are completed (and on //save, discard, undo, redo) and is fired once _editevents.Add(EditCompletedEvent.Subscribe((ec) => { HandleEditCompletedEvent(ec); return(Task.FromResult(0)); })); }); return(true); }