Пример #1
0
 public void TestBatchSend()
 {
     _config.AttemptRemoveSignature = true;
     using (var client = new Cmpp30Client(_config))
     {
         client.Start();
         for (var i = 0; i < 100; i++)
         {
             Thread.Sleep(50);
             if (client.Status == Cmpp30ClientStatus.Connected) break;
         }
         if (client.Status != Cmpp30ClientStatus.Connected)
         {
             Console.WriteLine("Client connection failed.");
             return;
         }
         Console.WriteLine("Connected.");
         var numbers = File.ReadAllLines("numbers.txt");
         var count = 0;
         foreach (var number in numbers.Where(x => !string.IsNullOrEmpty(x)))
         {
             Console.WriteLine("Sending message no. {0}. ", ++count);
             var status = Cmpp30SendStatus.Congested;
             while (status == Cmpp30SendStatus.Congested)
             {
                 List<long> msgIds;
                 status = client.Send("10086", number, "测试发送短信。", out msgIds, false);
             }
         }
     }
 }
Пример #2
0
 public void TestConnect()
 {
     _config.AttemptRemoveSignature = false;
     using (var client = new Cmpp30Client(_config))
     {
         client.OnMessageReport += client_OnMessageReport;
         client.Start();
         for (var i = 0; i < 100; i++)
         {
             Thread.Sleep(50);
             if (client.Status == Cmpp30ClientStatus.Connected) break;
         }
         if (client.Status != Cmpp30ClientStatus.Connected)
         {
             Console.WriteLine("Client connection failed. Status: {0} {1}.", client.Status, client.StatusText);
             return;
         }
         Console.WriteLine("Connected.");
         List<long> msgIds;
         Console.WriteLine(client.Send("", new[] { "13800138000", "13800138001" }, "测试发送短信", out msgIds));
         while (true)
         {
             Thread.Sleep(2500);
             Console.WriteLine(client.Status);
         }
     }
 }
Пример #3
0
        public void ParallelTestCmpp30()
        {
            using (var client = new Cmpp30Client(_config))
            {
                client.OnMessageReport += _OnMessageReport;
                client.OnMessageReceive += OnMessageReceive;
                client.Start();
                for (var i = 0; i < 100; i++)
                {
                    Thread.Sleep(50);
                    if (client.Status == Cmpp30ClientStatus.Connected) break;
                }
                if (client.Status != Cmpp30ClientStatus.Connected)
                {
                    Console.WriteLine("Client connection failed.");
                    return;
                }
                Console.WriteLine("Connected.");
                var tasks = new List<Task>();
                for (var i = 0; i < 100; i++)
                {
                    tasks.Add(Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            List<long> idList;
                            var response = client.Send("999", "13800138000", " ", out idList);
                            if (response == Cmpp30SendStatus.Congested)
                            {
                                Console.WriteLine("Congested");
                                return;
                            }

                            if (response != Cmpp30SendStatus.Success || idList.Count != 1) return;
                            //Assert.AreEqual(Cmpp30SendStatus.Success, response);
                            //Assert.AreEqual(1, idList.Count);
                            _msgIds.Add(idList[0]);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                        }
                    }));
                }
                Task.WaitAll(tasks.ToArray());
                while (true)
                {
                    if (_msgIds.Count == 0) break;
                    Console.WriteLine("Waiting for {0} more reports", _msgIds.Count);
                    Thread.Sleep(2000);
                }
            }
        }
Пример #4
0
 public void ContinuouslySend()
 {
     var dueTime = DateTime.Now.AddMinutes(5);
     using (var client = new Cmpp30Client(_config))
     {
         client.OnMessageReport += _OnMessageReport;
         client.OnMessageReceive += OnMessageReceive;
         client.Start();
         for (var i = 0; i < 100; i++)
         {
             Thread.Sleep(50);
             if (client.Status == Cmpp30ClientStatus.Connected) break;
         }
         if (client.Status != Cmpp30ClientStatus.Connected)
         {
             Console.WriteLine("Client connection failed.");
             return;
         }
         Console.WriteLine("Connected.");
         while (dueTime > DateTime.Now)
         {
             var tasks = new List<Task>();
             for (var i = 0; i < 3; i++)
             {
                 tasks.Add(Task.Factory.StartNew(() =>
                 {
                     try
                     {
                         List<long> idList;
                         var response = client.Send("999", "13800138000", " ", out idList);
                         if (response == Cmpp30SendStatus.Congested)
                         {
                             //Console.WriteLine("Congested");
                             return;
                         }
                         _totalSent++;
                         Assert.AreEqual(Cmpp30SendStatus.Success, response);
                         Assert.AreEqual(1, idList.Count);
                         lock (_msgIds) _msgIds.Add(idList[0]);
                     }
                     catch (Exception ex)
                     {
                         Console.WriteLine(ex);
                     }
                 }));
             }
             Task.WaitAll(tasks.ToArray());
             lock (_msgIds) Console.WriteLine("Waiting for {0} more reports", _msgIds.Count);
         }
         Console.WriteLine("Send {0} messages. Wait for reports.", _totalSent);
         while (true)
         {
             if (_msgIds.Count == 0) break;
             Console.WriteLine("Waiting for {0} more reports", _msgIds.Count);
             Thread.Sleep(2000);
         }
     }
 }
Пример #5
0
        public void SequentialTestCmpp30()
        {
            using (var client = new Cmpp30Client(_config))
            {
                client.OnMessageReport += _OnMessageReport;
                client.Start();
                for (var i = 0; i < 100; i++)
                {
                    Thread.Sleep(50);
                    if (client.Status == Cmpp30ClientStatus.Connected) break;
                }
                if (client.Status != Cmpp30ClientStatus.Connected)
                {
                    Console.WriteLine("Client connection failed.");
                    return;
                }
                Console.WriteLine("Connected.");

                for (var i = 0; i < 100; i++)
                {
                    List<long> idList;
                    var response = client.Send("999", "13800138000", "测试发送短信", out idList);
                    if (response == Cmpp30SendStatus.Congested) continue;

                    Assert.AreEqual(Cmpp30SendStatus.Success, response);
                    Assert.AreEqual(1, idList.Count);
                    _msgIds.Add(idList[0]);
                }
                while (true)
                {
                    if (_msgIds.Count == 0) break;
                    Console.WriteLine("Waiting for {0} more reports", _msgIds.Count);
                    Thread.Sleep(2000);
                }
            }
        }