Push() private method

private Push ( CodeGroupStackFrame element ) : void
element CodeGroupStackFrame
return void
 private ArrayList GenericResolve(Evidence evidence, out bool allConst)
 {
     CodeGroupStack stack = new CodeGroupStack();
     CodeGroup rootCodeGroup = this.m_rootCodeGroup;
     if (rootCodeGroup == null)
     {
         throw new PolicyException(Environment.GetResourceString("Policy_NonFullTrustAssembly"));
     }
     CodeGroupStackFrame element = new CodeGroupStackFrame {
         current = rootCodeGroup,
         parent = null
     };
     stack.Push(element);
     ArrayList list = new ArrayList();
     bool flag = false;
     allConst = true;
     Exception exception = null;
     while (!stack.IsEmpty())
     {
         element = stack.Pop();
         FirstMatchCodeGroup current = element.current as FirstMatchCodeGroup;
         UnionCodeGroup group3 = element.current as UnionCodeGroup;
         if (!(element.current.MembershipCondition is IConstantMembershipCondition) || ((group3 == null) && (current == null)))
         {
             allConst = false;
         }
         try
         {
             element.policy = PolicyManager.ResolveCodeGroup(element.current, evidence);
         }
         catch (Exception exception2)
         {
             if (exception == null)
             {
                 exception = exception2;
             }
         }
         if (element.policy != null)
         {
             if ((element.policy.Attributes & PolicyStatementAttribute.Exclusive) != PolicyStatementAttribute.Nothing)
             {
                 if (flag)
                 {
                     throw new PolicyException(Environment.GetResourceString("Policy_MultipleExclusive"));
                 }
                 list.RemoveRange(0, list.Count);
                 list.Add(element);
                 flag = true;
             }
             if (!flag)
             {
                 list.Add(element);
             }
         }
     }
     if (exception != null)
     {
         throw exception;
     }
     return list;
 }
        [System.Security.SecurityCritical]  // auto-generated
        private ArrayList GenericResolve(Evidence evidence, out bool allConst) {
            CodeGroupStack stack = new CodeGroupStack();

            // Note: if m_rootCodeGroup is null it means that we've
            // hit a recursive load case and ended up needing to
            // do a resolve on an assembly used in policy but is
            // not covered by the full trust assemblies list.  We'll
            // throw a policy exception to cover this case.

            CodeGroupStackFrame frame;
            CodeGroup rootCodeGroupRef = m_rootCodeGroup;

            if (rootCodeGroupRef == null)
                throw new PolicyException(Environment.GetResourceString("Policy_NonFullTrustAssembly"));

            frame = new CodeGroupStackFrame();
            frame.current = rootCodeGroupRef;
            frame.parent = null;

            stack.Push(frame);

            ArrayList accumulator = new ArrayList();

            bool foundExclusive = false;

            allConst = true;

            Exception storedException = null;

            while (!stack.IsEmpty()) {
                frame = stack.Pop();

                FirstMatchCodeGroup firstMatchGroup = frame.current as FirstMatchCodeGroup;
                UnionCodeGroup unionGroup = frame.current as UnionCodeGroup;

                if (!(frame.current.MembershipCondition is IConstantMembershipCondition) ||
                    (unionGroup == null && firstMatchGroup == null)) {
                    allConst = false;
                }

                try {
                    frame.policy = PolicyManager.ResolveCodeGroup(frame.current, evidence);
                }
                catch (Exception e) {
                    // If any exception occurs while attempting a resolve, we catch it here and
                    // set the equivalent of the resolve not matching to the evidence.
                    //frame.policy = null;

                    if (storedException == null)
                        storedException = e;
                }

                if (frame.policy != null) {                    
                    if ((frame.policy.Attributes & PolicyStatementAttribute.Exclusive) != 0) {
                        if (foundExclusive)
                            throw new PolicyException(Environment.GetResourceString("Policy_MultipleExclusive"));

                        accumulator.RemoveRange(0, accumulator.Count);
                        accumulator.Add(frame);
                        foundExclusive = true;
                    }

                    if (!foundExclusive) {
                        accumulator.Add(frame);
                    }
                }
            }

            if (storedException != null)
                throw storedException;

            return accumulator;
        }
