Request.ClientLockTokens Property

IT Hit WebDAV for .NET

Gets the array of lock tokens submitted by client.

[Visual Basic]
Public ReadOnly Property ClientLockTokens As StringCollection
[C#]
public System.Collections.Specialized.StringCollection ClientLockTokens {get;}

Property Value

StringCollection object containing collection of lock tokens submitted by client.

Remarks

ClientLockTokens property provides access to the array of lock tokens submitted by client. You must generate the lock tokens during the call to your Lock and CreateLockNull methods implementation. During this call you associate generated token with an item in the repository and return it to the Engine. Engine than sends the new token to the WebDAV client. When WebDAV client is modifying any server item it sends back to server the list of lock tokens. In your WebDAV server Class 2 implementation before modifying any locked items you must check if WebDAV client provided necessary lock token.

Example

 public abstract class HierarchyItem : IHierarchyItem, ILock
 {
        ...
        internal bool ClientHasToken
        {
            get
            {
                LockInfo[] itemLocks = ActiveLocks;
                if(itemLocks.Length == 0) 
                    return true;
                WDRequest request = new WDRequest();
                StringCollection clientLockTokens = request.ClientLockTokens;
                for(int i=0; i<clientLockTokens.Count; i++)
                    for(int j=0; j<itemLocks.Length; j++)
                        if(clientLockTokens[i] == itemLocks[j].Token) 
                            return true;
                return false;
            }
        }
        ...
    }
    
    public class Folder : HierarchyItem, IFolder, IFolderLock
    {
        ...
        public WebDAVResponse CreateFolder(string name)
        {
            if(!ClientHasToken)
                return new LockedResponse();

            SqlConnection conn = new SqlConnection(connStr);
            SqlTransaction trans = null;
            conn.Open();
            try
            {
                trans = conn.BeginTransaction();
                CreateChild(trans, name, ItemType.Folder);
                trans.Commit();
            }
            catch(Exception ex)
            {
                if(trans != null) trans.Rollback();
                throw;
            }
            finally
            {
                conn.Close();
            }
            return new CreatedResponse();
        }
        ...
    }
 

See Also

Request Class | ITHit.WebDAV.Server Namespace