当前位置: 首页>>代码示例>>C#>>正文


C# PolicyLevel.ToXml方法代码示例

本文整理汇总了C#中System.Security.Policy.PolicyLevel.ToXml方法的典型用法代码示例。如果您正苦于以下问题:C# PolicyLevel.ToXml方法的具体用法?C# PolicyLevel.ToXml怎么用?C# PolicyLevel.ToXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Policy.PolicyLevel的用法示例。


在下文中一共展示了PolicyLevel.ToXml方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EncodeLevel

        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
            {
                MemoryStream stream = new MemoryStream( 24576 ); 
            
                StreamWriter writer = new StreamWriter( stream, new UTF8Encoding(false) );
                
                Encoding encoding = level.Encoding;

                if (encoding == null)
                    encoding = writer.Encoding;
                
                SecurityElement format = new SecurityElement( "xml" );
                format.m_type = SecurityElementType.Format;
                format.AddAttribute( "version", "1.0" );
                format.AddAttribute( "encoding", encoding.WebName );
                writer.Write( format.ToString() );
                writer.Flush();
                writer = new StreamWriter( stream, encoding );
            
                writer.Write( elConf.ToString() );
                        
                writer.Flush();

                // Write out the new config.

                if (!Config.SaveData( level.ConfigId, stream.GetBuffer(), 0, (int)stream.Length ))
                {
                    throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ) );
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException( String.Format( Environment.GetResourceString( "Policy_UnableToSave" ), level.Label ), e );
            }

            Config.ResetCacheData( level.ConfigId );

            try
            {
                if (CanUseQuickCache( level.RootCodeGroup ))
                {
                    Config.SetQuickCache( level.ConfigId, GenerateQuickCache( level ) );
                }
            }
            catch (Exception)
            {
            }

        }
开发者ID:ArildF,项目名称:masters,代码行数:64,代码来源:policymanager.cs

示例2: EncodeLevel

        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));
        }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:45,代码来源:policymanager.cs

示例3: EncodeLevel

        internal static void EncodeLevel (PolicyLevel level)
        {
            Contract.Assert(level != null, "No policy level to encode.");

            // We cannot encode a policy level without a backing file  
            if (level.Path == null)
            {
                string errorMessage = Environment.GetResourceString("Policy_UnableToSave",
                                                    level.Label,
                                                    Environment.GetResourceString("Policy_SaveNotFileBased"));
                throw new PolicyException(errorMessage);
            }
                
            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.
                int hrSave = Config.SaveDataByte(level.Path, data, data.Length);
                Exception extendedError = Marshal.GetExceptionForHR(hrSave);
                if (extendedError != null)
                {
                    string extendedInformation = extendedError != null ? extendedError.Message : String.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, extendedInformation), extendedError);
                }
            }
            catch (Exception e)
            {
                if (e is PolicyException)
                    throw e;
                else
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", level.Label, e.Message), e);
            }

            Config.ResetCacheData(level.ConfigId);
            if (CanUseQuickCache(level.RootCodeGroup))
                Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:58,代码来源:policymanager.cs

示例4: EncodeLevel

 internal static void EncodeLevel(PolicyLevel level)
 {
     if (level.Path == null)
     {
         throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, Environment.GetResourceString("Policy_SaveNotFileBased") }));
     }
     SecurityElement element = new SecurityElement("configuration");
     SecurityElement child = new SecurityElement("mscorlib");
     SecurityElement element3 = new SecurityElement("security");
     SecurityElement element4 = new SecurityElement("policy");
     element.AddChild(child);
     child.AddChild(element3);
     element3.AddChild(element4);
     element4.AddChild(level.ToXml());
     try
     {
         StringBuilder builder = new StringBuilder();
         Encoding encoding = Encoding.UTF8;
         SecurityElement element5 = new SecurityElement("xml") {
             m_type = SecurityElementType.Format
         };
         element5.AddAttribute("version", "1.0");
         element5.AddAttribute("encoding", encoding.WebName);
         builder.Append(element5.ToString());
         builder.Append(element.ToString());
         byte[] bytes = encoding.GetBytes(builder.ToString());
         Exception exceptionForHR = Marshal.GetExceptionForHR(Config.SaveDataByte(level.Path, bytes, bytes.Length));
         if (exceptionForHR != null)
         {
             string str2 = (exceptionForHR != null) ? exceptionForHR.Message : string.Empty;
             throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, str2 }), exceptionForHR);
         }
     }
     catch (Exception exception2)
     {
         if (exception2 is PolicyException)
         {
             throw exception2;
         }
         throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", new object[] { level.Label, exception2.Message }), exception2);
     }
     Config.ResetCacheData(level.ConfigId);
     if (CanUseQuickCache(level.RootCodeGroup))
     {
         Config.SetQuickCache(level.ConfigId, GenerateQuickCache(level));
     }
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:47,代码来源:PolicyManager.cs


注:本文中的System.Security.Policy.PolicyLevel.ToXml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。