Exemple #1
0
        /// <summary>
        /// Pops the top access regulator from the stack associated with the specified resource, or from the
        /// default stack if subject is set as null.
        /// </summary>
        /// <param name="subject">The resource to be regulated, or null if all are to be regulated.</param>
        /// <returns>The AccessRegulator being popped, or null, if the stack was empty.</returns>
        public IAccessRegulator PopAccessRegulator(IResource subject)
        {
            IAccessRegulator retval = null;

            if (subject == null)
            {
                retval = (IAccessRegulator)m_defaultAccessRegulators.Pop();
                if (m_defaultAccessRegulators.Count == 0 && m_autoDeleteEmptyStacks)
                {
                    m_defaultAccessRegulators = null;
                }
            }
            else
            {
                Stack stack = (Stack)m_monitoredObjects[subject];
                if (stack != null)
                {
                    retval = (IAccessRegulator)stack.Pop();
                    if (m_autoDeleteEmptyStacks && stack.Count == 0)
                    {
                        m_monitoredObjects.Remove(subject);
                    }
                }
            }
            return(retval);
        }
Exemple #2
0
        /// <summary>
        /// Returns true if the given subject can be acquired using the presented key.
        /// </summary>
        /// <param name="subject">The resource whose acquisition is being queried.</param>
        /// <param name="usingKey">The key that is to be presented by the prospective acquirer.</param>
        /// <returns>True if the acquire will be allowed, false if not.</returns>
        public bool CanAcquire(object subject, object usingKey)
        {
            Stack myStack = (Stack)m_monitoredObjects[subject];

            if (myStack != null)
            {
                IAccessRegulator iar = (IAccessRegulator)myStack.Peek();
                return(iar == null || iar.CanAcquire(subject, usingKey));
            }
            else
            {
                if (m_defaultAccessRegulators == null || m_defaultAccessRegulators.Count == 0)
                {
                    return(true);
                }
                IAccessRegulator iar = (IAccessRegulator)m_defaultAccessRegulators.Peek();
                return(iar.CanAcquire(subject, usingKey));
            }
        }
Exemple #3
0
 /// <summary>
 /// Pushes an access regulator onto the stack that is associated with a particular resource, or
 /// the default stack, if no resource is specified.
 /// </summary>
 /// <param name="accReg">Access Regulator to be pushed.</param>
 /// <param name="subject">The resource to which this regulator is to apply, or null, if it applies to all of them.</param>
 public void PushAccessRegulator(IAccessRegulator accReg, IResource subject)
 {
     if (subject == null)
     {
         if (m_defaultAccessRegulators == null)
         {
             m_defaultAccessRegulators = new Stack();
         }
         m_defaultAccessRegulators.Push(accReg);
     }
     else
     {
         Stack stack = (Stack)m_monitoredObjects[subject];
         if (stack == null)
         {
             stack = new Stack();
             m_monitoredObjects.Add(subject, stack);
         }
         stack.Push(accReg);
     }
 }