Click or drag to resize

ILockAsyncRefreshLockAsync Method

IT Hit WebDAV Classes Reference
Updates lock timeout information on this item.

Namespace:  ITHit.WebDAV.Server.Class2
Assembly:  ITHit.WebDAV.Server (in ITHit.WebDAV.Server.dll) Version: 11.3.10719
Syntax
Task<RefreshLockResult> RefreshLockAsync(
	string token,
	Nullable<TimeSpan> requestedTimeOut
)

Task<RefreshLockResult> RefreshLockAsync(
	string token,
	Nullable<TimeSpan> requestedTimeOut
)

Parameters

token
Type: SystemString
Lock token.
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.

Return Value

Type: TaskRefreshLockResult
Instance of RefreshLockResult that contains information about the lock including 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 occurred during processing of the subtree.
DavExceptionIn other cases.
Remarks
This method is called when WebDAV client wants to modify (usually prolong) timeout for the previously set lock. In this method implementation you can update the lock timeout. Note that you can ignore the requested timout and set timeout that is different from the one requested by client.
Examples

The code below is part of 'WebDAVServer.FileSystemStorage.AspNet' C# & VB samples provided with the SDK.

public async Task<RefreshLockResult> RefreshLockAsync(string token, TimeSpan? requestedTimeOut)
{
    if (string.IsNullOrEmpty(token))
    {
        throw new DavException("Lock can not be found.", DavStatus.BAD_REQUEST);
    }

    List<DateLockInfo> locks = await GetLocksAsync(getAllWithExpired: true);
    DateLockInfo lockInfo = locks.SingleOrDefault(x => x.LockToken == token);

    if (lockInfo == null || lockInfo.Expiration <= DateTime.UtcNow)
    {
        throw new DavException("Lock can not be found.", DavStatus.CONFLICT);
    }
    else
    {
        lockInfo.TimeOut = TimeSpan.FromMinutes(5);

        if (requestedTimeOut.HasValue && requestedTimeOut < TimeSpan.MaxValue)
        {
            lockInfo.TimeOut = requestedTimeOut.Value;
        }


        lockInfo.Expiration = DateTime.UtcNow + lockInfo.TimeOut;

        await SaveLockAsync(lockInfo);
    }
    await context.socketService.NotifyLockedAsync(Path);

    return new RefreshLockResult(lockInfo.Level, lockInfo.IsDeep, lockInfo.TimeOut, lockInfo.ClientOwner);
}
See Also