System.Security.PolicyManager.EncodeLevel C# (CSharp) Method

EncodeLevel() static private method

static private EncodeLevel ( PolicyLevel level ) : void
level System.Security.Policy.PolicyLevel
return void
        internal static void EncodeLevel (PolicyLevel level) {
            SecurityElement elConf = new SecurityElement("configuration");
            SecurityElement elMscorlib = new SecurityElement("mscorlib");
            SecurityElement elSecurity = new SecurityElement("security");
            SecurityElement elPolicy = new SecurityElement("policy");

            elConf.AddChild(elMscorlib);
            elMscorlib.AddChild(elSecurity);
            elSecurity.AddChild(elPolicy);
            elPolicy.AddChild(level.ToXml());

            try
            {
                StringBuilder sb = new StringBuilder();
                Encoding encoding = Encoding.UTF8;

                SecurityElement format = new SecurityElement("xml");
                format.m_type = SecurityElementType.Format;
                format.AddAttribute("version", "1.0");
                format.AddAttribute("encoding", encoding.WebName);
                sb.Append(format.ToString());
                sb.Append(elConf.ToString());

                byte[] data = encoding.GetBytes(sb.ToString());

                // Write out the new config.
                if (level.Path == null || !Config.SaveDataByte(level.Path, data, 0, data.Length))
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label), e);
            }
            catch
            {
                throw new PolicyException(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("Policy_UnableToSave"), level.Label));
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
        }

Same methods

PolicyManager::EncodeLevel ( string label ) : void

Usage Example

 public static void SavePolicyLevel(PolicyLevel level)
 {
     if (!AppDomain.CurrentDomain.IsLegacyCasPolicyEnabled)
     {
         throw new NotSupportedException(Environment.GetResourceString("NotSupported_RequiresCasPolicyExplicit"));
     }
     PolicyManager.EncodeLevel(level);
 }
All Usage Examples Of System.Security.PolicyManager::EncodeLevel