示例#3
0
        private ArrayList GenericResolve( Evidence evidence, out bool allConst )
        {
            CodeGroupStack stack = new CodeGroupStack();
            
            // Note: if m_rootCodeGroup is null it means that we've
            // hit a recursive load case and ended up needing to
            // do a resolve on an assembly used in policy but is
            // not covered by the full trust assemblies list.  We'll
            // throw a policy exception to cover this case.

            CodeGroupStackFrame frame;
            CodeGroup rootCodeGroupRef = m_rootCodeGroup;

            if (rootCodeGroupRef == null)
                throw new PolicyException( Environment.GetResourceString( "Policy_NonFullTrustAssembly" ) );

            frame = new CodeGroupStackFrame();
            frame.current = rootCodeGroupRef;
            frame.parent = null;

            stack.Push( frame );
            
            ArrayList accumulator = new ArrayList();
            
            bool foundExclusive = false;
            
            allConst = true;

            Exception storedException = null;
            
            while (!stack.IsEmpty())
            {
                frame = stack.Pop();
                
#if _DEBUG
                if (debug)          
                    DEBUG_OUT( "Current frame =\n" + frame.current.ToXml().ToString() );
#endif
                
                UnionCodeGroup unionGroup = frame.current as UnionCodeGroup;
                NetCodeGroup netGroup = frame.current as NetCodeGroup;
                FileCodeGroup fileGroup = frame.current as FileCodeGroup;

                if (!(frame.current.MembershipCondition is IConstantMembershipCondition) || !(unionGroup != null || netGroup != null || fileGroup != null))
                {
                    allConst = false;
                }
         
                try
                {
                    if (unionGroup != null)
                        frame.policy = unionGroup.InternalResolve( evidence );
                    else if (netGroup != null)
                        frame.policy = netGroup.InternalResolve( evidence );
                    else if (fileGroup != null)
                        frame.policy = fileGroup.InternalResolve( evidence );
                    else
                        frame.policy = frame.current.Resolve( evidence );
                }
                catch (Exception e)
                {
                    // If any exception occurs while attempting a resolve, we catch it here and
                    // set the equivalent of the resolve not matching to the evidence.
                    //frame.policy = null;

                    if (storedException == null)
                        storedException = e;
                }
    
#if _DEBUG
                if (debug)          
                    DEBUG_OUT( "Check gives =\n" + (frame.policy == null ? "<null>" : frame.policy.ToXml().ToString() ) );
#endif
                    
                if (frame.policy != null)
                {
                    if ((frame.policy.Attributes & PolicyStatementAttribute.Exclusive) != 0)
                    {
#if _DEBUG
                        if (debug)          
                            DEBUG_OUT( "Discovered exclusive group" );
#endif
                        
                        if (foundExclusive)
                        {
                            throw new PolicyException( Environment.GetResourceString( "Policy_MultipleExclusive" ) );
                        }
                        else
                        {
                            accumulator.RemoveRange( 0, accumulator.Count );
                        
                            accumulator.Add( frame );
                       
                            foundExclusive = true;
                        }
                    }
                    
                    // We unroll the recursion in the case where we have UnionCodeGroups or NetCodeGroups.  

                    

                    if (unionGroup != null || netGroup != null || fileGroup != null)
                    {
                        IList children = ((CodeGroup)frame.current).GetChildrenInternal();
                   
                        if (children != null && children.Count > 0)
                        {
                            IEnumerator enumerator = children.GetEnumerator();
                                
                            while (enumerator.MoveNext())
                            {
#if _DEBUG
                                if (debug)          
                                    DEBUG_OUT( "Pushing =\n" + ((CodeGroup)enumerator.Current).ToXml().ToString());
#endif
                                    
                                CodeGroupStackFrame newFrame = new CodeGroupStackFrame();
                                    
                                newFrame.current = (CodeGroup)enumerator.Current;
                                newFrame.parent = frame;
                                    
                                stack.Push( newFrame );
                            }
                        }
                    }
                    
                    if (!foundExclusive)
                    {
                        accumulator.Add( frame );
                    }
                }
            }

            if (storedException != null)
                throw storedException;
        
            return accumulator;    
        }