I am developing an Pro application that will control edit events.
I would like to give option to turn of this option.
In ArcMap I would develop code that implement IExtension and IExtensioConfig then the extension "remember" if it is on or off. If it is on it runs the startup. If I am turning it off it will un subscribe to the events.
Here is the docs for ArcMap https://desktop.arcgis.com/en/arcobjects/latest/net/webframe.htm#AppFrameworkExtensionHowTo.htm
Moving to Pro I used this example: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/Licensing
I do not have a license for the extension.
I see two problems. First I do not see startup method - what code is running when extension exists?
Then the extension is always turned off, I could not find a way to remember the last state.
You can implement IExtensionConfig in your Module class and activate/deactivate your events in the State property setter:
public ExtensionState State
{
get { return this._state; }
set
{
this._state = value;
if (value == ExtensionState.Disabled) this.UnwireEvents();
else if (value == ExtensionState.Enabled) this.WireEvents();
}
}
If you want to persist your extension state in the project, you can overwrite the OnReadSettingsAsync and OnWriteSettingsAsync methods:
protected override Task OnReadSettingsAsync(ModuleSettingsReader settings)
{
if (null == settings) return Task.FromResult(0);
var value = settings.Get("MyExtensionState");
if (value != null && value is string s && Enum.TryParse(s, out ExtensionState extensionState))
{
this.State = extensionState;
}
return Task.FromResult(0);
}
protected override Task OnWriteSettingsAsync(ModuleSettingsWriter settings)
{
settings.Add("MyExtensionState", this.State.ToString());
return Task.FromResult(0);
}
See also https://github.com/Esri/arcgis-pro-sdk/wiki/ProGuide-Custom-settings. This also explains how to store settings at the application/user level.