/// <summary>
 /// 操作列队
 /// </summary>
 private void OperateQueue()
 {
     var mq = new SenparcMessageQueue();
     var key = mq.GetCurrentKey(); //获取最新的Key
     while (!string.IsNullOrEmpty(key))
     {
         var mqItem = mq.GetItem(key); //获取任务项
         mqItem.Action(); //执行
         mq.Remove(key); //清除
         key = mq.GetCurrentKey(); //获取最新的Key
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 操作队列
 /// </summary>
 public static void OperateQueue()
 {
     lock (FlushCacheLock)
     {
         var mq  = new SenparcMessageQueue();
         var key = mq.GetCurrentKey(); //获取最新的Key
         while (!string.IsNullOrEmpty(key))
         {
             var mqItem = mq.GetItem(key); //获取任务项
             mqItem.Action();              //执行
             mq.Remove(key);               //清除
             key = mq.GetCurrentKey();     //获取最新的Key
         }
     }
 }
 /// <summary>
 /// 操作列队
 /// </summary>
 public static void OperateQueue()
 {
     lock (FlushCacheLock)
     {
         var mq = new SenparcMessageQueue();
         var key = mq.GetCurrentKey(); //获取最新的Key
         while (!string.IsNullOrEmpty(key))
         {
             var mqItem = mq.GetItem(key); //获取任务项
             mqItem.Action(); //执行
             mq.Remove(key); //清除
             key = mq.GetCurrentKey(); //获取最新的Key
         }
     }
 }
 public void Run()
 {
     do
     {
         var mq = new SenparcMessageQueue();
         var key = mq.GetCurrentKey();//获取最新的Key
         while (!string.IsNullOrEmpty(key))
         {
             var mqItem = mq.GetItem(key);//获取任务项
             mqItem.Action();//执行
             mq.Remove(key);//清除
             key = mq.GetCurrentKey();//获取最新的Key
         }
         Thread.Sleep(_sleepMilliSeconds);
     } while (true);
 }
Esempio n. 5
0
        public void RunTest()
        {
            //默认情况下ThreadUtility应该已经将SenparcMessageQueueThreadUtility加入列队
            //下面对Container进行测试

            var c1 = TestContainer1.GetCollectionList();
            var key = DateTime.Now.Ticks.ToString();
            var bag = new TestContainerBag1()
            {
                Key = key,
                DateTime = DateTime.Now
            };
            TestContainer1.Update(key, bag);
            bag.DateTime = DateTime.MinValue;//进行修改

            //读取列队
            var mq = new SenparcMessageQueue();
            var mqKey = SenparcMessageQueue.GenerateKey("A",typeof(TestContainerBag1), bag.Key,"B");
            var mqItem = mq.GetItem(mqKey);
            Assert.IsNotNull(mqItem);

        }
        public void TestAll()
        {
            var mq = new SenparcMessageQueue();
            var count = mq.GetCount();
            var key = DateTime.Now.Ticks.ToString();

            //Test Add()
            var item = mq.Add(key, () => WeixinTrace.Log("测试SenparcMessageQueue写入Key=A"));
            Assert.AreEqual(count+1,mq.GetCount());
            //var hashCode = item.GetHashCode();

            //Test GetCurrentKey()
            var currentKey = mq.GetCurrentKey();
            Assert.AreEqual(key,currentKey);

            //Test GetItem
            var currentItem = mq.GetItem(currentKey);
            Assert.AreEqual(currentItem.Key,item.Key);
            Assert.AreEqual(currentItem.AddTime,item.AddTime);

            //Test Remove
            mq.Remove(key);
            Assert.AreEqual(count, mq.GetCount());
        }