Inheritance: System.Security.CodeAccessPermission, IUnrestrictedPermission
 public override IPermission CreatePermission()
 {
     NetworkInformationPermission perm = null;
     if (Unrestricted) {
         perm = new NetworkInformationPermission(PermissionState.Unrestricted);
     }
     else {
         perm = new NetworkInformationPermission(PermissionState.None);
         if (access != null) {
             if (0 == string.Compare(access, "Read", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.Read);
             }
             else if (0 == string.Compare(access, "Ping", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.Ping);
             }
             else if (0 == string.Compare(access, "None", StringComparison.OrdinalIgnoreCase)) {
                 perm.AddPermission(NetworkInformationAccess.None);
             }
             else {
                 throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val, strAccess, access));
             }
         }
     }
     return perm;
 }
 public override IPermission CreatePermission()
 {
     NetworkInformationPermission permission = null;
     if (base.Unrestricted)
     {
         return new NetworkInformationPermission(PermissionState.Unrestricted);
     }
     permission = new NetworkInformationPermission(PermissionState.None);
     if (this.access != null)
     {
         if (string.Compare(this.access, "Read", StringComparison.OrdinalIgnoreCase) == 0)
         {
             permission.AddPermission(NetworkInformationAccess.Read);
             return permission;
         }
         if (string.Compare(this.access, "Ping", StringComparison.OrdinalIgnoreCase) == 0)
         {
             permission.AddPermission(NetworkInformationAccess.Ping);
             return permission;
         }
         if (string.Compare(this.access, "None", StringComparison.OrdinalIgnoreCase) != 0)
         {
             throw new ArgumentException(SR.GetString("net_perm_invalid_val", new object[] { "Access", this.access }));
         }
         permission.AddPermission(NetworkInformationAccess.None);
     }
     return permission;
 }
Ejemplo n.º 3
0
        public override IPermission CreatePermission()
        {
            NetworkInformationPermission perm = null;

            if (Unrestricted)
            {
                perm = new NetworkInformationPermission(PermissionState.Unrestricted);
            }
            else
            {
                perm = new NetworkInformationPermission(PermissionState.None);
                if (access != null)
                {
                    if (0 == string.Compare(access, "Read", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.Read);
                    }
                    else if (0 == string.Compare(access, "Ping", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.Ping);
                    }
                    else if (0 == string.Compare(access, "None", StringComparison.OrdinalIgnoreCase))
                    {
                        perm.AddPermission(NetworkInformationAccess.None);
                    }
                    else
                    {
                        throw new ArgumentException(SR.GetString(SR.net_perm_invalid_val, strAccess, access));
                    }
                }
            }
            return(perm);
        }
        public override IPermission CreatePermission()
        {
            NetworkInformationPermission permission = null;

            if (base.Unrestricted)
            {
                return(new NetworkInformationPermission(PermissionState.Unrestricted));
            }
            permission = new NetworkInformationPermission(PermissionState.None);
            if (this.access != null)
            {
                if (string.Compare(this.access, "Read", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    permission.AddPermission(NetworkInformationAccess.Read);
                    return(permission);
                }
                if (string.Compare(this.access, "Ping", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    permission.AddPermission(NetworkInformationAccess.Ping);
                    return(permission);
                }
                if (string.Compare(this.access, "None", StringComparison.OrdinalIgnoreCase) != 0)
                {
                    throw new ArgumentException(SR.GetString("net_perm_invalid_val", new object[] { "Access", this.access }));
                }
                permission.AddPermission(NetworkInformationAccess.None);
            }
            return(permission);
        }
Ejemplo n.º 5
0
        public override bool IsSubsetOf(IPermission target)
        {
            // Pattern suggested by security engine
            if (target == null)
            {
                return(access == NetworkInformationAccess.None);
            }

            NetworkInformationPermission other = target as NetworkInformationPermission;

            if (other == null)
            {
                throw new ArgumentException(SR.GetString(SR.net_perm_target), "target");
            }

            if (unrestricted && !other.IsUnrestricted())
            {
                return(false);
            }
            else if ((access & other.access) == access)
            {
                return(true);
            }
            return(false);
        }
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            NetworkInformationPermission permission = target as NetworkInformationPermission;

            if (permission == null)
            {
                throw new ArgumentException(SR.GetString("net_perm_target"), "target");
            }
            if (!this.unrestricted && !permission.IsUnrestricted())
            {
                return(new NetworkInformationPermission(this.access | permission.access));
            }
            return(new NetworkInformationPermission(true));
        }
        public override bool IsSubsetOf(IPermission target)
        {
            if (target == null)
            {
                return(this.access == NetworkInformationAccess.None);
            }
            NetworkInformationPermission permission = target as NetworkInformationPermission;

            if (permission == null)
            {
                throw new ArgumentException(SR.GetString("net_perm_target"), "target");
            }
            if (this.unrestricted && !permission.IsUnrestricted())
            {
                return(false);
            }
            return((this.access & permission.access) == this.access);
        }
Ejemplo n.º 8
0
        public override IPermission Union(IPermission target)
        {
            if (target == null)
            {
                return(this.Copy());
            }
            NetworkInformationPermission other = target as NetworkInformationPermission;

            if (other == null)
            {
                throw new ArgumentException(SR.GetString(SR.net_perm_target), "target");
            }

            if (unrestricted || other.IsUnrestricted())
            {
                return(new NetworkInformationPermission(true));
            }

            return(new NetworkInformationPermission(this.access | other.access));
        }
Ejemplo n.º 9
0
        public static void CreatePermission()
        {
            //<Snippet6>
            //<Snippet5>
            //<Snippet2>
            //<Snippet1>
            System.Net.NetworkInformation.NetworkInformationPermission unrestricted =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Security.Permissions.PermissionState.Unrestricted);
            //</Snippet1>

            Console.WriteLine("Is unrestricted? " + unrestricted.IsUnrestricted());
            //</Snippet2>

            //<Snippet4>
            //<Snippet3>
            System.Net.NetworkInformation.NetworkInformationPermission read =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Net.NetworkInformation.NetworkInformationAccess.Read);
            //</Snippet3>
            System.Net.NetworkInformation.NetworkInformationPermission copyPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Copy();
            //</Snippet4>
            System.Net.NetworkInformation.NetworkInformationPermission unionPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Union(unrestricted);
            Console.WriteLine("Is subset?" + read.IsSubsetOf(unionPermission));
            //</Snippet5>
            System.Net.NetworkInformation.NetworkInformationPermission intersectPermission =
                (System.Net.NetworkInformation.NetworkInformationPermission)read.Intersect(unrestricted);
            //</Snippet6>

            //<Snippet7>
            System.Net.NetworkInformation.NetworkInformationPermission permission =
                new System.Net.NetworkInformation.NetworkInformationPermission(
                    System.Security.Permissions.PermissionState.None);
            permission.AddPermission(
                System.Net.NetworkInformation.NetworkInformationAccess.Read);
            Console.WriteLine("Access is {0}", permission.Access);
            //</Snippet7>
        }