public static DTLinkPathMgr GetInstance() { if (null == _instance) { lock (SynObj) { if (null == _instance) { _instance = new DTLinkPathMgr(); } } } return(_instance); }
/// <summary> /// 执行一条类型为Get的同步操作命令 /// </summary> /// <param name="cmdName"></param> /// <param name="requestId"></param> /// <param name="strIndex"></param> /// <param name="strIpAddr"></param> /// <param name="lmtPdu"></param> /// <returns></returns> public int CmdGetSync(string cmdName, out long requestId, string strIndex , string strIpAddr, ref CDTLmtbPdu lmtPdu, bool isPrint = false , bool needCheck = false, long timeOut = 0) { requestId = 0; Log.Info("CmdGetSync() start"); string msg = string.Format("cmdName={0},requestId={1},strIndex={2}, strIpAddr={3}" , cmdName, requestId, strIndex, strIpAddr); Log.Info(msg); if (string.IsNullOrEmpty(cmdName) || string.IsNullOrEmpty(strIpAddr)) { return(-1); } // TODO: 数据库先打桩 string strMibList = ""; // test if (cmdName.Equals("aaa")) { strMibList = "100.1.9.1.1|100.1.9.1.2"; } else { strMibList = "100.1.2.1.1.1.5.3"; } if (string.IsNullOrEmpty(strMibList)) { return(-1); } // 转换为oid数组 string[] mibList = StringToArray(strMibList); if (mibList == null) { return(-1); } // TODO : bNeedCheck if (needCheck) { } // TODO: // 获取oid的前缀 string strPreFixOid = "1.3.6.1.4.1.5105"; StringBuilder sbOid = new StringBuilder(); foreach (string v in mibList) { sbOid.Clear(); sbOid.AppendFormat("{0}.{1}{2}", strPreFixOid, v, strIndex); CDTLmtbVb vb = new CDTLmtbVb(); vb.set_Oid(sbOid.ToString()); lmtPdu.AddVb(vb); } lmtPdu.setCmdName(cmdName); lmtPdu.setPrintId(isPrint); lmtPdu.setSyncId(true); // 根据ip获取当前基站的snmp实例 LmtbSnmpEx lmtbSnmpEx = DTLinkPathMgr.GetInstance().getSnmpByIp(strIpAddr); int rs = lmtbSnmpEx.SnmpGetSync(lmtPdu, out requestId, strIpAddr, timeOut); if (rs != 0) { Log.Error("执行lmtbSnmpEx.SnmpGetSync()方法错误"); } return(0); }
/// <summary> /// 执行一条类型为Set的异步操作命令 /// </summary> /// <param name="cmdName"></param> /// <param name="requestId"></param> /// <param name="name2Value"></param> /// <param name="strIndex"></param> /// <param name="strIpAddr"></param> /// <param name="lmtPdu"></param> /// <param name="isPrint"></param> /// <param name="needCheck"></param> /// <param name="timeOut"></param> /// <returns></returns> public int CmdSetAsync(String cmdName, out long requestId, Dictionary <string, string> name2Value , string strIndex, string strIpAddr, bool isPrint = false, bool needCheck = false) { requestId = 0; int rs = 0; CDTLmtbPdu lmtPdu = new CDTLmtbPdu(); // TODO: 从数据库获取命令对应的oid string strMibList = "100.1.2.2.2.1.2|100.1.2.2.2.1.3|100.1.2.2.2.1.4|100.1.2.2.2.1.5|100.1.2.2.2.1.6|100.1.2.2.2.1.7"; if (string.IsNullOrEmpty(strMibList)) { return(-1); } // 将字符串转换为oid数组 string[] mibList = StringToArray(strMibList); if (mibList == null) { return(-1); } string strIndexFmt = string.Format(".{0}", strIndex.Trim('.')); // TODO if (needCheck) { } // 获取oid的前缀 string strPreFixOid = "1.3.6.1.4.1.5105"; StringBuilder sbOid = new StringBuilder(); string strMibValue; string strTyep; string strMibName; foreach (string v in mibList) { sbOid.Clear(); sbOid.AppendFormat("{0}.{1}{2}", strPreFixOid, v, strIndexFmt); CDTLmtbVb vb = new CDTLmtbVb(); vb.set_Oid(sbOid.ToString()); strTyep = ""; strMibName = ""; strMibValue = ""; // TODO: 从数据库中获取oid的名称和数据类型 MibNodeInfoTest mibNodeInfoTest = GetMibNodeInfoByOID(strIpAddr, v); strTyep = mibNodeInfoTest.strType; strMibName = mibNodeInfoTest.strMibName; if (name2Value.ContainsKey(strMibName)) { strMibValue = name2Value[strMibName]; } else { continue; } vb.set_Value(strMibValue); // TODO: vb.set_Syntax(GetAsnTypeByMibType(strTyep)); lmtPdu.AddVb(vb); } // end foreach lmtPdu.setCmdName(cmdName); lmtPdu.setPrintId(isPrint); lmtPdu.setSyncId(true); LmtbSnmpEx lmtbSnmpEx = DTLinkPathMgr.GetInstance().getSnmpByIp(strIpAddr); rs = lmtbSnmpEx.SnmpSetAsync(lmtPdu, out requestId, strIpAddr); if (rs != 0) { Log.Error("执行lmtbSnmpEx.SnmpSetAsync()方法错误"); } return(rs); }