Ejemplo n.º 1
0
        public void AddAddInDB()
        {
            //dw плохой тест, нужно переписать
            //событие так и не наступает
            RutorList rutorList = new RutorList();
            PostList  postList  = new PostList();
            bool      callFlag  = false;

            postList.OnAfterAdd += delegate(object sender, EventArgs e)
            {
                callFlag = true;
            };

            for (int countCall = 0; countCall < 48 && !callFlag; countCall++)
            {
                Thread.Sleep(250);
            }

            postList.Add(rutorList);
            Assert.AreEqual(true, callFlag);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Automatically called with 'false' before any items are added to the list.
        /// <para>
        /// But it is recommended to do that manually
        /// </para>
        /// </summary>
        /// <param name="state"></param>
        void SetLoadingAnimation(bool state)
        {
            // Turn on.
            if (state && !IsLoadingMore)
            {
                PostList.Add(new DummyLoadingPost());

                NotifyItemInserted(PostList.Count - 1);

                IsLoadingMore = true;
            }
            else
            {
                if (IsLoadingMore)
                {
                    PostList.RemoveAt(PostList.Count - 1);

                    NotifyItemRemoved(PostList.Count);

                    IsLoadingMore = false;
                }
            }
        }
Ejemplo n.º 3
0
        public Task <JsonResult> PostOrder(Order order)
        {
            if (order == null || string.IsNullOrEmpty(order.loginname))
            {
                return(null);
            }

            //order = new Order();
            //order.loginname = "chengwei";
            //order.username = "******";

            return(Task.Factory.StartNew(() =>
            {
                //秒杀库存数量
                int Number = 100;
                //返回结果
                OrderResult R = new OrderResult();
                //R.result = true;
                //R.content = "chenggong";

                //缓存数据库拿出请求队列
                List <Order> PostList = RedisUtils.Get <List <Order> >("Sale20170523", 0);
                if (PostList == null)
                {
                    PostList = new List <Order>();
                }
                PostList.Add(order);

                //缓存队列开始
                if (PostList.Count == 1)
                {
                    //创建一个进程,10秒后主动提交数据库
                    _timer = new Timer(new TimerCallback(ProcessorHandler), null, 10000, 0);

                    R.result = true;
                    R.content = "抢购成功";
                }
                //缓存队列达到请求数量
                else if (PostList.Count == Number)
                {
                    _timer.Dispose();
                    ProcessorHandler(null);

                    R.result = true;
                    R.content = "抢购成功";
                }
                //超出库存
                else if (PostList.Count > Number)
                {
                    _timer.Dispose();
                    R.result = false;
                    R.content = "库存不足";
                }
                //正常增加
                else
                {
                    R.result = true;
                    R.content = "抢购成功";
                }

                RedisUtils.Set <List <Order> >("Sale20170523", 0, PostList);
                AsyncManager.Parameters["Result"] = R;
            }).ContinueWith <JsonResult>(t =>
            {
                OrderResult R = AsyncManager.Parameters["Result"] as OrderResult;
                return Json(R, JsonRequestBehavior.AllowGet);
            }));
        }