ILockLockAsync Method
IT Hit WebDAV Classes Reference
Locks this item.
Namespace:
ITHit.WebDAV.Server.Class2
Assembly:
ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 13.3.13068
Syntax Task<LockResult> LockAsync(
LockLevel level,
bool isDeep,
Nullable<TimeSpan> requestedTimeOut,
string owner
)
Function LockAsync (
level As LockLevel,
isDeep As Boolean,
requestedTimeOut As Nullable(Of TimeSpan),
owner As String
) As Task(Of LockResult)
Task<LockResult^>^ LockAsync(
LockLevel level,
bool isDeep,
Nullable<TimeSpan> requestedTimeOut,
String^ owner
)
abstract LockAsync :
level : LockLevel *
isDeep : bool *
requestedTimeOut : Nullable<TimeSpan> *
owner : string -> Task<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:
TaskLockResult
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.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.
public async Task<LockResult> LockAsync(LockLevel level, bool isDeep, TimeSpan? requestedTimeOut, string owner)
{
await RequireUnlockedAsync(level == LockLevel.Shared);
string token = Guid.NewGuid().ToString();
TimeSpan timeOut = TimeSpan.FromMinutes(5);
if (requestedTimeOut.HasValue && requestedTimeOut < TimeSpan.MaxValue)
{
timeOut = requestedTimeOut.Value;
}
DateLockInfo lockInfo = new DateLockInfo
{
Expiration = DateTime.UtcNow + timeOut,
IsDeep = false,
Level = level,
LockRoot = Path,
LockToken = token,
ClientOwner = owner,
TimeOut = timeOut
};
await SaveLockAsync(lockInfo);
await context.socketService.NotifyLockedAsync(Path, GetWebSocketID());
return new LockResult(lockInfo.LockToken, lockInfo.TimeOut);
}
Public Async Function LockAsync(level As LockLevel, isDeep As Boolean, requestedTimeOut As TimeSpan?, owner As String) As Task(Of LockResult) Implements ILock.LockAsync
Await RequireUnlockedAsync(level = LockLevel.Shared)
Dim token As String = Guid.NewGuid().ToString()
Dim timeOut As TimeSpan = TimeSpan.FromMinutes(5)
If requestedTimeOut.HasValue AndAlso requestedTimeOut < TimeSpan.MaxValue Then
timeOut = requestedTimeOut.Value
End If
Dim lockInfo As DateLockInfo = New DateLockInfo With {.Expiration = DateTime.UtcNow + timeOut,
.IsDeep = False,
.Level = level,
.LockRoot = Path,
.LockToken = token,
.ClientOwner = owner,
.TimeOut = timeOut
}
Await SaveLockAsync(lockInfo)
Await context.socketService.NotifyLockedAsync(Path, GetWebSocketID())
Return New LockResult(lockInfo.LockToken, lockInfo.TimeOut)
End Function
No code example is currently available or this language may not be supported.
No code example is currently available or this language may not be supported.
See Also