Esempio n. 1
0
    //</Snippet8>

    // The following method is intended to demonstrate only the behavior of
    // StorePermission class members,and not their practical usage.  Most properties
    // and methods in this class are used for the resolution and enforcement of
    // security policy by the security infrastructure code.
    private static void ShowMembers()
    {
        Console.WriteLine("Creating first permission with Flags = OpenStore.");

        StorePermission sp1 = new StorePermission(StorePermissionFlags.OpenStore);

        Console.WriteLine("Creating second permission with Flags = AllFlags.");

        StorePermission sp2 = new StorePermission(StorePermissionFlags.AllFlags);

        Console.WriteLine("Creating third permission as Unrestricted.");
        //<Snippet9>
        StorePermission sp3 = new StorePermission(PermissionState.Unrestricted);

        //</Snippet9>
        Console.WriteLine("Creating fourth permission with a permission state of none.");

        StorePermission sp4 = new StorePermission(PermissionState.None);
        //<Snippet3>
        bool rc = sp2.IsSubsetOf(sp3);

        Console.WriteLine("Is the permission with complete store access (AllFlags) a subset of \n" +
                          "\tthe permission with an Unrestricted permission state? " + (rc ? "Yes" : "No"));
        rc = sp1.IsSubsetOf(sp2);
        Console.WriteLine("Is the permission with OpenStore access a subset of the permission with \n" +
                          "\tcomplete store access (AllFlags)? " + (rc ? "Yes" : "No"));
        //</Snippet3>
        //<Snippet4>
        rc = sp3.IsUnrestricted();
        Console.WriteLine("Is the third permission unrestricted? " + (rc ? "Yes" : "No"));
        //</Snippet4>
        //<Snippet5>
        Console.WriteLine("Copying the second permission to the fourth permission.");
        sp4 = (StorePermission)sp2.Copy();
        rc  = sp4.Equals(sp2);
        Console.WriteLine("Is the fourth permission equal to the second permission? " + (rc ? "Yes" : "No"));

        //</Snippet5>
        //<Snippet10>
        Console.WriteLine("Creating the intersection of the second and first permissions.");
        sp4 = (StorePermission)sp2.Intersect(sp1);
        Console.WriteLine("Value of the Flags property is: " + sp4.Flags.ToString());

        //</Snippet10>
        //<Snippet6>
        Console.WriteLine("Creating the union of the second and first permissions.");
        sp4 = (StorePermission)sp2.Union(sp1);
        Console.WriteLine("Result of the union of the second permission with the first:  " + sp4.Flags);

        //</Snippet6>
        //<Snippet7>
        Console.WriteLine("Using an XML roundtrip to reset the fourth permission.");
        sp4.FromXml(sp2.ToXml());
        rc = sp4.Equals(sp2);
        Console.WriteLine("Does the XML roundtrip result equal the original permission? " + (rc ? "Yes" : "No"));
        //</Snippet7>
    }