예제 #1
0
        private void startServer_Click(object sender, EventArgs e)
        {
            if (serviceSta == true)
            {
                serviceSta        = false;
                startService.Text = "服务已关闭";
            }
            else
            {
                serviceSta        = true;
                startService.Text = "服务已开启";
            }
            if (sendServiceThread != null)
            {
                return;
            }
            sendServiceThread = new Thread(() =>
            {
                while (serviceSta)
                {
                    SMSDB smddb         = new SMSDB();
                    List <SMSBean> lsms = smddb.queryMessage();
                    foreach (SMSBean sb in lsms)
                    {
                        api_ReceiveCallId(api.SendCNSM(sb.number, sb.message));
                        tools.log.Debug("已发送<<" + sb.toString());
                        this.Invoke(new Action <string>((s) =>
                        {
                            txt_MSG.AppendText(s + "\r\n");
                        }), sb.number + sb.message);

                        smddb.updateMessage(sb.id);
                    }


                    System.Threading.Thread.Sleep(1000);
                }
            });
            sendServiceThread.TrySetApartmentState(ApartmentState.STA);
            sendServiceThread.Start();

            /*
             * reportTheread = new Thread(() =>
             * {
             *  while (serviceSta)
             *  {
             *      reporttask r = new reporttask();
             *      r.reportTask();
             *      System.Threading.Thread.Sleep(2000);
             *  }
             * });
             * reportTheread.TrySetApartmentState(ApartmentState.STA);
             * sendServiceThread.Start();
             */
        }
예제 #2
0
        public void SMSDBTest()
        {
            var accountId = "account";
            SMS sms       = new SMS()
            {
                Account      = accountId,
                Audit        = AuditType.Auto,
                AuditTime    = DateTime.Now.ToString(),
                AuditUser    = "******",
                Channel      = "default",
                Content      = "ceshi neirong",
                Level        = LevelType.Level0,
                IsSplit      = true,
                SendTime     = DateTime.Now,
                SerialNumber = System.Guid.NewGuid(),
                Signature    = "【1111】",
                LinkID       = System.Guid.NewGuid().ToString(),
                SPNumber     = "1234",
                StatusReport = StatusReportType.Enabled,
                Extend       = null,
                FailureCase  = "",
                Filter       = FilterType.Failure,
                Number       = new List <string> {
                    "123", "1235", "234"
                },
                NumberCount = 3,
                WapURL      = "wapurl"
            };

            var b = SMSDB.AddSms(accountId, sms, 0);

            Assert.IsTrue(b);

            var l = SMSDB.GetSMSByAudit(DateTime.Now.AddDays(-5), DateTime.Now.AddDays(5));

            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count > 0);
            l = SMSDB.GetSMSByAudit(accountId, DateTime.Now.AddDays(-5), DateTime.Now.AddDays(5));
            Assert.IsNotNull(l);
            Assert.IsTrue(l.Count > 0);
            b = SMSDB.AuditSMS(sms.SerialNumber, true);
            Assert.IsTrue(b);
            var c = SMSDB.CountSMS(accountId);

            Assert.IsTrue(c > 0);

            var gsms = SMSDB.GetSMS(sms.SerialNumber);

            Assert.IsNotNull(gsms);
            Assert.IsTrue(sms.SerialNumber == gsms.SerialNumber);

            b = SMSDB.SetSMSLevel(sms.SerialNumber, (LevelType)5);
            Assert.IsTrue(b);
            gsms = SMSDB.GetSMS(sms.SerialNumber);
            Assert.IsTrue(gsms.Level == (LevelType)5);

            b = SMSDB.SetSMSLevel(sms.SerialNumber, (LevelType)12);
            Assert.IsTrue(b);
            gsms = SMSDB.GetSMS(sms.SerialNumber);



            SMS sms2 = new SMS()
            {
                Account      = accountId,
                Audit        = AuditType.Auto,
                AuditTime    = DateTime.Now.ToString(),
                AuditUser    = "******",
                Channel      = "default",
                Content      = "ceshi neirong",
                Level        = LevelType.Level0,
                IsSplit      = true,
                SendTime     = DateTime.Now,
                SerialNumber = System.Guid.NewGuid(),
                Signature    = "【1111】",
                LinkID       = System.Guid.NewGuid().ToString(),
                SPNumber     = "1234",
                StatusReport = StatusReportType.Enabled,
                Extend       = null,
                FailureCase  = "",
                Filter       = FilterType.Failure,
                Number       = new List <string> {
                    "123", "1235", "234"
                },
                NumberCount = 3,
                WapURL      = "wapurl"
            };
            SMS sms3 = new SMS()
            {
                Account      = accountId,
                Audit        = AuditType.Auto,
                AuditTime    = DateTime.Now.ToString(),
                AuditUser    = "******",
                Channel      = "default",
                Content      = "ceshi neirong",
                Level        = LevelType.Level0,
                IsSplit      = true,
                SendTime     = DateTime.Now,
                SerialNumber = System.Guid.NewGuid(),
                Signature    = "【1111】",
                LinkID       = System.Guid.NewGuid().ToString(),
                SPNumber     = "1234",
                StatusReport = StatusReportType.Enabled,
                Extend       = null,
                FailureCase  = "",
                Filter       = FilterType.Failure,
                Number       = new List <string> {
                    "123"
                },

                NumberCount = 1,
                WapURL      = "wapurl"
            };

            b = SMSDB.AddSms(accountId, sms2, 1);
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms3, 1);
            Assert.IsTrue(b);



            b = SMSDB.DelSMSs(new List <Guid>()
            {
                sms2.SerialNumber, sms3.SerialNumber
            });
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms, 1);
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms2, 1);
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms3, 1);
            Assert.IsTrue(b);
            l = SMSDB.GetSendSMSByOne(1000, "default");
            Assert.IsTrue(l.Count >= 1);
            l = SMSDB.GetSendSMSByLessHundred(1000, "default");
            Assert.IsTrue(l.Count >= 1);

            b = SMSDB.DelSMSs(new List <Guid>()
            {
                sms.SerialNumber, sms2.SerialNumber, sms3.SerialNumber
            });
            Assert.IsTrue(b);

            sms.SMSTimer  = DateTime.Now;
            sms2.SMSTimer = DateTime.Now;
            sms3.SMSTimer = DateTime.Now;
            b             = SMSDB.AddSms(accountId, sms, 1);
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms2, 1);
            Assert.IsTrue(b);
            b = SMSDB.AddSms(accountId, sms3, 1);
            Assert.IsTrue(b);

            l = SMSDB.GetSendSMSBySMSTimer(DateTime.Now.AddMinutes(1), "default");

            Assert.IsTrue(l.Count >= 3);
            b = SMSDB.DelSMSs(new List <Guid>()
            {
                sms.SerialNumber, sms2.SerialNumber, sms3.SerialNumber
            });
            Assert.IsTrue(b);
        }