Beispiel #1
0
 /// <summary>
 /// 添加映射脚本到缓存
 /// </summary>
 /// <param name="objScript"></param>
 public static void AddCacheMapScript(SmsServer.Model.MapScript objScript)
 {
     lock (pMapScriptList)
     {
         pMapScriptList[objScript.MapID] = objScript;
     }
 }
Beispiel #2
0
        /// <summary>
        /// 判断映射名称或映射编号是否已经存在
        /// </summary>
        public bool ExistsExEx(SmsServer.Model.MapScript model)
        {
            int iRowCount = MyDataBase.db.Select(SmsPlatForm.MapScript)
                            .Where(SmsPlatForm.MapScript.MapID == model.MapID ||
                                   SmsPlatForm.MapScript.MapName == model.MapName).ToDataSet().Tables[0].Rows.Count;

            return(iRowCount > 0 ? true : false);
        }
Beispiel #3
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(string strJson, out string strout)
 {
     SmsServer.Model.MapScript model = (SmsServer.Model.MapScript)JavaScriptConvert.DeserializeObject(strJson, typeof(SmsServer.Model.MapScript));
     if (dal.ExistsExEx(model))
     {
         strout = "映射编号或映射名称已存在";
         return(false);
     }
     strout = "添加映射失败";
     if (string.IsNullOrEmpty(model.MoSpgate))
     {
         model.MoSpgate = "";
     }
     return(dal.Add(model));
 }
Beispiel #4
0
 /// <summary>
 /// 更新一条数据
 /// </summary>
 public bool Update(SmsServer.Model.MapScript model)
 {
     try
     {
         MyDataBase.db.Update(SmsPlatForm.MapScript)
         .AddColumn(SmsPlatForm.MapScript.MapName, model.MapName)
         .AddColumn(SmsPlatForm.MapScript.ScriptFlag, model.ScriptFlag)
         .AddColumn(SmsPlatForm.MapScript.ScriptType, model.ScriptType)
         .AddColumn(SmsPlatForm.MapScript.ScriptCode, model.ScriptCode)
         .AddColumn(SmsPlatForm.MapScript.MoSpgate, model.MoSpgate)
         .AddColumn(SmsPlatForm.MapScript.MapInfo, model.MapInfo)
         .Where(SmsPlatForm.MapScript.MapID == model.MapID).Execute();
         return(true);
     }
     catch (System.Exception e)
     {
         //记录日志
         return(false);
     }
 }
Beispiel #5
0
 /// <summary>
 /// 增加一条数据
 /// </summary>
 public bool Add(SmsServer.Model.MapScript model)
 {
     try
     {
         MyDataBase.db.Insert(SmsPlatForm.MapScript)
         .AddColumn(SmsPlatForm.MapScript.MapID, model.MapID)
         .AddColumn(SmsPlatForm.MapScript.MapName, model.MapName)
         .AddColumn(SmsPlatForm.MapScript.ScriptFlag, model.ScriptFlag)
         .AddColumn(SmsPlatForm.MapScript.ScriptType, model.ScriptType)
         .AddColumn(SmsPlatForm.MapScript.ScriptCode, model.ScriptCode)
         .AddColumn(SmsPlatForm.MapScript.EasyScriptCode, "")
         .AddColumn(SmsPlatForm.MapScript.MoSpgate, model.MoSpgate)
         .AddColumn(SmsPlatForm.MapScript.MapInfo, model.MapInfo).Execute();
         return(true);
     }
     catch (System.Exception e)
     {
     }
     return(false);
 }
Beispiel #6
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(string strJson, out string strout)
        {
            SmsServer.Model.MapScript model = (SmsServer.Model.MapScript)JavaScriptConvert.DeserializeObject(strJson, typeof(SmsServer.Model.MapScript));
            if (dal.ExistsEx(model))
            {
                strout = "映射名称已经存在";
                return(false);
            }
            strout = "更新映射失败";
            //把参数字段匹配好
            if (string.IsNullOrEmpty(model.MoSpgate))
            {
                model.MoSpgate = "";
            }
            bool bRet = dal.Update(model);

            if (bRet)
            {
                DataCache.DeleteCacheMapScript(model.MapID);
            }
            //清除缓存
            return(bRet);
        }
Beispiel #7
0
        /// <summary>
        /// 从缓存中取映射脚本
        /// </summary>
        /// <param name="strMapID"></param>
        /// <param name="objScript"></param>
        /// <returns></returns>
        public static bool GetCacheMapScript(string strMapID, ref SmsServer.Model.MapScript objScript)
        {
            bool bExist = false;

            lock (pMapScriptList)
            {
                bExist = pMapScriptList.ContainsKey(strMapID);
                if (bExist)
                {
                    objScript = pMapScriptList[strMapID];
                }
            }
            if (!bExist)
            {
                objScript = new MapScript().GetSelectMapScript(strMapID);
                if (objScript == null)
                {
                    return(false);
                }
                AddCacheMapScript(objScript);
            }
            return(true);
        }
Beispiel #8
0
        /// <summary>
        /// 发送线程执行函数
        /// </summary>
        /// <param name="iThreadNumber"></param>
        private static void SendProc(object iThreadNumber)
        {
            string strShow = string.Format("线程:{0}启动", iThreadNumber.ToString( ));

            ShowInfo(strShow);
            Thread.Sleep(500);
            SmsTaskEx        objSmsTask = new SmsTaskEx();
            SmsSpgateEx      objSpgate  = new SmsSpgateEx();
            string           strContent = string.Empty;
            string           strParams  = string.Empty;
            string           strPortUrl = string.Empty;
            string           strRet     = string.Empty;
            MapScriptEx      objMap     = new MapScriptEx();
            DataAdapterClass objAdapter = new DataAdapterClass();

            Model.SendRetValue objRetValue = new Model.SendRetValue();
            SmsHistory         objHist     = new SmsHistory();
            DateTime           oldLogTime  = DateTime.Now;

            while (!m_bExit)
            {
                if ((int)iThreadNumber == 0)
                {
                    TimeSpan tSpan     = DateTime.Now - oldLogTime;
                    int      iInterval = SmsSetIni.QueryInterval;
                    if (tSpan.TotalSeconds > iInterval)
                    {
                        strPortUrl = SmsSetIni.KeepQueryUrl + "OnlineQuery.aspx?";
                        oldLogTime = DateTime.Now;
                        strParams  = "url=" + HttpUtility.UrlEncode(SmsSetIni.KeepOnlineUrl) + "&" + DateTime.Now.ToString("yyyyMMddhhmmss");
                        strRet     = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, 30000, 0, 2);
                    }
                }
                Thread.Sleep(SmsSetIni.SendThreadInterval);
                try
                {
                    objSmsTask = QueueManage <SmsTaskEx> .GetSingleMessage(SmsSetIni.TaskQueuePath);

                    if (objSmsTask == null)
                    {
                        //Thread.Sleep(100);
                        continue;
                    }
                    //strShow = string.Format("线程:{0}从消息队列中读取到数据。 。 。", iThreadNumber.ToString());
                    //ShowInfo(strShow);
                    //拿到后,从缓存中获取通道信息,获取通道各参数后发送
                    if (!DataCache.GetCacheSpgate(objSmsTask.SpgateNo, ref objSpgate))
                    {
                        //通道不存在,保存失败历史
                        continue;
                    }
                    strContent = ConvertString(objSmsTask.MsgContent, objSpgate.EncodeType);
                    strParams  = string.Format(objSpgate.SendParams, objSmsTask.PhoneList.Substring(0, objSmsTask.PhoneList.Length - 1),
                                               strContent, objSmsTask.PhoneNum, objSmsTask.SubPort + objSmsTask.SubPortEx, objSmsTask.SpgateNo);
                    strPortUrl = objSpgate.PortUrl;
                    //发送
                    strRet = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, objSpgate.TimeOut, objSpgate.EncodeType, objSpgate.SendType);
                    //先处理PostError[-1111]返回值
                    if (strRet.IndexOf("PostError[-1111]") == 0)
                    {
                        //POST异常,重发
                        objHist.Add(objSmsTask, 1, "", strRet);
                        continue;
                    }
                    string strPtMsgID = string.Empty;
                    //拿到结果后,匹配返回值
                    if (!DataCache.GetCacheMapScript(objSpgate.MtScriptID, ref objMap))   //如果没有匹配到映射脚本
                    {
                        //无映射脚本,默认成功
                        objHist.Add(objSmsTask, 0, strPtMsgID, "无映射脚本,默认成功");
                        continue;
                    }
                    //找到了脚本
                    if (!objAdapter.AdapterSendResult(objMap.ScriptCode, strRet, ref objRetValue))
                    {
                        //映射异常,算成功
                        objHist.Add(objSmsTask, 0, strPtMsgID, objRetValue.RetInfo);
                        continue;
                    }
                    if (objRetValue.RetValue == 0) //发送成功了
                    {
                        objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                    }
                    else
                    {
                        if (objRetValue.IsNeedResend != 1)  //需要重发
                        {
                            //处理重发
                            //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                        }
                        else
                        {
                            //保存失败历史
                            //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                        }
                        objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                    }
                    //根据匹配到的返回值决定是否需要重发此数据,如果不重发,则保存至历史表中
                    //保存发送历史
                    ShowInfo(strRet);
                }
                catch (Exception e)
                {
                    ShowInfo(e.Message);
                    Thread.Sleep(2000);
                }
            }
            strShow = string.Format("线程:{0}退出", iThreadNumber.ToString());
            ShowInfo(strShow);
        }
 /// <summary>
 /// 发送线程执行函数
 /// </summary>
 /// <param name="iThreadNumber"></param>
 private static void SendProc(object iThreadNumber)
 {
     string strShow = string.Format("线程:{0}启动", iThreadNumber.ToString( ));
     ShowInfo(strShow);
     Thread.Sleep(500);
     SmsTaskEx objSmsTask = new SmsTaskEx();
     SmsSpgateEx objSpgate = new SmsSpgateEx();
     string strContent = string.Empty;
     string strParams = string.Empty;
     string strPortUrl = string.Empty;
     string strRet = string.Empty;
     MapScriptEx objMap = new MapScriptEx();
     DataAdapterClass objAdapter = new DataAdapterClass();
     Model.SendRetValue objRetValue = new Model.SendRetValue();
     SmsHistory objHist = new SmsHistory();
     DateTime oldLogTime = DateTime.Now;
     while (!m_bExit)
     {
         if ((int)iThreadNumber == 0 )
         {
             TimeSpan tSpan = DateTime.Now - oldLogTime ;
             int iInterval = SmsSetIni.QueryInterval;
             if (tSpan.TotalSeconds > iInterval)
             {
                 strPortUrl = SmsSetIni.KeepQueryUrl  + "OnlineQuery.aspx?";
                 oldLogTime = DateTime.Now;
                 strParams = "url="+HttpUtility.UrlEncode(SmsSetIni.KeepOnlineUrl) + "&" + DateTime.Now.ToString("yyyyMMddhhmmss");
                 strRet = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, 30000, 0, 2);
             }
         }
         Thread.Sleep(SmsSetIni.SendThreadInterval);
         try
         {
             objSmsTask = QueueManage<SmsTaskEx>.GetSingleMessage(SmsSetIni.TaskQueuePath);
             if (objSmsTask == null)
             {
                 //Thread.Sleep(100);
                 continue;
             }
             //strShow = string.Format("线程:{0}从消息队列中读取到数据。 。 。", iThreadNumber.ToString());
             //ShowInfo(strShow);
             //拿到后,从缓存中获取通道信息,获取通道各参数后发送
             if (!DataCache.GetCacheSpgate(objSmsTask.SpgateNo, ref objSpgate))
             {
                 //通道不存在,保存失败历史
                 continue;
             }
             strContent = ConvertString(objSmsTask.MsgContent, objSpgate.EncodeType);
             strParams = string.Format(objSpgate.SendParams, objSmsTask.PhoneList.Substring(0, objSmsTask.PhoneList.Length - 1),
                 strContent, objSmsTask.PhoneNum, objSmsTask.SubPort + objSmsTask.SubPortEx, objSmsTask.SpgateNo);
             strPortUrl = objSpgate.PortUrl;
             //发送
             strRet = SmsHttpSend.HttpSendMessge(ref strPortUrl, ref strParams, objSpgate.TimeOut, objSpgate.EncodeType, objSpgate.SendType);
             //先处理PostError[-1111]返回值
             if (strRet.IndexOf("PostError[-1111]") == 0)
             {
                 //POST异常,重发
                 objHist.Add(objSmsTask, 1, "", strRet);
                 continue;
             }
             string strPtMsgID = string.Empty;
             //拿到结果后,匹配返回值
             if (!DataCache.GetCacheMapScript(objSpgate.MtScriptID, ref objMap))   //如果没有匹配到映射脚本
             {
                 //无映射脚本,默认成功
                 objHist.Add(objSmsTask, 0, strPtMsgID, "无映射脚本,默认成功");
                 continue;
             }
             //找到了脚本
             if (!objAdapter.AdapterSendResult(objMap.ScriptCode, strRet, ref objRetValue))
             {
                 //映射异常,算成功
                 objHist.Add(objSmsTask, 0, strPtMsgID, objRetValue.RetInfo);
                 continue;
             }
             if (objRetValue.RetValue == 0) //发送成功了
             {
                 objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
             }
             else
             {
                 if (objRetValue.IsNeedResend != 1)  //需要重发
                 {
                     //处理重发
                     //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                 }
                 else
                 {
                     //保存失败历史
                     //objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
                 }
                 objHist.Add(objSmsTask, objRetValue.RetValue, strPtMsgID, objRetValue.RetInfo);
             }
             //根据匹配到的返回值决定是否需要重发此数据,如果不重发,则保存至历史表中
             //保存发送历史
             ShowInfo(strRet);
         }
         catch (Exception e)
         {
             ShowInfo(e.Message);
             Thread.Sleep(2000);
         }
     }
     strShow = string.Format("线程:{0}退出", iThreadNumber.ToString());
     ShowInfo(strShow);
 }