Jim Sculley

PDM API: Object Properties Show Incorrect Value

Discussion created by Jim Sculley on Apr 1, 2019
Latest reply on Apr 5, 2019 by Jim Sculley

I have some C# code (in an EPDM add-in) that attempts to call IEdmFile::LockFile. If the file is checked out, the call throws a COMException as expected. The error code for the exception is EdmResultErrorCodes_e.E_EDM_FILE_IS_LOCKED, as expected. I set a breakpoint in my error handler, and when I look at the properties for the file in question, the IsLocked property is false, which is not expected. The LockedByUserID is 0 and the LockPath is null, so EPDM threw an exception because the file was locked, but then indicates that the file is not locked.

 

It gets worse......

 

I created a simple C# macro:

 

public void Main()
{
IEdmVault10 vault = new EdmVault5Class();
vault.LoginAuto("vault name", 0);
IEdmFolder5 folder = null;
IEdmFile10 file = vault.GetFileFromPath("<path to file in vault>", out folder) as IEdmFile10;
try
{
file.LockFile(folder.ID, 0, (int)EdmLockFlag.EdmLock_Simple);
}
catch (COMException)
{
IEdmFile10 file2 = vault.GetFileFromPath("<path to file in vault>", out folder) as IEdmFile10;
MessageBox.Show("Variable 'file' is locked: " + file.IsLocked + "\nVariable 'file2' is locked: " + file2.IsLocked);
}
}

 

I set a breakpoint on the line calling LockFile and when the code pauses, I check out the file in question on another machine. On resuming, the exception is thrown as expected. In the exception handler I get a new reference to the file in question and display the IsLocked property for the original reference and the new reference.

 

Here are the results:

 

Ouch. Two variables, which should be pointing at the same object, showing different values for the properties of that object.

 

So, the IEdmFile5 object has a Refresh() method, with this detailed description of its purpose:

 

 

Gosh, thanks. Clear as mud. If you add a call to Refresh for the file variable, you get the correct results:

 

Unless I set a breakpoint after the Refresh call and undo the checkout from my other machine, in which case we get this:

 

 

All this seems to indicate that objects returned by PDM are merely snapshots of PDM entities (files, folders, etc) at a moment in time. From a programming perspective, this is truly frightening. With no guarantees that changes to underlying PDM entities aren't being made by others at the same time your code is running, you cannot have predictable behavior.

 

You might say, "Well, just call Refresh() every time before you ask an object for its properties.", but there is no guarantee that the underlying entity won't be changed between the Refresh() call and the very next line of code.

Outcomes