//站点基本设置 public static bool SetBaseBox() { //因为恢复出厂设置之后dsp地址会恢复默认值,所以此处要检查下 DB_Talk.Model.m_Box modelbox = new DB_Talk.BLL.m_Box().GetModel(Global.Params.BoxID); if (modelbox != null && !string.IsNullOrEmpty(modelbox.vc_DspIP) && GetDspAddress() != modelbox.vc_DspIP) { MBoxSDK.ConfigSDK.MBOX_SetDspAddress(Global.Params.BoxHandle, modelbox.vc_DspIP); } //因为恢复出厂设置之后调度IP地址会清空,所以此处要重新设置下 List<string> lstIP=new List<string>(); GetDispatcherAddress(out lstIP); if (modelbox != null && !string.IsNullOrEmpty(modelbox.vc_DispatchIP1) ) //&& !lstIP.Contains(modelbox.vc_DispatchIP1)) { lstIP[0]=modelbox.vc_DispatchIP1; } if (modelbox != null && !string.IsNullOrEmpty(modelbox.vc_DispatchIP2) ) //&& !lstIP.Contains(modelbox.vc_DispatchIP2)) { lstIP[1]=modelbox.vc_DispatchIP2; } SetDispatcherAddress(lstIP); //设置CDR服务器 int open = 1, openReal = 2; //1打开,2关闭 if (!MBoxSDK.ConfigSDK.MBOX_SetCdrTrigger(Global.Params.BoxHandle, open, openReal)) return false; //SIP管理设置 if (!SetSipRegisterCycleAndHeartBeatInterval()) return false; //SAP接入点设置 DB_Talk.Model.m_SAPPoint model = new DB_Talk.Model.m_SAPPoint(); model.BoxID = Global.Params.BoxID; model.SAPID = 1; model.i_Port = 5060; model.i_Type = 1; if(!CreateSipSap(model)) { return false; } //设置默认的呼叫源、路由规则、呼叫源规则 if (!Tools.MBoxOperate.CreateCalinglSourceRule()) { 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; }
//获取SAP接入点 private static bool GetSipSap(out List<DB_Talk.Model.m_SAPPoint> lst) { byte[] byteArray = new byte[ArraySizeBig]; int len = 0; bool b = MBoxSDK.ConfigSDK.MBOX_GetSipSap(Global.Params.BoxHandle, byteArray, (uint)byteArray.Length, ref len); lst = new List<DB_Talk.Model.m_SAPPoint>(); 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_SAPPoint m = new DB_Talk.Model.m_SAPPoint(); string[] strArray2 = strArray[i].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); m.SAPID = int.Parse(strArray2[0]); m.i_Port = int.Parse(strArray2[1]); m.i_Type = int.Parse(strArray2[2]); m.BoxID = Global.Params.BoxID; lst.Add(m); } } return b; }
/// <summary> /// 获得数据列表 /// </summary> public List<DB_Talk.Model.m_SAPPoint> DataTableToList(DataSet ds) { List<DB_Talk.Model.m_SAPPoint> modelList = new List<DB_Talk.Model.m_SAPPoint>(); if (ds == null) return modelList; DataTable dt = ds.Tables[0]; int rowsCount = dt.Rows.Count; if (rowsCount > 0) { DB_Talk.Model.m_SAPPoint model; for (int n = 0; n < rowsCount; n++) { model = new DB_Talk.Model.m_SAPPoint(); 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]["SAPID"]!=null && dt.Rows[n]["SAPID"].ToString()!="") { model.SAPID=int.Parse(dt.Rows[n]["SAPID"].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_Port"]!=null && dt.Rows[n]["i_Port"].ToString()!="") { model.i_Port=int.Parse(dt.Rows[n]["i_Port"].ToString()); } if(dt.Rows[n]["i_Type"]!=null && dt.Rows[n]["i_Type"].ToString()!="") { model.i_Type=int.Parse(dt.Rows[n]["i_Type"].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; }
/// <summary> /// 根据条件得到一个对象实体 /// </summary> public DB_Talk.Model.m_SAPPoint GetModel(string strWhere) { StringBuilder strSql=new StringBuilder(); strSql.Append(" select top 1 "); strSql.Append(" ID, BoxID, SAPID, vc_Code, vc_Name, i_Port, i_Type, vc_Memo, i_Flag "); strSql.Append(" from m_SAPPoint "); if(strWhere.Trim()!="") { strSql.Append(" where "+strWhere); } DB_Talk.Model.m_SAPPoint model=new DB_Talk.Model.m_SAPPoint(); DataSet ds=GetDataSet(strSql.ToString()); if(ds!=null && ds.Tables[0].Rows.Count>0) { model=DataTableToList(ds)[0]; return model; } else { return null; } }