private static void WriteAcls(JsonWriter writer, List<Claim> allowed, List<Claim> denied, List<ResetRequest> reset)
        {
            var map = new Dictionary<SidTypeKey, ClaimGroup>();
            allowed.For(x =>
            {
                ClaimGroup group;
                var key = new SidTypeKey { Sid = x.Sid, Type = x.ClaimType };
                if (map.TryGetValue(key, out group) == false)
                    group = new ClaimGroup { Sid = x.Sid, Type = x.ClaimType };
                group.Allowed.Add(x.AccessType);
            });
            denied.For(x =>
            {
                ClaimGroup group;
                var key = new SidTypeKey { Sid = x.Sid, Type = x.ClaimType };
                if (map.TryGetValue(key, out group) == false)
                    group = new ClaimGroup { Sid = x.Sid, Type = x.ClaimType };
                group.Denied.Add(x.AccessType);
            });
            reset.For(x =>
            {
                ClaimGroup group;
                var key = new SidTypeKey { Sid = x.Sid, Type = x.Type };
                if (map.TryGetValue(key, out group) == false)
                    group = new ClaimGroup { Sid = x.Sid, Type = x.Type };
                group.Reset.Add(x.Access);
            });

            writer.WriteStartArray();
            map.Values.For(x =>
            {
                writer.WriteStartObject();
                writer.WriteProperty("sid", x.Sid);
                writer.WriteProperty("type", x.Type.ToString().ToLower());
                if (x.Allowed.Count > 0)
                    writer.WriteArray("allow", x.Allowed.Select(y => y.ToString().ToLower()));
                if (x.Denied.Count > 0)
                    writer.WriteArray("deny", x.Denied.Select(y => y.ToString().ToLower()));
                if (x.Reset.Count > 0)
                    writer.WriteArray("dontcare", x.Reset.Select(y => y.ToString().ToLower()));
                writer.WriteEndObject();
            });
            writer.WriteEndArray();
        }
 private static void ParseClaims(Acl acl, JObject item)
 {
     var sid = item.Property("sid").Value.ToString();
     var type = item.Property("type").Value.ToString();
     List<Access> allowed = new List<Access>();
     List<Access> denied = new List<Access>();
     var allowProperty = item.Property("allow");
     if (allowProperty != null)
     {
         allowProperty
             .Values()
             .Select(x => (Access)Enum.Parse(typeof(Access), x.ToString(), true))
             .For(x => allowed.Add(x));
     }
     var denyProperty = item.Property("deny");
     if (denyProperty != null)
     {
         denyProperty
             .Values()
             .Select(x => (Access)Enum.Parse(typeof(Access), x.ToString(), true))
             .For(x => denied.Add(x));
     }
     ClaimType claimType = (ClaimType)Enum.Parse(typeof(ClaimType), type, true);
     List<Claim> claims = new List<Claim>();
     allowed.For(x => claims.Add(new Claim(Permission.Allow, x, claimType, sid)));
     denied.For(x => claims.Add(new Claim(Permission.Deny, x, claimType, sid)));
     acl.SetInternal(claims);
 }