Click or drag to resize

ILockLock Method

IT Hit WebDAV Classes Reference
Locks this item.

Namespace: ITHit.WebDAV.Server.Class2
Assembly: 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
)

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