I have a large, enterprise scale distributed application that I am working on.
I am using windows data-binding to generate data-bound forms for configuration quickly (in hours instead of weeks)
The entities that I am binding to implement INotifyPropertyChanged, and the data-binding has worked really well up to this point.
Due to changes in the specification and increasing row contention, I recently had to move from an optimistic locking model, to a pessimistic locking model.
As such, the entities are now "ReadOnly" by default, and in order to change property values, the entity must first obtain an exclusive lock on the record (which it does by a call to the server)
I tried implementing the IEditableObject interface, and in the BeginEdit() method I acquire the lock, and in the CancelEdit()/EndEdit() methods I release the lock.
This all works fine, except in the situation where a lock cannot be obtained (because another user has the same record locked)
If the time-out is exceeded while waiting for a lock, an ApplicationException is thrown out of the BeginEdit() method.
However, there doesn't seem to be any way to handle this exception, nor does there seem to be any way to communicate to the binding source that a particular entity is read-only.
I am considering implementing the ICustomTypeDescriptor interface, so that for a ReadOnly entity, I can yield property information that would return PropertyInfo.CanWrite as false.... but I am not sure if the windows binding framework will re-query this interface frequently enough.
There doesn't seem to be any support for Entities that might be in a read-only state.... (unless I have managed to miss it in the documentation???)
Any help, ideas, comments appreciated, specifically:
Is there an interface I can implement on the entity object that will communicate the read-only status of a record to the binding source, and subsequently set the bound controls to read-only (or not enabled)?
How do you tell windows-forms-data-binding (BindingSource) that a particular record