// ToXml creates an XML encoding of the permission and its current state; FromXml reconstructs a
// permission with the specified state from the XML encoding.
private bool ToFromXmlDemo()
{
}
// Test harness.
public static void Main(String[] args)
{
try
{
SiteIdentityPermissionDemo testcase = new SiteIdentityPermissionDemo();
bool returnCode = testcase.RunDemo();
if (returnCode)
{
Console.Out.WriteLine("The SiteIdentityPermission demo completed successfully.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 100;
}
else
{
Console.Out.WriteLine("The SiteIdentityPermission demo failed.");
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
catch(Exception e)
{
Console.Out.WriteLine("The SiteIdentityPermission demo failed.");
Console.WriteLine(e.ToString());
Console.Out.WriteLine("Press the Enter key to exit.");
string consoleInput = Console.ReadLine();
System.Environment.ExitCode = 101;
}
}
}
// This class generates SiteIdentityPermission objects.
internal class SiteGenerator
{
private string[] siteArray =
// Replace this array with web sites of your own choosing.
{"www.northwindtraders.northwindtraders.com",
"*.northwindtraders.com",
"*.margiestravel.com","northwindtraders.com",
"*northwindtraders.com",""};
private int siteIndex = 0;
public SiteGenerator()
{
ResetIndex();
}
public void ResetIndex()
{
siteIndex = 0;
}
// CreateSite creates a SiteIdentityPermission.
public bool CreateSite(out SiteIdentityPermission sitePerm, out string site, out bool successFlag)
{
// Intersect creates and returns a new permission that is the intersection of the
// current permission and the permission specified.
private bool IntersectDemo()
{
// This sample demonstrates the IsSubsetOf, Union, Intersect, Copy, ToXml and FromXml methods
// of the SiteIdentityPermission class.
using System;
using System.Security;
using System.Security.Permissions;
[assembly:CLSCompliant(true)]
public class SiteIdentityPermissionDemo
{
// IsSubsetOf determines whether the current permission is a subset of the specified permission.
private bool IsSubsetOfDemo()
{
bool returnCodeCode = true;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
siteGen1.ResetIndex();
while(siteGen1.CreateSite(out siteIdPerm1, out site1, out successFlag))
{
if(siteIdPerm1 == null | successFlag == false) continue;
siteGen2.ResetIndex();
Console.WriteLine("**************************************************************************");
while(siteGen2.CreateSite(out siteIdPerm2, out site2, out successFlag))
{
try
{
if(siteIdPerm2 == null | successFlag == false) continue;
if(siteIdPerm1.IsSubsetOf(siteIdPerm2))
{
Console.WriteLine(site1 + " is a subset of " + site2);
}
else
{
Console.WriteLine(site1 + " is not a subset of " + site2);
}
// Union creates a new permission that is the union of the current permission
// and the specified permission.
private bool UnionDemo()
{
bool returnCodeCode = true;
String site1,site2;
bool successFlag;
SiteIdentityPermission siteIdPerm1,siteIdPerm2,p3;
SiteGenerator siteGen1 = new SiteGenerator();
SiteGenerator siteGen2 = new SiteGenerator();
if(p3 != null)
{
Console.WriteLine("The union of " + firstSite + " and \n\t" + secondSite + " = \n\t"
+ thirdSite + "\n");
}
else
{
Console.WriteLine("The union of " + firstSite + " and \n\t" + secondSite + " = null.\n");
}
}
catch
{
// Expected exception, result of the union is null.
Console.WriteLine("The union of " + firstSite + " and \n\t" + secondSite + " = null.\n");