Beispiel #1
0
    // Print the properties of the specified code group to the console.
    private static void PrintCodeGroup(CodeGroup codeGroup)
    {
        // Compare the type of the specified object with the FileCodeGroup
        // type.
        if (!codeGroup.GetType().Equals(typeof(FileCodeGroup)))
        {
            throw new ArgumentException("Expected the FileCodeGroup type.");
        }

        string codeGroupName       = codeGroup.Name;
        string membershipCondition = codeGroup.MembershipCondition.ToString();
        string permissionSetName   = codeGroup.PermissionSetName;

        int hashCode = codeGroup.GetHashCode();

        string mergeLogic = "";

        if (codeGroup.MergeLogic.Equals("Union"))
        {
            mergeLogic = " with Union merge logic";
        }

        // Retrieve the class path for FileCodeGroup.
        string fileGroupClass = codeGroup.ToString();

        // Write summary to the console window.
        Console.WriteLine("\n*** " + fileGroupClass + " summary ***");
        Console.Write("A FileCodeGroup named ");
        Console.Write(codeGroupName + mergeLogic);
        Console.Write(" has been created with hash code" + hashCode + ".");
        Console.Write("This code group contains a " + membershipCondition);
        Console.Write(" membership condition with the ");
        Console.Write(permissionSetName + " permission set. ");

        Console.Write("The code group has the following security policy: ");
        Console.WriteLine(ResolveEvidence(codeGroup));


        int childCount = codeGroup.Children.Count;

        if (childCount > 0)
        {
            Console.Write("There are " + childCount);
            Console.WriteLine(" child code groups in this code group.");

            // Iterate through the child code groups to display their names
            // and remove them from the specified code group.
            for (int i = 0; i < childCount; i++)
            {
                // Get child code group as type FileCodeGroup.
                FileCodeGroup childCodeGroup =
                    (FileCodeGroup)codeGroup.Children[i];

                Console.Write("Removing the " + childCodeGroup.Name + ".");
                // Remove child code group.
                codeGroup.RemoveChild(childCodeGroup);
            }

            Console.WriteLine();
        }
        else
        {
            Console.Write("There are no child code groups");
            Console.WriteLine(" in this code group.");
        }
    }
Beispiel #2
0
    // Print the properties of the specified code group to the console.
    private static void PrintCodeGroup(CodeGroup codeGroup)
    {
        // Compare the type of the specified object with the
        // FirstMatchCodeGroup type.
        //<Snippet12>
        if (!codeGroup.GetType().Equals(typeof(FirstMatchCodeGroup)))
        //</Snippet12>
        {
            throw new ArgumentException(
                      "Expected the FirstMatchCodeGroup type.");
        }

        string codeGroupName       = codeGroup.Name;
        string membershipCondition = codeGroup.MembershipCondition.ToString();
        //<Snippet13>
        string permissionSetName = codeGroup.PermissionSetName;
        //</Snippet13>

        //<Snippet14>
        int hashCode = codeGroup.GetHashCode();
        //</Snippet14>

        string mergeLogic = "";

        //<Snippet15>
        if (codeGroup.MergeLogic.Equals("First Match"))
        //</Snippet15>
        {
            mergeLogic = "with first-match merge logic";
        }

        // Retrieve the class path for the FirstMatchCodeGroup.
        //<Snippet16>
        string firstMatchGroupClass = codeGroup.ToString();
        //</Snippet16>

        string attributeString = "";

        // Retrieve the string representation of the FirstMatchCodeGroup's
        // attributes.
        //<Snippet5>
        if (codeGroup.AttributeString != null)
        {
            attributeString = codeGroup.AttributeString;
        }
        //</Snippet5>

        // Write a summary to the console window.
        Console.WriteLine("\n*** " + firstMatchGroupClass + " summary ***");
        Console.Write("A FirstMatchCodeGroup named ");
        Console.Write(codeGroupName + mergeLogic);
        Console.Write(" has been created with hash code(" + hashCode + ").");
        Console.Write("\nThis code group contains a " + membershipCondition);
        Console.Write(" membership condition with the ");
        Console.WriteLine(permissionSetName + " permission set.");

        Console.Write("The code group contains the following policy: ");
        Console.Write(ResolveEvidence(codeGroup));
        Console.Write("\nIt also contains the following attributes: ");
        Console.WriteLine(attributeString);

        int childCount = codeGroup.Children.Count;

        if (childCount > 0)
        {
            Console.Write("There are " + childCount);
            Console.WriteLine(" child elements in the code group.");

            // Iterate through the child code groups to display their names
            // and then remove them from the specified code group.
            for (int i = 0; i < childCount; i++)
            {
                // Retrieve a child code group, which has been cast as a
                // FirstMatchCodeGroup type.
                //<Snippet21>
                FirstMatchCodeGroup childCodeGroup =
                    (FirstMatchCodeGroup)codeGroup.Children[i];
                //</Snippet21>

                Console.Write("Removing the " + childCodeGroup.Name + ".");
                // Remove the child code group.
                //<Snippet17>
                codeGroup.RemoveChild(childCodeGroup);
                //</Snippet17>
            }

            Console.WriteLine();
        }
        else
        {
            Console.WriteLine(" No child code groups were found in this" +
                              " code group.");
        }
    }