[GIS] Problems when trying to Undo edit operations in ArcGIS

arcobjectsversioning

I'm trying to programatically stop/abort/undo an edit operation inside a ArcSDE environment. My environment is currently Oracle, ArcSDE 9.3.1 and in our custom code (I inherited a large ugly portion of a system) the developers do use StartEditing/StartEditOperation and StopEditing/StopEditOperation workflow, but they ONLY use IWorkspaceEdit interface and not Imultiversion interface.

Unfortunately, out database is NOT versioned and all edits done with ArcMap are done by uncheking the option of Undo/Redo – hence, all my undos fails (COM Exception).

I'm trying to capture a OnDeleteEvent and inside it, I check for a certain condition, and then I call AbortOperation, but the operation is not aborted. I need to stop the whole edit session and ask to not save to "rollback" my edits. This consistent with ESRI docs.

My guess here is, the delete already happened and commited to the database? If yes, what is an strategy to not allow this certain edit to happen? There are some other scenarios that I need to cancel the edit operation. I know that IEditEvents2 has a BeforeStopOperation event, but ESRI explicitely tells us not to call AbortOperation inside these events.

There are also other problems with this setup: I check for all edits on a stopEditOperation and generate some notifications with it. All edits come to me as empty. THis might have something to do with it?

Please, help?

Thanks guys!

Exemple code (onDeleteEvent):

    void events_OnDelete(IObject obj)
    {
        ITable table = null;
        IDataset dataset = obj.Table as IDataset;

        IFeatureWorkspace workspace = dataset.Workspace as IFeatureWorkspace;
        IWorkspaceEdit edit = workspace as IWorkspaceEdit;

        edit.EnableUndoRedo();

        IQueryFilter filter = new QueryFilterClass();

        try
        {
            foreach (string s in VariousTables())
            {
                table = workspace.OpenTable(s);

                if (s.Contains("vertex"))
                    filter.WhereClause = "clause A";
                else
                    filter.WhereClause = "clause B";

                if (table.RowCount(filter) > 0)
                {
                    edit.AbortEditOperation(); --> this still deletes the point
                    // edit.UndoEditOperation() --> this breaks, as the workspace does not support Undos
                    break;
                }
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show("ErroR",ex);
        }
    }

Best Answer

According to the documentation here, you need to raise an error rather than using AbortEditOperation when you want to cancel an edit in OnDelete.

If you are using the OnCreate, OnDelete or OnChange methods in a class extension to validate edit operations, you should not call AbortEditOperation on the workspace if your logic indicates that the edit operation is invalid. Instead, raise an error which will be propagated to the application that is performing the edit on the class.