Click or drag to resize

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
)

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
ExceptionCondition
LockedExceptionThis folder was locked. Client did not provide the lock token.
NeedPrivilegesExceptionThe user doesn't have enough privileges.
InsufficientStorageExceptionQuota limit is reached.
MultistatusExceptionErrors has occured during processing of the subtree.
DavExceptionIn other cases.
Remarks
This method is called when item is being locked by WebDAV client. In your implementation you must do the following:
  1. Generate the new lock-token, usually GUID.
  2. Save information about the lock in a storage.
  3. Associate the lock with the item in the repository.
  4. 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();

    // If timeout is absent or infinit timeout requested,
    // grant 5 minute lock.
    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);
}
See Also