Exemplo n.º 1
0
 /// <summary>
 /// Acquires the specified request. Removes it from availability and from the resource pool.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <returns><c>true</c> if if the resource was successfully acquired, <c>false</c> otherwise.</returns>
 public bool Acquire(IResourceRequest request)
 {
     ResourceRequested?.Invoke(request, this);
     RequestEvent?.Invoke(request, this);
     lock (this) {
         if (AttemptExecution(request))
         {
             AcquiredEvent?.Invoke(request, this);
             ResourceAcquired?.Invoke(request, this);
             return(true);
         }
         else
         {
             return(false);
         }
     }
 }
Exemplo n.º 2
0
        public bool Acquire(IResourceRequest request)
        {
            IResource originator = m_wrappedByWhom ?? this;

            RequestEvent?.Invoke(request, originator);
            lock (this) {
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                if (request.QuantityObtained != 0.0)
                {
                    request.Unreserve();
                }
                if (AttemptRemovalFromService(request))
                {
                    AcquiredEvent?.Invoke(request, originator);
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }