Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            // set timeout as 3 sec
            TimeSpan cacheTimeout = new TimeSpan(0, 0, 3);

            // KEY_TYPE : string
            // VALUE_TYPE : int
            TimeoutCache<string, int> cache = new TimeoutCache<string, int>(cacheTimeout);

            // set value
            cache["hihi"] = 10;

            while (true)
            {
                try
                {
                    int val = cache["hihi"];
                    Console.WriteLine("Cache hit. value : {0}", val);
                }
                catch (TimeoutCacheMissException)
                {
                    Console.WriteLine("Cache miss");
                }

                // sleep 1 sec
                Thread.Sleep(1000);
            }
        }
Ejemplo n.º 2
0
        public bool Start()
        {
            lp = new LocalParams();
            if (!dbexec.IsConn(lp.SqlConnStr))
            {
                SMSLog.Debug("SmsService==>Init=>sql登录失败[" + lp.SqlConnStr + "]");
                return(false);
            }
            MySqlDBExec.ConnectionstringLocalTransaction = lp.SqlConnStr;
            _cstDic         = new Dictionary <int, SendThread>();
            _cmppAccountDic = new Dictionary <int, AccountInfoModel>();
            //初始数据标识
            string sql1 = "update t_sendsms set CTSubmitStatus=0 Where  CTGatewayNum='" + lp.GateWayNum + "'";
            string sql2 = "update t_smsmobile_t set  smsFlag='0' where SubmitStatus='0' and GatewayNum='" + lp.GateWayNum + "'";
            int    re1  = MySqlDBExec.ExecuteNonQuery(sql1, null);

            SMSLog.Debug("SmsService==>Init初始内容表:" + re1);
            int re2 = MySqlDBExec.ExecuteNonQuery(sql2, null);

            SMSLog.Debug("SmsService==>Init初始手机号码表:" + re2);


            cache          = new TimeoutCache(60 * 30);//缓存
            ReportQueue    = new SMDQueue[_reportQueueNum];
            ReportSeqQueue = new SMDQueue[_reportQueueNum];
            for (int i = 0; i < _reportQueueNum; i++)
            {
                string title = "Report_" + i;
                ReportQueue[i] = new SMDQueue(title);
                ReportQueue[i].Start(3000);

                string seqt = "ReportSeq_" + i;
                ReportSeqQueue[i] = new SMDQueue(seqt);
                ReportSeqQueue[i].Start(4000);
            }

            /*
             * GlobalModel.UpdateMobileSubmitStateHandler = this.UpdateMobileSubmitState;
             * GlobalModel.UpdateReportStateHandler = this.UpdateReportState;
             * GlobalModel.UpdateMobileByBatchNumHandler = this.UpdateMobileByBatchNum;
             * GlobalModel.UpdateSMSContentSubmitStatuHandler = this.UpdateSMSContentSubmitStatu;
             * GlobalModel.DeleteContentHandler = this.DeleteContent;
             * GlobalModel.SaveMoHandler = this.SaveMo;
             * */

            //读取企业CMPP账号信息
            List <AccountInfoModel> accountLst = LoadCmppAccount();

            if (accountLst != null && accountLst.Count > 0)
            {
                foreach (AccountInfoModel m in accountLst)
                {
                    SendThread cmpp = new SendThread(m);

                    if (cmpp.Login())
                    {
                        _cstDic.Add(m.eprId, cmpp);
                        _cmppAccountDic.Add(m.eprId, m);
                        cmpp.IsSend = true;
                        cmpp.Start();
                    }
                    else
                    {
                        SMSLog.Debug("SmsService==>Init[" + m.eprId + "]登录失败");
                    }
                    Thread.Sleep(10);
                }
            }
            else
            {
                SMSLog.Debug("SmsService==>[Init]读取cmpp账号失败");
                return(false);
            }

            GlobalModel.IsStopCollect = false;
            CollectObject_Business co = new CollectObject_Business();

            _collDataTimer = new Timer(new TimerCallback(CollectThread), co, lp.ReadContentDealy, lp.ReadContentDealy);
            SMSLog.Debug("SmsService==>[Init]启动成功");
            return(true);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Clears the cache
 /// </summary>
 public void Clear()
 {
     HandlerCache.Clear();
     TimeoutCache.Clear();
 }