/// <include file='..\..\doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Intersect"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Intersect(IPermission target)
        {
            if (target == null)
            {
                return(null);
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;

            if (this.IsUnrestricted())
            {
                return(targetQueuePermission.Copy());
            }

            if (targetQueuePermission.IsUnrestricted())
            {
                return(this.Copy());
            }

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();
            MessageQueuePermission newPermission = new MessageQueuePermission();
            Hashtable newFormatNames             = new Hashtable(GetComparer());

            newPermission.resolvedFormatNames = newFormatNames;
            IDictionaryEnumerator formatNamesEnumerator;
            Hashtable             formatNamesTable;

            if (this.resolvedFormatNames.Count < targetQueuePermission.resolvedFormatNames.Count)
            {
                formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
                formatNamesTable      = targetQueuePermission.resolvedFormatNames;
            }
            else
            {
                formatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();
                formatNamesTable      = this.resolvedFormatNames;
            }

            while (formatNamesEnumerator.MoveNext())
            {
                if (formatNamesTable.ContainsKey(formatNamesEnumerator.Key))
                {
                    string currentFormatName = (string)formatNamesEnumerator.Key;
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    MessageQueuePermissionAccess targetAccess  = (MessageQueuePermissionAccess)formatNamesTable[currentFormatName];
                    newFormatNames.Add(currentFormatName, currentAccess & targetAccess);
                }
            }

            return(newPermission);
        }
        /// <include file='..\..\doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Union"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;
            MessageQueuePermission newPermission         = new MessageQueuePermission();

            if (this.IsUnrestricted() || targetQueuePermission.IsUnrestricted())
            {
                newPermission.isUnrestricted = true;
                return(newPermission);
            }

            Hashtable newFormatNames = new Hashtable(GetComparer());

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();

            IDictionaryEnumerator formatNamesEnumerator       = this.resolvedFormatNames.GetEnumerator();
            IDictionaryEnumerator targetFormatNamesEnumerator = targetQueuePermission.resolvedFormatNames.GetEnumerator();

            while (formatNamesEnumerator.MoveNext())
            {
                newFormatNames[(string)formatNamesEnumerator.Key] = formatNamesEnumerator.Value;
            }

            while (targetFormatNamesEnumerator.MoveNext())
            {
                if (!newFormatNames.ContainsKey(targetFormatNamesEnumerator.Key))
                {
                    newFormatNames[targetFormatNamesEnumerator.Key] = targetFormatNamesEnumerator.Value;
                }
                else
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)newFormatNames[targetFormatNamesEnumerator.Key];
                    newFormatNames[targetFormatNamesEnumerator.Key] = currentAccess | (MessageQueuePermissionAccess)targetFormatNamesEnumerator.Value;
                }
            }

            newPermission.resolvedFormatNames = newFormatNames;
            return(newPermission);
        }
        /// <include file='..\..\doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.Copy"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override IPermission Copy()
        {
            MessageQueuePermission permission = new MessageQueuePermission {
                isUnrestricted = this.isUnrestricted
            };

            foreach (MessageQueuePermissionEntry entry in this.PermissionEntries)
            {
                permission.PermissionEntries.Add(entry);
            }

            permission.resolvedFormatNames = this.resolvedFormatNames;
            return(permission);
        }
        /// <include file='..\..\doc\MessageQueuePermission.uex' path='docs/doc[@for="MessageQueuePermission.IsSubsetOf"]/*' />
        /// <devdoc>
        ///    <para>[To be supplied.]</para>
        /// </devdoc>
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(false);
            }

            if (!(target is MessageQueuePermission))
            {
                throw new ArgumentException(Res.GetString(Res.InvalidParameter, "target", target.ToString()));
            }

            MessageQueuePermission targetQueuePermission = (MessageQueuePermission)target;

            if (targetQueuePermission.IsUnrestricted())
            {
                return(true);
            }
            else if (this.IsUnrestricted())
            {
                return(false);
            }

            this.ResolveFormatNames();
            targetQueuePermission.ResolveFormatNames();

            //If one of the tables is empty the subset cannot be resolved reliably, should assume
            //then that they are not subset of each other.
            if ((this.resolvedFormatNames.Count == 0 && targetQueuePermission.resolvedFormatNames.Count != 0) ||
                (this.resolvedFormatNames.Count != 0 && targetQueuePermission.resolvedFormatNames.Count == 0))
            {
                return(false);
            }

            //If the target table contains a wild card, all the current formatName access need to be
            //a subset of the target.
            IDictionaryEnumerator formatNamesEnumerator;

            if (targetQueuePermission.resolvedFormatNames.ContainsKey(Any))
            {
                MessageQueuePermissionAccess targetAccess = (MessageQueuePermissionAccess)targetQueuePermission.resolvedFormatNames[Any];
                formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
                while (formatNamesEnumerator.MoveNext())
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    if ((currentAccess & targetAccess) != currentAccess)
                    {
                        return(false);
                    }
                }

                return(true);
            }

            //If the current table contains a wild card it can be treated as any other format name.
            formatNamesEnumerator = this.resolvedFormatNames.GetEnumerator();
            while (formatNamesEnumerator.MoveNext())
            {
                string currentFormatName = (string)formatNamesEnumerator.Key;
                if (!targetQueuePermission.resolvedFormatNames.ContainsKey(currentFormatName))
                {
                    return(false);
                }
                else
                {
                    MessageQueuePermissionAccess currentAccess = (MessageQueuePermissionAccess)formatNamesEnumerator.Value;
                    MessageQueuePermissionAccess targetAccess  = (MessageQueuePermissionAccess)targetQueuePermission.resolvedFormatNames[currentFormatName];
                    if ((currentAccess & targetAccess) != currentAccess)
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
 /// <include file='..\..\doc\MessageQueuePermissionEntryCollection.uex' path='docs/doc[@for="MessageQueuePermissionEntryCollection.MessageQueuePermissionEntryCollection"]/*' />
 /// <internalonly/>
 internal MessageQueuePermissionEntryCollection(MessageQueuePermission owner)
 {
     this.owner = owner;
 }