public LockResult RefreshLock(IStoreItem item, bool recursiveLock, IEnumerable <int> timeouts, WebDavUri lockTokenUri)
        {
            var timeout      = timeouts.Cast <int?>().FirstOrDefault();
            var itemLockInfo = new ItemLockInfo(item, LockType.Write, LockScope.Exclusive, lockTokenUri, recursiveLock, null, timeout ?? -1);

            return(new LockResult(DavStatusCode.Ok, GetActiveLockInfo(itemLockInfo)));
        }
        public LockResult Lock(IStoreItem item, LockType lockType, LockScope lockScope, XElement owner, WebDavUri lockRootUri,
                               bool recursiveLock, IEnumerable <int> timeouts)
        {
            var timeout      = timeouts.Cast <int?>().FirstOrDefault();
            var itemLockInfo = new ItemLockInfo(item, lockType, lockScope, lockRootUri, recursiveLock, owner, timeout ?? -1);

            return(new LockResult(DavStatusCode.Ok, GetActiveLockInfo(itemLockInfo)));
        }
 private static ActiveLock GetActiveLockInfo(ItemLockInfo itemLockInfo)
 {
     return(new ActiveLock(itemLockInfo.Type,
                           itemLockInfo.Scope,
                           itemLockInfo.Recursive ? int.MaxValue : 0, itemLockInfo.Owner,
                           itemLockInfo.Timeout,
                           new WebDavUri($"{TokenScheme}:{itemLockInfo.Token:D}"),
                           itemLockInfo.LockRootUri));
 }
Пример #4
0
        public LockResult Lock(IStoreItem item, LockType lockType, LockScope lockScope, XElement owner, Uri lockRootUri, bool recursive, IEnumerable <int> timeouts)
        {
            // Determine the expiration based on the first time-out
            var timeout = timeouts.Cast <int?>().FirstOrDefault();

            // Determine the item's key
            var key = item.UniqueKey;

            lock (_itemLocks)
            {
                // Make sure the item is in the dictionary
                ItemLockTypeDictionary itemLockTypeDictionary;
                if (!_itemLocks.TryGetValue(key, out itemLockTypeDictionary))
                {
                    _itemLocks.Add(key, itemLockTypeDictionary = new ItemLockTypeDictionary());
                }

                // Make sure there is already a lock-list for this type
                ItemLockList itemLockList;
                if (!itemLockTypeDictionary.TryGetValue(lockType, out itemLockList))
                {
                    // Create a new lock-list
                    itemLockTypeDictionary.Add(lockType, itemLockList = new ItemLockList());
                }
                else
                {
                    // Check if there is already an exclusive lock
                    if (itemLockList.Any(l => l.Scope == LockScope.Exclusive))
                    {
                        return(new LockResult(DavStatusCode.Locked));
                    }
                }

                // Create the lock info object
                var itemLockInfo = new ItemLockInfo(item, lockType, lockScope, lockRootUri, recursive, owner, timeout ?? -1);

                // Add the lock
                itemLockList.Add(itemLockInfo);

                // Return the active lock
                return(new LockResult(DavStatusCode.Ok, GetActiveLockInfo(itemLockInfo)));
            }
        }