Example #1
0
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DB_Talk.Model.m_Route> DataTableToList(DataSet ds)
		{
			List<DB_Talk.Model.m_Route> modelList = new List<DB_Talk.Model.m_Route>();
			if (ds == null) return modelList;
            DataTable dt = ds.Tables[0];
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DB_Talk.Model.m_Route model;
				for (int n = 0; n < rowsCount; n++)
				{
				  model = new DB_Talk.Model.m_Route();	
                  if(dt.Rows[n]["ID"]!=null && dt.Rows[n]["ID"].ToString()!="")
				  {
				      model.ID=int.Parse(dt.Rows[n]["ID"].ToString());
				  }
				  if(dt.Rows[n]["BoxID"]!=null && dt.Rows[n]["BoxID"].ToString()!="")
				  {
				      model.BoxID=int.Parse(dt.Rows[n]["BoxID"].ToString());
				  }
				  if(dt.Rows[n]["RouteGroupID"]!=null && dt.Rows[n]["RouteGroupID"].ToString()!="")
				  {
				      model.RouteGroupID=int.Parse(dt.Rows[n]["RouteGroupID"].ToString());
				  }
				  if(dt.Rows[n]["vc_Code"]!=null && dt.Rows[n]["vc_Code"].ToString()!="")
				  {
				     model.vc_Code= dt.Rows[n]["vc_Code"].ToString();
				  }
				  if(dt.Rows[n]["vc_Name"]!=null && dt.Rows[n]["vc_Name"].ToString()!="")
				  {
				     model.vc_Name= dt.Rows[n]["vc_Name"].ToString();
				  }
				  if(dt.Rows[n]["i_RouteType"]!=null && dt.Rows[n]["i_RouteType"].ToString()!="")
				  {
				      model.i_RouteType=int.Parse(dt.Rows[n]["i_RouteType"].ToString());
				  }
				  if(dt.Rows[n]["i_LoadBalance"]!=null && dt.Rows[n]["i_LoadBalance"].ToString()!="")
				  {
				      model.i_LoadBalance=int.Parse(dt.Rows[n]["i_LoadBalance"].ToString());
				  }
				  if(dt.Rows[n]["vc_Memo"]!=null && dt.Rows[n]["vc_Memo"].ToString()!="")
				  {
				     model.vc_Memo= dt.Rows[n]["vc_Memo"].ToString();
				  }
				  if(dt.Rows[n]["i_Flag"]!=null && dt.Rows[n]["i_Flag"].ToString()!="")
				  {
				      model.i_Flag=int.Parse(dt.Rows[n]["i_Flag"].ToString());
				  }
				   modelList.Add(model);
				
				}
			}
			return modelList;
		}
        //删除中继
        public static bool DeletePRI(DB_Talk.Model.m_PRIInterface model)
        {
            //去激活PRI中继
            if (!SetPRITrunkDective(model))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("去激活PRI失败");
                return false;
            }

            //删除信令信道
            DB_Talk.Model.m_PRISigLink PRISigLinkModel = new DB_Talk.Model.m_PRISigLink();
            PRISigLinkModel.PRIID = model.PRIID;
            if (!DeleteAllSigChannel(PRISigLinkModel.PRIID))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("删除信令信道失败");
                return false;
            }


            //删除承载信道
            if (!DeleteT1Channel(model.PRIID))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("删除承载信道失败");
                return false;
            }

            //删除中继
            if (!DeletePriTrunkByID(model))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("删除PRI失败");
                return false;
            }

            //删除路由规则0,PRIID,PRIID
            DB_Talk.Model.m_RouteRule modelRRule = new DB_Talk.Model.m_RouteRule();
            modelRRule.OriRouteID = 0;
            modelRRule.DestRouteID = model.RouteID;
            modelRRule.ID = model.RouteID;
            modelRRule.BoxID = Global.Params.BoxID;
            if (!DeleteRoutingRule(modelRRule))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("删除路由规则失败");
                return false;
            }
           

            //删除路由
            DB_Talk.Model.m_Route mR = new DB_Talk.Model.m_Route();
            mR.ID = model.RouteID;
            mR.vc_Name = "PRI" + model.PRIID.ToString();
            mR.RouteGroupID = model.RouteID;
            mR.i_RouteType = 1; //1: btw(1)双向(默认)
            if (!DeleteRoute(mR))
                return false;

            //删除路由组
            DB_Talk.Model.m_RouteGroup mRg = new DB_Talk.Model.m_RouteGroup();
            mRg.vc_Name = "PRI" + model.PRIID.ToString();
            mRg.ID = model.RouteID;
            if (!DeleteRouteGroup(mRg))
            {
                return false;
            }
          
            //删除呼叫规则

            return true;
        }
