private void ChangePermissions <TTarget, TSecurity, TAccessRule, TRights>(XmlNode targetNode, Dictionary <string, TRights> rightsDictionary, SetLocalPermissions.GetTarget <TTarget> getTarget, SetLocalPermissions.GetOrginalPermissionsOnTarget <TSecurity, TTarget> getOrginalPermissionsOnTarget, SetLocalPermissions.SetPermissionsOnTarget <TSecurity, TTarget> setPermissionsOnTarget, SetLocalPermissions.CreateAccessRule <TAccessRule, TRights> createAccessRule, SetLocalPermissions.AddAccessRule <TSecurity, TAccessRule> addAccessRule, SetLocalPermissions.RemoveAccessRuleAll <TSecurity> removeAccessRuleAll) where TTarget : class where TSecurity : NativeObjectSecurity, new() where TAccessRule : AccessRule
        {
            TaskLogger.LogEnter();
            TTarget   target    = getTarget(targetNode);
            TSecurity tsecurity = default(TSecurity);

            if (targetNode.Attributes["Sddl"] != null)
            {
                string value = targetNode.Attributes["Sddl"].Value;
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentException(null, "Sddl");
                }
                if (targetNode.Attributes.Count > 2)
                {
                    foreach (object obj in targetNode.Attributes)
                    {
                        XmlNode xmlNode = (XmlNode)obj;
                        if (xmlNode.Name != "Sddl" && xmlNode.Name != "Path")
                        {
                            throw new ArgumentException(null, xmlNode.Name);
                        }
                    }
                }
                if (targetNode.ChildNodes.Count > 0)
                {
                    throw new ArgumentException(null, targetNode.ChildNodes[0].Name);
                }
                tsecurity = Activator.CreateInstance <TSecurity>();
                tsecurity.SetSecurityDescriptorSddlForm(value);
            }
            else
            {
                tsecurity = getOrginalPermissionsOnTarget(target);
                if (tsecurity.AreAccessRulesCanonical)
                {
                    tsecurity.SetAccessRuleProtection(this.IsProtected(targetNode), this.PreserveInheritance(targetNode));
                }
                else
                {
                    tsecurity = Activator.CreateInstance <TSecurity>();
                }
                using (XmlNodeList xmlNodeList = targetNode.SelectNodes("Permission"))
                {
                    foreach (object obj2 in xmlNodeList)
                    {
                        XmlNode            permissionNode     = (XmlNode)obj2;
                        SecurityIdentifier securityIdentifier = this.GetSecurityIdentifier(permissionNode);
                        InheritanceFlags   inheritanceFlags   = InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit;
                        PropagationFlags   propagationFlags   = PropagationFlags.None;
                        if (this.IsProtected(targetNode) && this.PreserveInheritance(targetNode) && !this.IsExtended(permissionNode))
                        {
                            removeAccessRuleAll(tsecurity, securityIdentifier);
                        }
                        List <SetLocalPermissions.RightsWithAccessControlType <TRights> > rights = this.GetRights <TRights>(permissionNode, rightsDictionary);
                        foreach (SetLocalPermissions.RightsWithAccessControlType <TRights> rightsWithAccessControlType in rights)
                        {
                            addAccessRule(tsecurity, createAccessRule(securityIdentifier, rightsWithAccessControlType.Rights, inheritanceFlags, propagationFlags, rightsWithAccessControlType.AccessControlType));
                        }
                    }
                }
            }
            setPermissionsOnTarget(target, tsecurity);
            TaskLogger.LogExit();
        }
 private void SetPermissionsOnCurrentLevel <TTarget, TSecurity, TAccessRule, TRights>(XmlNode permissionSetNode, string targetType, Dictionary <string, TRights> rightsDictionary, SetLocalPermissions.GetTarget <TTarget> getTarget, SetLocalPermissions.GetOrginalPermissionsOnTarget <TSecurity, TTarget> getOrginalPermissionsOnTarget, SetLocalPermissions.SetPermissionsOnTarget <TSecurity, TTarget> setPermissionsOnTarget, SetLocalPermissions.CreateAccessRule <TAccessRule, TRights> createAccessRule, SetLocalPermissions.AddAccessRule <TSecurity, TAccessRule> addAccessRule, SetLocalPermissions.RemoveAccessRuleAll <TSecurity> removeAccessRuleAll) where TTarget : class where TSecurity : NativeObjectSecurity, new() where TAccessRule : AccessRule
 {
     TaskLogger.LogEnter();
     using (XmlNodeList xmlNodeList = permissionSetNode.SelectNodes(targetType))
     {
         foreach (object obj in xmlNodeList)
         {
             XmlNode targetNode = (XmlNode)obj;
             this.ChangePermissions <TTarget, TSecurity, TAccessRule, TRights>(targetNode, rightsDictionary, getTarget, getOrginalPermissionsOnTarget, setPermissionsOnTarget, createAccessRule, addAccessRule, removeAccessRuleAll);
         }
     }
     TaskLogger.LogExit();
 }