Select to view content in your preferred language

IDatasetEdit::isBeingEdited() returns incorrect result

722
3
05-16-2010 04:14 PM
GailNagle
Emerging Contributor
Hello,

I have a multi-layer file geodatabase. I have loaded a single layer into ArcMap and started editing.
I then open this file geodatabase layer in another application and use the IDatasetEdit interface to query each subdataset object (i.e. layer by layer) if the subdataset is being edited. using this call:
HRESULT IDatasetEdit::isBeingEdited(  VARIANT_BOOL* pIsBeingEdited);
Although the layer IS BEING EDITED, the argument pIsBeingEdited always returns false.
How can I tell programmatically when a layer in a file GDB is being edited?
My application is written in C++.

BTW, the IWorkspaceEdit method with the same signature also says it is not being edited.

Thank you,
Gail
0 Kudos
3 Replies
GailNagle
Emerging Contributor
Just a bit more info on my previous post. I also tried the IDatasetEditEx interface with the same disappointing result. And in the file GDB directory I can see many lock files which should indicate the editing session can be detected. Finally, when I do this in reverse order, i.e. open the layer for editing in my application, ArcMap is able to detect the locks. So what is the method for doing this? I find it hard to believe that an application is supposed to use file system calls to find the relevant locks.

Thanks again,
Gail
0 Kudos
GailNagle
Emerging Contributor
I think I have found the solution. The confusion is about what IDatasetEdit::isBeingEdited( VARIANT_BOOL* pIsBeingEdited) actually means. If pIsBeingEdited is VARIANT_TRUE, then it means the current application is editing the dataset (or standalone feature class). If pIsBeingEdited is VARIANT_FALSE, then it means some OTHER application has a write lock on the dataset (or standalone feature class). Here is how I used this information to return the information I needed about which datasets are read-only to my application. Please note that in the C++ snippets below, the code is extracted from a class that has class members starting with m_.

void
MyClass::updateReadOnlyForDataset(BSTR dataset_name)
{
   if(m_ipWorkspace == NULL)
      return;

   try
   {
      IFeatureDatasetPtr ipFeatureDataset = NULL;
      IFeatureWorkspacePtr ipFeatureWorkspace( m_ipWorkspace );
      HRESULT hr = ipFeatureWorkspace->OpenFeatureDataset(dataset_name, &ipFeatureDataset );
      if(ipFeatureDataset)
      {
         IDatasetEditPtr datasetEdit = NULL;
         datasetEdit = ipFeatureDataset;
         if(datasetEdit)
         {
            VARIANT_BOOL pIsBeingEdited = VARIANT_FALSE;
            //are we editing this dataset or does another app have it locked?
            hr =  datasetEdit->IsBeingEdited(&pIsBeingEdited);
            if(pIsBeingEdited == VARIANT_FALSE)
            {
               //since we are not editing it, then it is locked by another app
               m_read_only = true;
            }
         }
      }
   }
   catch(...)
   {
      //report error
   }
}

void
MyClass::updateReadOnlyForFeatureClass(BSTR layer_name)
{
   if(m_ipWorkspace == NULL)
      return;
   try
   {
      IFeatureClassPtr ipFeatureClass = NULL;
      IFeatureWorkspacePtr ipFeatureWorkspace( m_ipWorkspace );
      HRESULT hr = ipFeatureWorkspace->OpenFeatureClass(layer_name, &ipFeatureClass );
      if(ipFeatureClass)
      {
         IDatasetEditPtr datasetEdit = NULL;
         datasetEdit = ipFeatureClass;
         //are we editing this standalone fc or does another app have it locked?
         if(datasetEdit)
         {
            VARIANT_BOOL pIsBeingEdited = VARIANT_FALSE;
            hr =  datasetEdit->IsBeingEdited(&pIsBeingEdited);
            if(pIsBeingEdited == VARIANT_FALSE)
            {
               //since we are not editing it, then it is locked by another app
               m_read_only = true;
            }
         }
      }
   }
   catch(...)
   {
      //report error
   }
}

// main
HRESULT hr = _ipWorkspaceEdit->StartEditing( VARIANT_FALSE );
...

BSTR layer_name = ::AoAllocBSTR( L"None" );
...
ipDataset->get_Name( &layer_name );

//if testing a dataset ...
updateReadOnlyForDataset(layer_name );

//if testing a standalone feature class ...
updateReadOnlyForFeatureClass(layer_name);
0 Kudos
NagendraPutti
Deactivated User
Gail, You are right,

May be if some one requires, I am posting C# version of your implementation

static void doTestFGDB(){
            //This test assumes two datasets and one of them holds AdministrativeAreas
            IWorkspace wkspc = fGDBWorkspaceFromString(@"C:\issues\815849\LTDS_20_931.gdb");
            IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)wkspc;
            workspaceEdit.StartEditing(false);
            IFeatureWorkspace fw = wkspc as IFeatureWorkspace;           
            IFeatureClass fc = fw.OpenFeatureClass("AdministrativeAreas");           
            IDatasetEdit de = fc as IDatasetEdit;          

            try
            {    Console.WriteLine(de.IsBeingEdited());
                // When AdministrativeAreas is open in ArcMap for editing - FALSE
                // When AdministrativeAreas is removed from ArcMap editing - FALSE
                // When parent datset(AdministrativeAreas) is removed and second dataset is opened in editing - TRUE
               
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
          
            Console.WriteLine("TEST finished");
        }
0 Kudos