예제 #1
0
        public void TestCmppSendSmsSparsely()
        {
            var client    = new CmppSmsClient(_configurations);
            var receivers = new string[] { "18613350979" };
            var content   = "【测试短信】测试短信";

            int count = 10;

            Random r = new Random();


            Task.Run(async() =>
            {
                //await client.StartAsync();
                for (int i = 0; i < count; i++)
                {
                    Debug.WriteLine("sending {0}...", i + 1);
                    await client.SendSmsAsync(receivers, content);

                    int wait = 5 + r.Next(10);
                    for (int w = wait; w >= 0; w--)
                    {
                        Debug.WriteLine("Wait {0}...", w);
                        await Task.Delay(1000);
                    }
                }
                await client.StopAsync();
            }).Wait();
        }
예제 #2
0
        public void TestCmppLifetimeSimple()
        {
            var client = new CmppSmsClient(_configurations);

            Task.Run(async() =>
            {
                await client.StartAsync();
                await Task.Delay(int.MaxValue);
                await client.StopAsync();
            }).Wait();
        }
예제 #3
0
        public void TestServerCmppSendSmsSimple()
        {
            var client = new CmppSmsClient(_configurations);

            var server = new CmppSmsServer(new SmsServerConfigurations()
            {
                HostName  = _configurations.HostName,
                HostPort  = _configurations.HostPort,
                UserName  = _configurations.UserName,
                Password  = _configurations.UserName,
                ServiceID = _configurations.ServiceId,
            });


            var ts1 = server.StartAsync();

            ts1.Wait();


            var receivers = new string[] { "18613350979" };
            var content   = "【测试短信】测试短信";

            var cancel = new CancellationTokenSource();

            client.SmsResponseReceived += (sender, e) =>
            {
                var response = e.Envolope.Response as CmppMessageSubmitResponse;
                Debug.WriteLine("<!>RESPONSE: {0}", response.Result);
            };

            client.SmsReportReceived += (sender, e) =>
            {
                var report = e.Report as CmppMessageReport;
                Debug.WriteLine("<!>REPORT: {0}", report.Stat);
                cancel.Cancel();
            };

            Task.Run(async() =>
            {
                //await client.StartAsync();
                await client.SendSmsAsync(receivers, content);

                await Task.Delay(5000, cancel.Token);

                await client.StopAsync();
            }).Wait();

            var ts2 = server.StopAsync();

            ts2.Wait();
        }
예제 #4
0
        public void TestCmppSendSmsSimple()
        {
            var client = new CmppSmsClient(_configurations);

            Random r = new Random();

            var receivers = new string[] { "13979121569" };
            var content   = "【天天快递】您的快递提取码为" + r.Next(1000000).ToString("000000");


            var cancel = new CancellationTokenSource();

            client.SmsResponseReceived += (sender, e) =>
            {
                var response = e.Envolope.Response as CmppMessageSubmitResponse;
                Debug.WriteLine("<!>RESPONSE: {0}", response.Result);
            };

            client.SmsReportReceived += (sender, e) =>
            {
                var report = e.Report as CmppMessageReport;
                Debug.WriteLine("<!>REPORT: {0}", report.Stat.ToString());
                cancel.Cancel();
            };

            Task.Run(async() =>
            {
                //await client.StartAsync();

                for (int i = 0; i < 10; i++)
                {
                    await client.SendSmsAsync(receivers, content);
                }

                try
                {
                    await Task.Delay(2000, cancel.Token);
                }
                catch { }

                await client.StopAsync();
            }).Wait();
        }
예제 #5
0
        public void TestSmsDeliverReceived()
        {
            var client = new CmppSmsClient(_configurations);

            client.SmsDeliverReceived += (sender, e) =>
            {
                var deliver = e.Deliver;
                Assert.IsNotNull(deliver);
                Assert.IsInstanceOfType(e.Deliver, typeof(CmppMessageDeliver));
                Thread.Sleep(1000);
                Debug.WriteLine("上行短信接收成功!");
            };


            Task.Run(async() =>
            {
                await client.StartAsync();
                await Task.Delay(150000);
            }).Wait();
        }
예제 #6
0
        private static void TestSmgpChannel()
        {
            var configs = new CmppConfiguration()
            {
                HostName  = "211.136.112.109",
                HostPort  = 7891,
                UserName  = "******",
                Password  = "******",
                ServiceId = "10690810",
                SpCode    = "106908100066",
            };

            configs = new CmppConfiguration()
            {
                HostName        = "101.227.68.68",
                HostPort        = 7891,
                UserName        = "******",
                Password        = "******",
                ServiceId       = "HELP",
                SpCode          = "020106",
                KeepConnection  = false,
                RemoveSignature = false
            };


            var receiver = Program.GetArgumentValue("no");
            var content  = Program.GetArgumentValue("text");

            if (string.IsNullOrEmpty(receiver))
            {
                receiver = "18613350979";
            }
            if (string.IsNullOrEmpty(content))
            {
                content = "【天天快递】明天下雨,请记得带伞。";
            }

            Console.WriteLine("sending \"{0}\" to {1}...", content, receiver);

            var t = Task.Run(async() =>
            {
                CmppSmsClient client = new CmppSmsClient(configs);
                await client.StartAsync();

                client.SmsResponseReceived += (sender, e) =>
                {
                    var response = e.Envolope.Response as CmppMessageSubmitResponse;
                    Console.WriteLine("<!> RESPONSE: " + response.Result.ToString());
                };

                client.SmsReportReceived += (sender, e) =>
                {
                    var report = e.Report as CmppMessageReport;
                    Console.WriteLine("<!> REPORT: " + report.Stat.ToString());
                };

                await client.SendSmsAsync(receiver, content);
            });

            try
            {
                t.Wait();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }

            int count = 60;

            while (count > 0)
            {
                count--;
                Console.Title = string.Format("waiting {0}...", count);
                Task.Delay(1000).Wait();
            }
        }
