Ejemplo n.º 1
0
        public void FindChangedCache()
        {
            var        watch  = Stopwatch.StartNew();
            int        userId = 1001;
            var        cache  = new PersonalCacheStruct <UserFriend>();
            UserFriend Jim    = cache.FindKey(userId.ToString());

            if (Jim == null)
            {
                Jim = new UserFriend()
                {
                    UserId = userId, Friends2 = new CacheList <FriendsData>()
                };
                Jim.Friends2.Add(new FriendsData()
                {
                    UserId = 1000
                });
                Assert.IsTrue(cache.AddOrUpdate(Jim));
            }
            else
            {
                Assert.IsFalse(Jim.HasChanged);
                Assert.IsTrue(Jim.IsInCache);
            }

            foreach (var f in Jim.Friends2)
            {
                f.Num++;
            }

            Assert.IsTrue(Jim.HasChanged);
            Assert.IsTrue(Jim.IsInCache);
            WaitEnd(watch);
        }
Ejemplo n.º 2
0
        public static void UpdateData(tb_User _user)
        {
            var cacheSet = new PersonalCacheStruct <tb_User>();

            ////tb_User _tempuser = cacheSet.Find((t_user) => { return t_user.UserID == _user.UserID; });
            ////_tempuser.ModifyLocked();
            cacheSet.AddOrUpdate(_user);
        }
Ejemplo n.º 3
0
        public void ChangedCache()
        {
            var  watch   = Stopwatch.StartNew();
            int  fuserId = 1000;
            var  cache   = new PersonalCacheStruct <UserFriend>();
            long userId  = cache.GetNextNo();

            cache.FindKey(userId.ToString());

            UserFriend Jim = PersonalCacheStruct.GetOrAdd <UserFriend>(userId.ToString(), new Lazy <UserFriend>(() =>
            {
                var f = new UserFriend()
                {
                    UserId = userId, Name = "Jim"
                };
                f.Friends.Add(new FriendsData()
                {
                    UserId = fuserId, Num = 1
                });
                f.FriendDict.Add(fuserId, new FriendsData()
                {
                    UserId = fuserId, Num = 1
                });
                return(f);
            }));

            //Jim.SetChangeProperty("Name");
            Assert.IsTrue(cache.AddOrUpdate(Jim));
            Assert.IsTrue(Jim.IsInCache);

            var         temp  = cache.FindKey(userId.ToString());
            FriendsData fdata = null;

            //list
            fdata = temp.Friends[0];
            if (fdata != null)
            {
                Trace.WriteLine("num:" + fdata.Num);
                fdata.Num++;
                Assert.IsTrue(Jim.Friends.HasChanged, "list error");
                Assert.IsTrue(Jim.HasChangePropertys, "list error");
            }
            //dict
            if (temp.FriendDict.TryGetValue(fuserId, out fdata))
            {
                fdata.Num++;
                Assert.IsTrue(Jim.FriendDict.HasChanged, "dict error");
                Assert.IsTrue(Jim.HasChangePropertys, "entity error");
            }
            WaitEnd(watch);
        }
Ejemplo n.º 4
0
        public override bool TakeAction()
        {
            var cache = new PersonalCacheStruct <GameUser>();

            _user = (GameUser)Current.User;

            if (_user != null)
            {
                //_user.ModifyLocked(() =>
                //{
                //    _user.NickName = _uname;
                //});

                _user.NickName = _uname;

                cache.AddOrUpdate(_user);

                //var cacheUser = cache.FindKey(_user.IEMI);

                //if (cacheUser==null)
                //{
                //    Console.WriteLine("null-------1005");
                //}
                //else {

                //    cacheUser.ModifyLocked(() =>
                //    {
                //        cacheUser.NickName = _uname;
                //    });

                //    //cache.ReLoad(cacheUser.PersonalId);
                //}
            }
            else
            {
                throw new Exception("去你妈的");
            }

            return(true);
        }
Ejemplo n.º 5
0
        public void GetAndAddOfMutiKey()
        {
            var watch  = Stopwatch.StartNew();
            int userId = 138001;
            var cache  = new PersonalCacheStruct <UserKeyData>();

            cache.AddOrUpdate(new UserKeyData()
            {
                UserId = userId, Key = "4", Value = "aa"
            });
            var list = cache.FindAll(userId.ToString());

            Assert.IsTrue(list.Count > 0);
            Trace.WriteLine("data count:" + list.Count);

            var key = userId + cache.GetNextNo();

            cache.Add(new UserKeyData()
            {
                UserId = key.ToInt(), Key = "4", Value = "aa"
            });
            Assert.IsNotNull(cache.FindKey(key.ToString(), key, "4"));
            WaitEnd(watch);
        }
Ejemplo n.º 6
0
        public override bool TakeAction()
        {
            var iemiCache = new ShareCacheStruct <IemiEntity>();


            var cache = new PersonalCacheStruct <GameUser>();


            var entity = iemiCache.FindKey(_pid);

            if (entity == null)
            {
                var filter = new DbDataFilter();
                filter.Condition = "IEMI = @IEMI";
                filter.Parameters.Add("IEMI", _pid);
                iemiCache.TryRecoverFromDb(filter, _pid);

                entity = iemiCache.FindKey(_pid);
            }

            if (entity == null)
            {
                Console.WriteLine("1004-------------IemiEntity Is Null");

                entity      = new IemiEntity();
                entity.IEMI = _pid;

                _user = new GameUser()
                {
                    UserId    = (int)cache.GetNextNo(),
                    IEMI      = _pid,
                    Searching = false,
                    RivalId   = -1
                };

                entity.UserId = _user.UserId;


                iemiCache.AddOrUpdate(entity);

                cache.AddOrUpdate(_user);

                Current.Bind(_user);
            }
            else
            {
                int userId = entity.UserId;

                _user = cache.FindKey(userId.ToString());

                if (_user == null)
                {
                    var filter = new DbDataFilter();
                    filter.Condition = "UserId = @UserId";
                    filter.Parameters.Add("UserId", userId);
                    var ii = cache.TryRecoverFromDb(filter, userId.ToString());

                    Console.WriteLine(string.Format("1004-------------UserId:{0},IEMI:{1}", userId, entity.IEMI));
                }

                if (cache.TryFindKey(entity.UserId.ToString(), out _user, entity.UserId.ToString()) == ZyGames.Framework.Model.LoadingStatus.Success)
                {
                    Current.Bind(_user);
                }
                else
                {
                }
            }


            return(true);
        }