ICSSoft.STORMNET.Web.Tools.WebLockHelper
class to work with web-locks of data objects in web applications. Uses the date and lifetime of a lock to determine its relevance, the lock is stored in the database.
Interface
A class implements an interface ILockHelper
:
public interface ILockHelper
{
bool LockDataObject(string dataObjectKey, string userName, out string lockUserName);
bool ClearWebLock(string dataObjectKey, string userName);
string GetLock(string dataObjectKey);
TimeSpan LockTimeout { get; set; }
}
LockDataObject
is to try to establish a lock on the object by the given key and user name. In the event of a locktrue
returns if the object is already locked -false
. In this case, the parameterlockUserName
is written the name of the user that set the lock.ClearWebLock
- remove a lock if it was installed by the current user. In case a good cleaning will returntrue
, otherwisefalse
.GetLock
- returns the name of the user that has locked the object by key. If the object is not locked, an empty string is returned.LockTimeout
the lifetime of a lock. You need to remove the old lock. If the edit page is open, it periodically sends ajax requests to extend the lock. When you close the page requests are canceled, and the lock is aging. The frequency of requests corresponds to the lifetime of the lock.
Uses
If the desired application service locks, you can implement an interface ILockHelper
and use your own class where you have, for example, to ask for locks in WebObjectListView.
An example of using WebLockHelper
in WOLV:
// A property that stores LockHelper
public static ILockHelper LockHelper
{
get
{
if (_lockHelper == null)
{
_lockHelper = new WebLockHelper();
}
return _lockHelper;
}
set { _lockHelper = value; }
}
Setting the lock:
if (lockHelper.LockDataObject(PK, Context.User.Identity.Name, out lockUserName))
{
MessageBox.Show("The object was successfully locked");
}
else
{
MessageBox.Show("The object is already locked by user " + lockUserName);
}