本文整理汇总了C#中System.Security.Policy.PolicyStatement.FromXml方法的典型用法代码示例。如果您正苦于以下问题:C# PolicyStatement.FromXml方法的具体用法?C# PolicyStatement.FromXml怎么用?C# PolicyStatement.FromXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Policy.PolicyStatement
的用法示例。
在下文中一共展示了PolicyStatement.FromXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PolicyStatementCallMethods
public static void PolicyStatementCallMethods()
{
PolicyStatement ps = new PolicyStatement(new PermissionSet(new PermissionState()));
PolicyStatement ps2 = ps.Copy();
bool equals = ps.Equals(ps2);
int hash = ps.GetHashCode();
SecurityElement se = new SecurityElement("");
PolicyLevel pl = (PolicyLevel)Activator.CreateInstance(typeof(PolicyLevel), true);
ps.FromXml(se);
ps.FromXml(se, pl);
se = ps.ToXml();
se = ps.ToXml(pl);
}
示例2: CalculatePolicy
internal PolicyStatement CalculatePolicy( String host, String scheme, String port )
{
SecurityElement webPerm = CreateWebPermission( host, scheme, port );
SecurityElement root = new SecurityElement( "PolicyStatement" );
SecurityElement permSet = new SecurityElement( "PermissionSet" );
permSet.AddAttribute( "class", "System.Security.PermissionSet" );
permSet.AddAttribute( "version", "1" );
if (webPerm != null)
permSet.AddChild( webPerm );
root.AddChild( permSet );
PolicyStatement policy = new PolicyStatement();
policy.FromXml( root );
return policy;
}
示例3: FromXml
public void FromXml (SecurityElement element) {
if (element == null)
throw new ArgumentNullException("element");
if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
#if FEATURE_CLICKONCE
m_appTrustedToRun = false;
string isAppTrustedToRun = element.Attribute("TrustedToRun");
if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0) {
m_appTrustedToRun = true;
}
m_persist = false;
string persist = element.Attribute("Persist");
if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0) {
m_persist = true;
}
m_appId = null;
string fullName = element.Attribute("FullName");
if (fullName != null && fullName.Length > 0) {
m_appId = new ApplicationIdentity(fullName);
}
#endif // FEATURE_CLICKONCE
m_psDefaultGrant = null;
m_grantSetSpecialFlags = 0;
SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
if (elDefaultGrant != null) {
SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
if (elDefaultGrantPS != null) {
PolicyStatement ps = new PolicyStatement(null);
ps.FromXml(elDefaultGrantPS);
m_psDefaultGrant = ps;
m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(ps.PermissionSet, null);
}
}
List<StrongName> fullTrustAssemblies = new List<StrongName>();
SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
while (enumerator.MoveNext()) {
StrongName fullTrustAssembly = new StrongName();
fullTrustAssembly.FromXml(enumerator.Current as SecurityElement);
fullTrustAssemblies.Add(fullTrustAssembly);
}
}
m_fullTrustAssemblies = fullTrustAssemblies.AsReadOnly();
#if FEATURE_CLICKONCE
m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
#endif // FEATURE_CLICKONCE
}
示例4: CheckCache
[System.Security.SecurityCritical] // auto-generated
private PolicyStatement CheckCache (int count, byte[] serializedEvidence) {
if (m_configId == ConfigId.None)
return null;
if (serializedEvidence == null)
return null;
byte[] cachedValue;
if (!Config.GetCacheEntry(m_configId, count, serializedEvidence, out cachedValue))
return null;
PolicyStatement cachedSet = new PolicyStatement();
SecurityDocument doc = new SecurityDocument(cachedValue);
cachedSet.FromXml(doc, 0, null, true);
return cachedSet;
}
示例5: CheckCache
private PolicyStatement CheckCache(int count, byte[] serializedEvidence)
{
byte[] buffer;
if (this.m_configId == System.Security.Policy.ConfigId.None)
{
return null;
}
if (!Config.GetCacheEntry(this.m_configId, count, serializedEvidence, out buffer))
{
return null;
}
PolicyStatement statement = new PolicyStatement();
SecurityDocument doc = new SecurityDocument(buffer);
statement.FromXml(doc, 0, null, true);
return statement;
}
示例6: CalculatePolicy
private PolicyStatement CalculatePolicy( String host, String scheme )
{
//
//
SecurityElement socketPerm = null;
SecurityElement webPerm = CreateWebPermission( host, scheme );
// Now build the policy statement
SecurityElement root = new SecurityElement( "PolicyStatement" );
SecurityElement permSet = new SecurityElement( "PermissionSet" );
permSet.AddAttribute( "class", "System.Security.PermissionSet" );
permSet.AddAttribute( "version", "1" );
if (webPerm != null)
permSet.AddChild( webPerm );
if (socketPerm != null)
permSet.AddChild( socketPerm );
root.AddChild( permSet );
PolicyStatement policy = new PolicyStatement();
policy.FromXml( root );
return policy;
}
示例7: ParsePolicy
private void ParsePolicy()
{
// There is a potential deadlock situation here
// since the PolicyStatement.FromXml method calls
// into PolicyLevel and we are holding this CodeGroup's lock.
// We solve this by releasing the lock for the duration of
// the FromXml call, but this leads us into some race conditions
// with other threads trying to alter the state of this object.
// The trickiest of these is the case from FromXml gets called on
// this object, in which case we will loop and try the decode again.
while (true)
{
PolicyStatement policy = new PolicyStatement();
bool needToParse = false;
SecurityElement elPolicy = new SecurityElement( "PolicyStatement" );
elPolicy.AddAttribute( "version", "1" );
SecurityElement localRef = m_element;
lock (this)
{
// We create an xml representation of a policy statement from the
// xml for a code group. We do this to hide the policy statement from
// users in the config file.
if (m_element != null)
{
String permSetName = m_element.Attribute( "PermissionSetName" );
if (permSetName != null)
{
elPolicy.AddAttribute( "PermissionSetName", permSetName );
needToParse = true;
}
else
{
SecurityElement elPermSet = m_element.SearchForChildByTag( "PermissionSet" );
if (elPermSet != null)
{
elPolicy.AddChild( elPermSet );
needToParse = true;
}
else
{
elPolicy.AddChild( new PermissionSet( false ).ToXml() );
needToParse = true;
}
}
String attributes = m_element.Attribute( "Attributes" );
if (attributes != null)
{
elPolicy.AddAttribute( "Attributes", attributes );
needToParse = true;
}
}
}
if (needToParse)
policy.FromXml( elPolicy, m_parentLevel );
else
policy.PermissionSet = null;
lock (this)
{
if (localRef == m_element && m_policy == null)
{
m_policy = policy;
break;
}
else if (m_policy != null)
{
break;
}
}
}
if (m_policy != null && m_children != null && m_membershipCondition != null)
{
//m_element = null;
//m_parentLevel = null;
}
}
示例8: CheckCache
private PolicyStatement CheckCache( int count, char[] serializedEvidence, out bool xmlError )
{
BCLDebug.Assert( m_configId != ConfigId.None, "PolicyLevels must have a valid config id to check the cache" );
char[] cachedValue;
PolicyStatement cachedSet = null;
xmlError = false;
if (!Config.GetCacheEntry( m_configId, count, serializedEvidence, out cachedValue ))
{
return null;
}
else
{
BCLDebug.Assert( cachedValue != null, "GetCacheData returned success but cached value is null" );
cachedSet = new PolicyStatement();
Parser parser = null;
try
{
parser = new Parser( cachedValue );
cachedSet.FromXml( parser.GetTopElement() );
return cachedSet;
}
catch (XmlSyntaxException)
{
BCLDebug.Assert( false, "XmlSyntaxException in CheckCache" );
xmlError = true;
return null;
}
}
}
示例9: ToFromXml_RoundTrip
public void ToFromXml_RoundTrip ()
{
PolicyStatement ps1 = new PolicyStatement (Unrestricted, PolicyStatementAttribute.All);
SecurityElement se = ps1.ToXml ();
PolicyStatement ps2 = new PolicyStatement (null);
ps2.FromXml (se, null);
Assert.AreEqual (ps1.ToXml ().ToString (), ps2.ToXml ().ToString (), "Xml");
}
示例10: ToFromXml_PolicyLevelNull
public void ToFromXml_PolicyLevelNull ()
{
PolicyStatement ps = new PolicyStatement (null);
SecurityElement se = ps.ToXml (null);
ps.FromXml (se, null);
}
示例11: FromXml_BadSecurityElement
public void FromXml_BadSecurityElement ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (new SecurityElement ("Bad"));
}
示例12: FromXml_SecurityElementNull
public void FromXml_SecurityElementNull ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (null, PolicyLevel.CreateAppDomainLevel ());
}
示例13: FromXml_Null
public void FromXml_Null ()
{
PolicyStatement ps = new PolicyStatement (null);
ps.FromXml (null);
}
示例14: FromXml
public void FromXml(SecurityElement element)
{
if (element == null)
{
throw new ArgumentNullException("element");
}
if (string.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
{
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
}
this.m_appTrustedToRun = false;
string strA = element.Attribute("TrustedToRun");
if ((strA != null) && (string.Compare(strA, "true", StringComparison.Ordinal) == 0))
{
this.m_appTrustedToRun = true;
}
this.m_persist = false;
string str2 = element.Attribute("Persist");
if ((str2 != null) && (string.Compare(str2, "true", StringComparison.Ordinal) == 0))
{
this.m_persist = true;
}
this.m_appId = null;
string applicationIdentityFullName = element.Attribute("FullName");
if ((applicationIdentityFullName != null) && (applicationIdentityFullName.Length > 0))
{
this.m_appId = new System.ApplicationIdentity(applicationIdentityFullName);
}
this.m_psDefaultGrant = null;
this.m_grantSetSpecialFlags = 0;
SecurityElement element2 = element.SearchForChildByTag("DefaultGrant");
if (element2 != null)
{
SecurityElement et = element2.SearchForChildByTag("PolicyStatement");
if (et != null)
{
PolicyStatement statement = new PolicyStatement(null);
statement.FromXml(et);
this.m_psDefaultGrant = statement;
this.m_grantSetSpecialFlags = SecurityManager.GetSpecialFlags(statement.PermissionSet, null);
}
}
List<StrongName> list = new List<StrongName>();
SecurityElement element4 = element.SearchForChildByTag("FullTrustAssemblies");
if ((element4 != null) && (element4.InternalChildren != null))
{
IEnumerator enumerator = element4.Children.GetEnumerator();
while (enumerator.MoveNext())
{
StrongName item = new StrongName();
item.FromXml(enumerator.Current as SecurityElement);
list.Add(item);
}
}
this.m_fullTrustAssemblies = list.AsReadOnly();
this.m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
}
示例15: FromXml
public void FromXml (SecurityElement element) {
if (element == null)
throw new ArgumentNullException("element");
if (String.Compare(element.Tag, "ApplicationTrust", StringComparison.Ordinal) != 0)
throw new ArgumentException(Environment.GetResourceString("Argument_InvalidXML"));
m_psDefaultGrant = null;
m_fullTrustAssemblies = null;
m_appTrustedToRun = false;
string isAppTrustedToRun = element.Attribute("TrustedToRun");
if (isAppTrustedToRun != null && String.Compare(isAppTrustedToRun, "true", StringComparison.Ordinal) == 0)
m_appTrustedToRun = true;
string persist = element.Attribute("Persist");
if (persist != null && String.Compare(persist, "true", StringComparison.Ordinal) == 0)
m_persist = true;
string fullName = element.Attribute("FullName");
if (fullName != null && fullName.Length > 0)
m_appId = new ApplicationIdentity(fullName);
SecurityElement elDefaultGrant = element.SearchForChildByTag("DefaultGrant");
if (elDefaultGrant != null) {
SecurityElement elDefaultGrantPS = elDefaultGrant.SearchForChildByTag("PolicyStatement");
if (elDefaultGrantPS != null) {
PolicyStatement ps = new PolicyStatement(null);
ps.FromXml(elDefaultGrantPS);
m_psDefaultGrant = ps;
}
}
SecurityElement elFullTrustAssemblies = element.SearchForChildByTag("FullTrustAssemblies");
if (elFullTrustAssemblies != null && elFullTrustAssemblies.InternalChildren != null) {
m_fullTrustAssemblies = new StrongName[elFullTrustAssemblies.Children.Count];
IEnumerator enumerator = elFullTrustAssemblies.Children.GetEnumerator();
int index = 0;
while (enumerator.MoveNext()) {
m_fullTrustAssemblies[index] = new StrongName();
m_fullTrustAssemblies[index].FromXml(enumerator.Current as SecurityElement);
index++;
}
}
m_elExtraInfo = element.SearchForChildByTag("ExtraInfo");
}