In ArcMap, I was able to determine if my users were in an edit session, or no.
I know that an edit session isn't the same / not required in Pro. But many of my users are still new to Pro, so I suggest they follow the instructions in this link, to enable editing from the edit tab.
https://www.youtube.com/watch?v=nQq3sgFbk8I
I have a c# Add-In for ArcGIS pro. I would like my program to be able to determine if my user is in an edit session, or no.
I have tried things like this:
private async void CheckEditSession()
{
// Check if an edit session is in progress
bool editInProgress = false;
await QueuedTask.Run(() =>
{
editInProgress = EditingModule.Current.EditState == EditState.Editing;
});
// Display appropriate message
if (editInProgress)
{
MessageBox.Show("Edit session in progress.");
}
else
{
MessageBox.Show("Edit Session NOT in progress.");
}
}
But, as you can see, this syntax isn't really available. I'm having trouble finding any equivalent in the vast work of Pro Snippets.
How can I programmatically determine whether or not my user is in an edit session, or not?
The Project class has the IsEditingEnabled property. This is the snippet to disable editing.
// if editing
if (Project.Current.IsEditingEnabled)
{
var res = MessageBox.Show("Do you want to disable editing? Editing tools will be disabled",
"Disable Editing?", System.Windows.MessageBoxButton.YesNoCancel);
if (res == System.Windows.MessageBoxResult.No ||
res == System.Windows.MessageBoxResult.Cancel)
{
return;
}
//we must check for edits
if (Project.Current.HasEdits)
{
res = MessageBox.Show("Save edits?", "Save Edits?", System.Windows.MessageBoxButton.YesNoCancel);
if (res == System.Windows.MessageBoxResult.Cancel)
return;
else if (res == System.Windows.MessageBoxResult.No)
Project.Current.DiscardEditsAsync();
else
{
Project.Current.SaveEditsAsync();
}
}
Project.Current.SetIsEditingEnabledAsync(false);
}
How would this work for a CoreHost application, where pro has been configured to require an edit session?
When configured this way, the Geodatabase.ApplyEdits method must be passed true, otherwise an exception is thrown. But in a CoreHost application, Project.Current is always null. How can I know when I must set the second parameter as true? Further, doing so get's rid of the exception and things appear to complete successfully, but the edit is not actually written to the attribute table.