void ReceiveRes(IAsyncResult ar) { SnmpMessageResult res = ar as SnmpMessageResult; foreach (KeyValuePair <string, string> iter in res.AsyncState as Dictionary <string, string> ) { Console.WriteLine("NextIndex" + iter.Key.ToString() + "Value:" + iter.Value.ToString()); } }
/// <summary> /// 按照单个节点进行GetNext; /// 该函数将所有数据收集完成后再通知主界面DataGrid更新; /// </summary> /// <param name="ar"></param> private void ReceiveResBySingleNode(IAsyncResult ar) { SnmpMessageResult res = ar as SnmpMessageResult; // 遍历GetNext结果,添加到对应容器当中,GetNextResList容器中保存着全量集; foreach (KeyValuePair <string, string> iter in res.AsyncState as Dictionary <string, string> ) { GetNextResList.Add(iter.Key, iter.Value); } }
/// <summary> /// 每有一条新的MIB数据,都会调用该函数; /// </summary> /// <param name="ar"></param> /// <param name="oid_cn"></param> /// <param name="oid_en"></param> /// <param name="contentlist"></param> public void UpdateMibDataGrid(IAsyncResult ar, Dictionary <string, string> oid_cn, Dictionary <string, string> oid_en, ObservableCollection <DyDataGrid_MIBModel> contentlist) { SnmpMessageResult res = ar as SnmpMessageResult; // 将信息回填到DataGrid当中; this.MibDataGrid.Dispatcher.Invoke(new Action(() => { this.MibDataGrid.Columns.Clear(); //以最后一次为准即可; dynamic model = new DyDataGrid_MIBModel(); // 遍历GetNext的结果; foreach (KeyValuePair <string, string> iter in res.AsyncState as Dictionary <string, string> ) { Console.WriteLine("NextIndex" + iter.Key.ToString() + " Value:" + iter.Value.ToString()); // 通过基站反馈回来的一行结果,动态生成一个类型,用来与DataGrid对应; foreach (var iter2 in oid_cn) { // 如果存在对应关系; if (iter.Key.ToString().Contains(iter2.Key)) { Console.WriteLine("Add Property:" + oid_en[iter2.Key] + " Value:" + iter.Value.ToString() + " and Header is:" + iter2.Value.ToString()); model.AddProperty(oid_en[iter2.Key], new DataGrid_Cell_MIB() { m_Content = iter.Value.ToString(), oid = iter.Key, MibName_CN = iter2.Value, MibName_EN = oid_en[iter2.Key] }, iter2.Value.ToString()); } } } // 将这个整行数据填入List; if (model.Properties.Count != 0) { // 向单元格内添加内容; contentlist.Add(model); } foreach (var iter3 in oid_en) { Console.WriteLine("new binding is:" + iter3.Value + ".m_Content"); DataGridTextColumn column = new DataGridTextColumn(); column.Header = oid_cn[iter3.Key]; column.Binding = new Binding(iter3.Value + ".m_Content"); this.MibDataGrid.Columns.Add(column); } this.MibDataGrid.DataContext = contentlist; })); }
private void AsyncGetSNMP(IAsyncResult ar) { SnmpMessageResult res = ar as SnmpMessageResult; Dictionary <string, string> temp = res.AsyncState as Dictionary <string, string>; }