ILockLock Method
IT Hit WebDAV Classes Reference
Locks this item.
Namespace: ITHit.WebDAV.Server.Class2Assembly: ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 4.5.3121.0
Syntax LockResult Lock(
LockLevel level,
bool isDeep,
Nullable<TimeSpan> requestedTimeOut,
string owner
)
Function Lock (
level As LockLevel,
isDeep As Boolean,
requestedTimeOut As Nullable(Of TimeSpan),
owner As String
) As LockResult
LockResult^ Lock(
LockLevel level,
bool isDeep,
Nullable<TimeSpan> requestedTimeOut,
String^ owner
)
abstract Lock :
level : LockLevel *
isDeep : bool *
requestedTimeOut : Nullable<TimeSpan> *
owner : string -> LockResult
Parameters
- level
- Type: ITHit.WebDAV.Server.Class2LockLevel
Whether lock is shared or exclusive. If an exclusive lock is set other users are not
be able to set any locks. If a shared lock is set other users are able to set shared lock on the item. - isDeep
- Type: SystemBoolean
Specifies if the lock applied only to this item or to the entire subtree. - requestedTimeOut
- Type: SystemNullableTimeSpan
Lock timeout which was requested by client. MaxValue
means infinity lock that never expires. Note that your server can ignore this parameter and set
timeout that is different from the one requested by client. Some clients may not provide any timeout. The null is passed in this case. - owner
- Type: SystemString
Owner of the lock as specified by client.
Return Value
Type:
LockResult
Instance of
LockResult that contains lock-token and timeout that was actually set.
Exceptions Remarks
This method is called when item is being locked by WebDAV client. In your implementation you must do the following:
- Generate the new lock-token, usually GUID.
- Save information about the lock in a storage.
- Associate the lock with the item in the repository.
- Return the lock-token to the Engine.
Optionally in in this method you can modify the lock timeout requested by client. For example instead of infinity
lock you can set lock for some limited time. You must return both lock-token and lock timeout via
LockResult
return value, the engine than sends the lock-token and timeout values back to WebDAV client.
Examples The code below is part of 'WebDAVServer.NtfsStorage' sample provided with the SDK.
public LockResult Lock(LockLevel level, bool isDeep, TimeSpan? requestedTimeOut, string owner)
{
RequireUnlocked(level == LockLevel.Shared);
string token = Guid.NewGuid().ToString();
TimeSpan timeOut;
if (!requestedTimeOut.HasValue || requestedTimeOut == TimeSpan.MaxValue)
{
timeOut = TimeSpan.FromMinutes(5);
}
else
{
timeOut = requestedTimeOut.Value;
}
DateTime expiration = DateTime.UtcNow + timeOut;
explicitLocks.Add(new DateLockInfo
{
Expiration = expiration,
IsDeep = false,
Level = level,
LockRoot = Path,
LockToken = token,
ClientOwner = owner,
TimeOut = timeOut
});
saveLocks();
return new LockResult(token, timeOut);
}
See Also