Ejemplo n.º 1
0
        public void ExtendTest()
        {
            var x = Experiments.Json.Jsonify(new { z = 1,
                                                   a = new { b = new object[] { 1, 2, 3, new{ _id = 1, a = 2 }, new{ _id = 2, b = 4 } } } });
            var y = Experiments.Json.Jsonify(new { b = 1, z = "_remove_",
                                                   a = new { c = 2, b = new object[] { 4, 5, new{ _remove = 1 }, new{ _id = 1, b = 3 }, new{ _remove = new{ _id = 2 } } } } });
            var merged = Experiments.Json.Stringify(JsonExtend.Extend(x, y)).Simplify(SimplifyOptions.SingleQuotes);

            Console.WriteLine(merged);
            Assert.AreEqual(@"{'a':{'b':[2,3,4,5,{'_id':1,'a':2,'b':3}],'c':2},'b':1}", merged);
        }
Ejemplo n.º 2
0
 public virtual void Merge(IItem src)
 {
     if (string.IsNullOrWhiteSpace(this.Id))
     {
         Id = src.Id;
     }
     if (Version < src.Version)
     {
         Version = src.Version;
     }
     CheckRoled(this, src);
     if (null != src.Custom && 0 != src.Custom.Count)
     {
         Custom = Custom ?? new Dictionary <string, object>();
         JsonExtend.Extend(Custom, src.Custom);
     }
 }
Ejemplo n.º 3
0
        public void Apply(IUser targetUser)
        {
            if (ChangedActive(targetUser))
            {
                targetUser.Active = Active.Value;
            }
            if (ChangedLogable(targetUser))
            {
                targetUser.Logable = Logable.Value;
            }
            if (ChangedCustom(targetUser))
            {
                var target = targetUser.Custom ?? new Dictionary <string, object>();
                JsonExtend.Extend(target, Custom);
            }
            if (ChangedEmail(targetUser))
            {
                targetUser.Email = Email;
            }
            if (ChangedPublicKey(targetUser))
            {
                targetUser.PublicKey = PublicKey;
            }
            if (ChangedExpire(targetUser))
            {
                targetUser.Expire = Expire.Value.ToUniversalTime();
            }
            if (ChangedGroups(targetUser))
            {
                foreach (var item in AddGroups)
                {
                    targetUser.Groups.Remove(item);
                    targetUser.Groups.Add(item);
                }
                foreach (var item in RemoveGroups)
                {
                    targetUser.Groups.Remove(item);
                }
            }
            if (ChangedRoles(targetUser))
            {
                foreach (var item in AddRoles)
                {
                    targetUser.Roles.Remove(item);
                    targetUser.Roles.Add(item);
                }
                foreach (var item in RemoveRoles)
                {
                    targetUser.Roles.Remove(item);
                }
            }
            if (ChangedIsAdmin(targetUser))
            {
                targetUser.IsAdmin = IsAdmin.Value;
            }

            if (ChangedIsGroup(targetUser))
            {
                targetUser.IsGroup = IsGroup.Value;
            }

            if (ChangedDomain(targetUser))
            {
                targetUser.Domain = Domain;
            }
            if (ChangedPassword(targetUser))
            {
                var pwd = new PasswordManager();
                pwd.SetPassword(targetUser, Password, true);
            }

            if (ChangedName(targetUser))
            {
                targetUser.Name = Name;
                ;
            }
        }