Пример #1
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);
        }