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

CanUseQuickCache() static private method

static private CanUseQuickCache ( CodeGroup group ) : bool
group System.Security.Policy.CodeGroup
return bool
        internal static bool CanUseQuickCache (CodeGroup group) {
            ArrayList list = new ArrayList();

            list.Add(group);

            for (int i = 0; i < list.Count; ++i)
            {
                group = (CodeGroup)list[i];

                IUnionSemanticCodeGroup unionGroup = group as IUnionSemanticCodeGroup;

                if (unionGroup != null)
                {
                    if (!TestPolicyStatement(group.PolicyStatement))
                        return false;
                }
                else
                {
                    return false;
                }

                IMembershipCondition cond = group.MembershipCondition;
                if (cond != null && !(cond is IConstantMembershipCondition))
                {
                    return false;
                }

                IList children = group.Children;

                if (children != null && children.Count > 0)
                {
                    IEnumerator enumerator = children.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        list.Add(enumerator.Current);
                    }
                }
            }

            return true;
        }

Usage Example

Beispiel #1
0
        internal static void EncodeLevel(PolicyLevel level)
        {
            if (level.Path == null)
            {
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)Environment.GetResourceString("Policy_SaveNotFileBased")));
            }
            SecurityElement securityElement1 = new SecurityElement("configuration");
            SecurityElement child1           = new SecurityElement("mscorlib");
            SecurityElement child2           = new SecurityElement("security");
            SecurityElement child3           = new SecurityElement("policy");

            securityElement1.AddChild(child1);
            child1.AddChild(child2);
            child2.AddChild(child3);
            child3.AddChild(level.ToXml());
            try
            {
                StringBuilder   stringBuilder    = new StringBuilder();
                Encoding        utF8             = Encoding.UTF8;
                SecurityElement securityElement2 = new SecurityElement("xml");
                securityElement2.m_type = SecurityElementType.Format;
                securityElement2.AddAttribute("version", "1.0");
                securityElement2.AddAttribute("encoding", utF8.WebName);
                stringBuilder.Append(securityElement2.ToString());
                stringBuilder.Append(securityElement1.ToString());
                byte[]    bytes          = utF8.GetBytes(stringBuilder.ToString());
                string    path           = level.Path;
                byte[]    data           = bytes;
                int       length         = data.Length;
                Exception exceptionForHr = Marshal.GetExceptionForHR(Config.SaveDataByte(path, data, length));
                if (exceptionForHr != null)
                {
                    string str = exceptionForHr != null ? exceptionForHr.Message : string.Empty;
                    throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)str), exceptionForHr);
                }
            }
            catch (Exception ex)
            {
                if (ex is PolicyException)
                {
                    throw ex;
                }
                throw new PolicyException(Environment.GetResourceString("Policy_UnableToSave", (object)level.Label, (object)ex.Message), ex);
            }
            Config.ResetCacheData(level.ConfigId);
            if (!PolicyManager.CanUseQuickCache(level.RootCodeGroup))
            {
                return;
            }
            Config.SetQuickCache(level.ConfigId, PolicyManager.GenerateQuickCache(level));
        }
All Usage Examples Of System.Security.PolicyManager::CanUseQuickCache