Example #3
0
		/// <summary>
		/// 根据条件得到一个对象实体
		/// </summary>
		public DB_Talk.Model.m_Route GetModel(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("  select top 1 ");
			strSql.Append("  ID, BoxID, RouteGroupID, vc_Code, vc_Name, i_RouteType, i_LoadBalance, vc_Memo, i_Flag  ");			
			strSql.Append("  from m_Route ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			DB_Talk.Model.m_Route model=new DB_Talk.Model.m_Route();
			DataSet ds=GetDataSet(strSql.ToString());
			if(ds!=null && ds.Tables[0].Rows.Count>0)
			{
                model=DataTableToList(ds)[0];						
				return model;
			}
			else
			{
				return null;
			}
		}
        //创建中继
        public static bool createPRI(DB_Talk.Model.m_PRIInterface newmodel, List<DB_Talk.Model.m_CalledRule> lstRuleAdd, List<DB_Talk.Model.m_CalledRule> lstRuleDelete)
        {
            //创建路由组
            DB_Talk.Model.m_RouteGroup mRg = new DB_Talk.Model.m_RouteGroup();
            mRg.vc_Name = "PRI" + newmodel.PRIID.ToString();
            int routeGroupID = 0;
            if (!CreateRouteGroup(mRg, out routeGroupID))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加PRI路由组失败");
                return false;
            }
            newmodel.RouteID = routeGroupID;
            //创建路由
            DB_Talk.Model.m_Route mR = new DB_Talk.Model.m_Route();
            mR.ID = routeGroupID;
            mR.RouteGroupID = routeGroupID;
            mR.vc_Name = "PRI" + newmodel.PRIID.ToString();
            mR.i_RouteType = MBoxSDK.ConfigSDK.EnumRouteType.btw.GetHashCode();
            if (!CreateRoute(mR))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加PRI路由失败");
                return false;
            }

            //创建路由规则0,PRIID,PRIID
            DB_Talk.Model.m_RouteRule modelRRule = new DB_Talk.Model.m_RouteRule();
            modelRRule.OriRouteID = 0;
            modelRRule.DestRouteID = newmodel.RouteID;
            modelRRule.ID = newmodel.RouteID;
            modelRRule.BoxID = Global.Params.BoxID;
            if (!CreateRoutingRule(modelRRule))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加路由规则失败");
                return false;
            }
            

            //创建PRI中继
            if (!CreatePriTrunk(newmodel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加PRI失败");
                return false;
            }
            //创建承载新道
            DB_Talk.Model.m_PRIChannel PRIChannelModel = new DB_Talk.Model.m_PRIChannel();
            PRIChannelModel.i_E1Port = newmodel.i_E1Port;
            PRIChannelModel.i_LinkID = newmodel.i_LinkID;
            PRIChannelModel.PRIID = newmodel.PRIID;
            if (!CreateT1Channel(PRIChannelModel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加承载信道失败");
                return false;
            }

            //创建信令新道

            DB_Talk.Model.m_PRISigLink PRISigLinkModel = new DB_Talk.Model.m_PRISigLink();
            PRISigLinkModel.i_E1Port = newmodel.i_E1Port;
            PRISigLinkModel.i_LinkID = newmodel.i_LinkID;
            PRISigLinkModel.PRIID = newmodel.PRIID;
            PRISigLinkModel.i_UNIType = newmodel.i_UNIType;
            if (!CreateSigChannel(PRISigLinkModel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加信令信道失败");
                return false;
            }

            //激活PRI中继
            if (!SetPRITrunkActive(newmodel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("激活PRI失败");
                return false;
            }

            //添加被叫规则
            foreach (DB_Talk.Model.m_CalledRule d in lstRuleAdd)
            {
                d.DestRouteID = routeGroupID;
                if (!CreateCall_OutRule(d))
                {
                    CommControl.Tools.WriteLog.AppendErrorLog("添加被叫规则失败,被叫号码为:" + d.vc_CalledNumber);
                    DeletePRI(newmodel);
                    return false;
                }
            }
            if (!Delete_Rule(lstRuleAdd, lstRuleDelete))
                return false;


            return true;

        }
 //查询路由
 private static bool QueryRoute(out List<DB_Talk.Model.m_Route> lstRoute)
 {
     bool b = false;
     lstRoute = new List<DB_Talk.Model.m_Route>();
     byte[] byteArray = new byte[ArraySizeBig];
     int len = ArraySizeBig;
     b = MBoxSDK.ConfigSDK.MBOX_GetRouting(Global.Params.BoxHandle, byteArray, (uint)byteArray.Length, ref len);
     //if (b)
     {
         string str = System.Text.Encoding.Default.GetString(byteArray);
         str = str.Replace("\0", "");
         string[] strArray = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
         for (int i = 0; i < strArray.Length; i++)
         {
             DB_Talk.Model.m_Route m = new DB_Talk.Model.m_Route();
             string[] strArray2 = strArray[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
             m.ID = (int.Parse(strArray2[0]));
             m.i_RouteType = (int.Parse(strArray2[1]));
             m.RouteGroupID = (int.Parse(strArray2[2]));
             m.vc_Name = strArray2[3];
             m.BoxID = Global.Params.BoxID;
             lstRoute.Add(m);
             //"路由ID,路由类型,路由组ID,路由名称"
         }
     }
     return b;
 }
        /// <summary>创建SMS</summary>
        /// <returns></returns>
        public static bool CreateSMS(DB_Talk.Model.SMSConfig smsModel)
        {
            bool b = false;
            #region 路由组
            
            
            DB_Talk.Model.m_RouteGroup group = new DB_Talk.Model.m_RouteGroup();
            group.vc_Name = "SMS";
            int groupID = 0;

            if (CreateRouteGroup(group, out groupID) == false) return false ;
            #endregion

            #region 路由
            
            
            DB_Talk.Model.m_Route route = new DB_Talk.Model.m_Route();
            route.RouteGroupID = groupID;
            route.ID = groupID;
            route.i_RouteType = MBoxSDK.ConfigSDK.EnumRouteType.esme.GetHashCode();
            route.vc_Name = "SMS";

            if (CreateRoute(route) == false) return false;

            #endregion

            if (DeleteAllSMSConfig() == false) return false;
            if (CreateSMSEntry(route.ID, smsModel.SystemID, smsModel.Password) == false) return false;
            if (CreateSMSIP(smsModel.IP) == false) return false;
            return true;
        }
        public static bool DeleteSIP(DB_Talk.Model.m_SIPInterface model)
        {
            //去激活SIP
            if (!SetSipTrunkDective(model))
                return false;

            //删除SIP
            if (!DeleteSipTrunkByID(model))
                return false;

            //删除SAP接入点
            DB_Talk.Model.m_SAPPoint msap = new DB_Talk.Model.m_SAPPoint();
            msap.SAPID = model.SIPID + 1;
            msap.i_Port = model.i_Port;
            msap.i_Type = 1;   //默认1=udp
            if (!DeleteSipSap(msap))
                return false;

            //删除路由规则0,PRIID,PRIID
            DB_Talk.Model.m_RouteRule modelRRule = new DB_Talk.Model.m_RouteRule();
            modelRRule.OriRouteID = 0;
            modelRRule.DestRouteID = model.RouteID;
            modelRRule.ID = model.RouteID;
            modelRRule.BoxID = Global.Params.BoxID;
            if (!DeleteRoutingRule(modelRRule))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("删除路由规则失败");
                return false;
            }

            //删除路由
            DB_Talk.Model.m_Route mR = new DB_Talk.Model.m_Route();
            mR.ID = model.RouteID;
            mR.vc_Name = "SIP" + model.SIPID.ToString();
            mR.RouteGroupID = model.RouteID;
            mR.i_RouteType = 1; //1: btw(1)双向(默认)
            if (!DeleteRoute(mR))
                return false;

            //删除路由组
            DB_Talk.Model.m_RouteGroup mRg = new DB_Talk.Model.m_RouteGroup();
            mRg.vc_Name = "SIP" + model.SIPID.ToString();
            mRg.ID = model.RouteID;
            if (!DeleteRouteGroup(mRg))
            {
                return false;
            }

            return true;

        }
        private static bool createSIP(DB_Talk.Model.m_SIPInterface newmodel, List<DB_Talk.Model.m_CalledRule> lstRuleAdd, List<DB_Talk.Model.m_CalledRule> lstRuleDelete)
        {
            //创建路由组
            DB_Talk.Model.m_RouteGroup mRg = new DB_Talk.Model.m_RouteGroup();
            mRg.vc_Name = "SIP" + newmodel.SIPID.ToString();
            int routeGroupID = 0;
            if (!CreateRouteGroup(mRg, out routeGroupID))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加路由组失败");
                return false;
            }
            newmodel.RouteID = routeGroupID;
            //创建路由
            DB_Talk.Model.m_Route mR = new DB_Talk.Model.m_Route();
            mR.ID = routeGroupID;
            mR.RouteGroupID = routeGroupID;
            mR.vc_Name = "SIP" + newmodel.SIPID.ToString();
            mR.i_RouteType = MBoxSDK.ConfigSDK.EnumRouteType.btw.GetHashCode();
            if (!CreateRoute(mR))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加路由失败");
                return false;
            }

            //创建路由规则0,PRIID,PRIID
            DB_Talk.Model.m_RouteRule modelRRule = new DB_Talk.Model.m_RouteRule();
            modelRRule.OriRouteID = 0;
            modelRRule.DestRouteID = newmodel.RouteID;
            modelRRule.ID = newmodel.RouteID;
            modelRRule.BoxID = Global.Params.BoxID;
            if (!CreateRoutingRule(modelRRule))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加路由规则失败");
                return false;
            }
            
            //创建SAP接入点
            DB_Talk.Model.m_SAPPoint msap = new DB_Talk.Model.m_SAPPoint();
            msap.SAPID = newmodel.SIPID +1;
            msap.i_Port = newmodel.i_Port;
            msap.i_Type = 1;   //默认1=udp
            if (!CreateSipSap(msap))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加SAP失败");
                return false;
            }
            //创建SIP
            if (!CreateSipTrunk(newmodel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("添加SIP失败");
                return false;
            }
            //激活SIP
            if (!SetSipTrunkActive(newmodel))
            {
                CommControl.Tools.WriteLog.AppendErrorLog("激活SIP失败");
                return false;
            }

            //添加被叫规则
            foreach (DB_Talk.Model.m_CalledRule d in lstRuleAdd)
            {
                d.DestRouteID = routeGroupID;
                if (!CreateCall_OutRule(d))
                {
                    CommControl.Tools.WriteLog.AppendErrorLog("添加被叫规则失败,被叫号码为:" + d.vc_CalledNumber);
                    DeleteSIP(newmodel);
                    return false;
                }
            }
            if (!Delete_Rule(lstRuleAdd, lstRuleDelete))
                return false;

            return true;

        }