Example #1
0
        /// <summary>
        /// Stop any other transactions reading or writing this item to/from
        /// the cache. Send them straight to the database instead. (The lock
        /// does time out eventually.) This implementation tracks concurrent
        /// locks by transactions which simultaneously attempt to write to an
        /// item.
        /// </summary>
        public async Task <ISoftLock> LockAsync(CacheKey key, object version, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            using (await(_asyncReaderWriterLock.WriteLockAsync()).ConfigureAwait(false))
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("Invalidating: {0}", key);
                }

                var lockValue = await(_cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);
                try
                {
                    ILockable lockable = (ILockable)await(Cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
                    long      timeout  = Cache.NextTimestamp() + Cache.Timeout;
                    CacheLock @lock    = lockable == null?
                                         CacheLock.Create(timeout, NextLockId(), version) :
                                             lockable.Lock(timeout, NextLockId());

                    await(Cache.PutAsync(key, @lock, cancellationToken)).ConfigureAwait(false);
                    return(@lock);
                }
                finally
                {
                    await(_cache.UnlockAsync(key, lockValue, cancellationToken)).ConfigureAwait(false);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Stop any other transactions reading or writing this item to/from
        /// the cache. Send them straight to the database instead. (The lock
        /// does time out eventually.) This implementation tracks concurrent
        /// locks by transactions which simultaneously attempt to write to an
        /// item.
        /// </summary>
        public async Task <ISoftLock> LockAsync(CacheKey key, object version, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            using (await _lockObjectAsync.LockAsync())
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("Invalidating: {0}", key);
                }

                try
                {
                    await(cache.LockAsync(key, cancellationToken)).ConfigureAwait(false);

                    ILockable lockable = (ILockable)await(cache.GetAsync(key, cancellationToken)).ConfigureAwait(false);
                    long      timeout  = cache.NextTimestamp() + cache.Timeout;
                    CacheLock @lock    = lockable == null ?
                                         new CacheLock(timeout, NextLockId(), version) :
                                         lockable.Lock(timeout, NextLockId());
                    await(cache.PutAsync(key, @lock, cancellationToken)).ConfigureAwait(false);
                    return(@lock);
                }
                finally
                {
                    await(cache.UnlockAsync(key, cancellationToken)).ConfigureAwait(false);
                }
            }
        }
            public void Add(ILockable lockable)
            {
                if(locked)
                    lockable.Lock();

                lockables.Add(lockable);
            }
        /// <summary>
        /// Stop any other transactions reading or writing this item to/from
        /// the cache. Send them straight to the database instead. (The lock
        /// does time out eventually.) This implementation tracks concurrent
        /// locks by transactions which simultaneously attempt to write to an
        /// item.
        /// </summary>
        public ISoftLock Lock(CacheKey key, object version)
        {
            lock (_lockObject)
            {
                if (log.IsDebugEnabled())
                {
                    log.Debug("Invalidating: {0}", key);
                }

                try
                {
                    cache.Lock(key);

                    ILockable lockable = (ILockable)cache.Get(key);
                    long      timeout  = cache.NextTimestamp() + cache.Timeout;
                    CacheLock @lock    = lockable == null?
                                         CacheLock.Create(timeout, NextLockId(), version) :
                                             lockable.Lock(timeout, NextLockId());

                    cache.Put(key, @lock);
                    return(@lock);
                }
                finally
                {
                    cache.Unlock(key);
                }
            }
        }
Example #5
0
 private static void TryLockEntityInfo(ILockable info, bool recursive)
 {
     if (info != null)
     {
         info.Lock(recursive);
     }
 }
Example #6
0
 public void Lock()
 {
     if (theLock != null)
     {
         theLock.Lock();
         //Console.WriteLine("This door is locked.");
     }
 }
Example #7
0
 public void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.GetComponent <ILockable>() != null)
     {
         ILockable lockable = collision.GetComponent <ILockable>();
         if ((lockable as ShipLocked).GetCamp() != GetCamp())
         {
             lockable.Lock();
             targetList.Add((lockable as MonoBehaviour).transform);
         }
     }
 }
    // return was pressed, run checks now
    public void submit()
    {
        if (inputCode.Length == 0)
        {
            UpdateText(DisplayDefault);
            clearInput();
            return;
        }

        // check for controlcode first (special case)
        if (CheckCode() == false)
        {
            // failed attempt!
            availableInterface.Lock();
            UpdateText(DisplayDenied);
            if (!noAudio)
            {
                AudioDenied.Play();
            }
        }
        else
        {
            // grant access
            if (GameObjDoor.tag == "File")
            {
                GameObjDoor.transform.position = new Vector3(GameObjDoor.transform.position.x, 2.533f, GameObjDoor.transform.position.z);
            }
            else if (GameObjDoor.tag == "Door")
            {
                GameObjDoor.transform.Rotate(0, 90, 0);
            }
            UpdateText(DisplayGranted);
        }

        clearInput();
    }
Example #9
0
 public Lock(ILockable lockable)
 {
     this.lockable = lockable;
     lockable.Lock();
 }
Example #10
0
 private Lock(ILockable obj)
 {
     _obj = obj;
     _obj.Lock();
 }