コード例 #1
0
ファイル: ClusterHelper.cs プロジェクト: yongwuhou/NCache
        private static void ReleaseLeasable(object instance)
        {
            if (instance == null)
            {
                return;
            }

            if (instance is OperationResponse)
            {
                ReleaseCacheEntry(((OperationResponse)instance).SerializablePayload);
                return;
            }

            ILeasable leasable = instance as ILeasable;

            //for atomic
            if (leasable != null)
            {
                leasable.MarkFree(NCModulesConstants.Global);
            }
            else if (instance is IDictionary) //for bulk
            {
                foreach (object value in ((IDictionary)instance).Values)
                {
                    leasable = value as ILeasable;
                    if (leasable != null)
                    {
                        leasable.MarkFree(NCModulesConstants.Global);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Dispose the lease. No need to implement the dispose pattern since this just release the lease and is sealed
        /// </summary>
        public void Dispose()
        {
            if (this.leasable != null)
            {
                Debug.Assert(this.DataObject != null);

                this.leasable.Release();
                this.leasable   = null;
                this.DataObject = null;
            }
        }
コード例 #3
0
    public int CalculateLease(int id)
    {
        ILeasable property = _leasableRepository.GetLeasable(id);
        Type      type     = property.GetType();

        if (_calculations.TryGetValue(type, out var calculation))
        {
            return(calculation(property));
        }
        throw new Exception("Unexpected type, please extend the calculator");
    }
コード例 #4
0
        /// <summary>
        /// Initializes a new LifeTimeWrapper
        /// </summary>
        /// <param name="leasable">lease object</param>
        public AutoLease(ILeasable <T> leasable)
        {
            if (leasable == null)
            {
                throw new ArgumentNullException(nameof(leasable));
            }

            this.leasable = leasable;

            // Try to acquire a lease on the leasable object, and renew if necessary
            this.DataObject = this.leasable.Acquire();
        }
コード例 #5
0
 public void ShowLeasingCharges(int id)
 {
     leasable = leasableRepository.GetLeasable(id);
     var leasingCharge = GetLeasingCharges((T)leasable);
 }
コード例 #6
0
 public static int GetLeasingCharges(ILeasable leasable)
 => leasable is ClubHouse x