예제 #7
0
        public void TestServerCmppSendSmsPerformanceByTime()
        {
            var client = new CmppSmsClient(_configurations);

            var server = new CmppSmsServer(new SmsServerConfigurations()
            {
                HostName  = _configurations.HostName,
                HostPort  = _configurations.HostPort,
                UserName  = _configurations.UserName,
                Password  = _configurations.UserName,
                ServiceID = _configurations.ServiceId,
            });


            var ts1 = server.StartAsync();

            ts1.Wait();


            var receivers = new string[] { "13979121569" };
            var content   = "测试短信";

            var totalSpan = TimeSpan.FromMinutes(5);
            int count     = 0;

            int responseCount = 0;
            int reportCount   = 0;

            Task.Run(async() =>
            {
                client.SmsResponseReceived += (sender, e) =>
                {
                    responseCount++;
                };

                client.SmsReportReceived += (sender, e) =>
                {
                    reportCount++;
                };

                await client.StartAsync();

                var start = DateTime.Now;
                DateTime?responseComplete = null;
                DateTime?reportComplete   = null;

                var updateStamp = DateTime.Now;

                while ((DateTime.Now - start) < totalSpan)
                {
                    await client.SendSmsAsync(receivers, content);
                    count++;
                    await Task.Delay(0);

                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }
                }

                var waitSpan  = TimeSpan.FromSeconds(count / 100);
                var waitStart = DateTime.Now;

                while ((DateTime.Now - waitStart) < waitSpan)
                {
                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }

                    if (responseComplete == null && responseCount == count)
                    {
                        responseComplete = DateTime.Now;
                    }

                    if (reportComplete == null && reportCount == count)
                    {
                        reportComplete = DateTime.Now;
                    }

                    if (responseCount == count && reportCount == count)
                    {
                        break;
                    }
                    await Task.Delay(50);
                }

                await client.StopAsync();


                Debug.WriteLine("Messages Sent {0}", count);
                Debug.WriteLine("Rsponses {0}", responseCount);
                Debug.WriteLine("Reports  {0}", reportCount);

                if (responseComplete.HasValue)
                {
                    var duration = (responseComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Submit spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }

                if (reportComplete.HasValue)
                {
                    var duration = (reportComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Report spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }
            }).Wait();

            var ts2 = server.StopAsync();

            ts2.Wait();

            var stats = server.GetStats();

            Debug.WriteLine("Server stats:\r\n");
            Debug.WriteLine(stats);
        }
예제 #8
0
        public void TestCmppSendSmsPerformanceByTime()
        {
            var client = new CmppSmsClient(_configurations);

            var r = new Random();


            var receivers = new string[] { "13979121569" };
            var content   = "测试短信";

            var totalSpan = TimeSpan.FromMinutes(5);
            int count     = 0;

            int responseCount = 0;
            int reportCount   = 0;

            Task.Run(async() =>
            {
                client.SmsResponseReceived += (sender, e) =>
                {
                    responseCount++;
                };

                client.SmsReportReceived += (sender, e) =>
                {
                    reportCount++;
                };

                await client.StartAsync();

                var start = DateTime.Now;
                DateTime?responseComplete = null;
                DateTime?reportComplete   = null;

                var updateStamp = DateTime.Now;

                while ((DateTime.Now - start) < totalSpan)
                {
                    content = "【天天快递】您的快递提取码为" + r.Next(1000000).ToString("000000");

                    await client.SendSmsAsync(receivers, content);
                    count++;
                    await Task.Delay(0);

                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }
                }

                var waitSpan  = TimeSpan.FromSeconds(count / 100);
                var waitStart = DateTime.Now;

                while ((DateTime.Now - waitStart) < waitSpan)
                {
                    if ((DateTime.Now - updateStamp) >= TimeSpan.FromMinutes(1))
                    {
                        updateStamp = DateTime.Now;
                        Debug.WriteLine("{0} {1} {2} ", count, responseCount, reportCount);
                    }

                    if (responseComplete == null && responseCount == count)
                    {
                        responseComplete = DateTime.Now;
                    }

                    if (reportComplete == null && reportCount == count)
                    {
                        reportComplete = DateTime.Now;
                    }

                    if (responseCount == count && reportCount == count)
                    {
                        break;
                    }
                    await Task.Delay(50);
                }

                await client.StopAsync();


                Debug.WriteLine("Messages Sent {0}", count);
                Debug.WriteLine("Rsponses {0}", responseCount);
                Debug.WriteLine("Reports  {0}", reportCount);

                if (responseComplete.HasValue)
                {
                    var duration = (responseComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Submit spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }

                if (reportComplete.HasValue)
                {
                    var duration = (reportComplete.Value - start).TotalSeconds;
                    Debug.WriteLine("Report spent {0} seconds on {1} messages, throughput : {2} mps",
                                    duration, count, count / duration);
                }
            }).Wait();
        }