Example #1
0
 /// <summary>
 /// 锁定奖品
 /// </summary>
 /// <param name="value"></param>
 private void LockPrize(ValueTuple <bool, string, Dictionary <string, object> > tp)
 {
     try
     {
         if (tp.Item1)
         {
             UsersInfo user  = tp.Item3["User"] as UsersInfo;
             PrizeInfo prize = JsonConvert.DeserializeObject <PrizeInfo>(tp.Item2);
             if (null != user && null != prize)
             {
                 user.PrizeInfo = prize;
                 ShowSysMessage($"用户{user.Name}锁定到一个奖品:{tp.Item2}");
                 PrizeUser(user);// 将中奖人塞入中奖队列
             }
         }
         else
         {
             ShowSysMessage(tp.Item2);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "出错了", MessageBoxButtons.OK);
     }
 }
Example #2
0
        /// <summary>
        /// 拿用户去抽一个奖品
        /// </summary>
        /// <param name="user"></param>
        private void LockPrize(UsersInfo user)
        {
            SetReceivefigModel(PrizeQueueName);//设置队列信息(奖品池)
            Dictionary <string, object> data = new Dictionary <string, object> {
                { "User", user }
            };

            RabbitReceive.BasicGet(LockPrize, data);
        }
Example #3
0
 /// <summary>
 ///
 /// </summary>
 private void ParallelFunction(CancellationToken ct)
 {
     Parallel.For(0, 1000, item =>
     {
         if (!ct.IsCancellationRequested)
         {
             string value   = string.Empty;
             UsersInfo user = new UsersInfo
             {
                 Id   = item,
                 Name = "我是:" + item
             };
             value = Newtonsoft.Json.JsonConvert.SerializeObject(user);
             ShowSysMessage($"进来了一位用户:{value}");
             RabbitSend.Send(user);
         }
     });
 }
Example #4
0
 /// <summary>
 /// 先去用户池中取出一个人
 /// </summary>
 /// <param name="tp"></param>
 private void LockUser(ValueTuple <bool, string, Dictionary <string, object> > tp)
 {
     try
     {
         if (tp.Item1)
         {
             ShowSysMessage($"锁定到一个用户:{tp.Item2}");
             UsersInfo user = JsonConvert.DeserializeObject <UsersInfo>(tp.Item2);
             if (null != user)
             {
                 Thread.Sleep(50);
                 LockPrize(user);//拿用户去抽一个奖品
             }
         }
         else
         {
             ShowSysMessage(tp.Item2);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "出错了", MessageBoxButtons.OK);
     }
 }
Example #5
0
 /// <summary>
 /// 将中奖人塞入中奖队列
 /// </summary>
 /// <param name="user"></param>
 private void PrizeUser(UsersInfo user)
 {
     SetSendfigModel(PrizeUserQueueName);  //设置队列信息(中奖人)
     RabbitSend.Send(user);
     Thread.Sleep(50);
 }