private void ShowTable(Dictionary <Oid, AsnType> result) { tableViewDataGridView.Columns.Clear(); if (result == null) { ErrorMessageBox.Show("Request failed."); } else { var rowNumber = 0; var prevColumnNumber = -1; foreach (KeyValuePair <Oid, AsnType> entry in result) { if (entry.Value.ToString().Equals("Null")) { ErrorMessageBox.Show("Request failed."); } else { var tableRootOid = new Oid(oidTextBox.Text); var currentOid = entry.Key; var cutOid = currentOid.CutCommonRoot(tableRootOid); var columnNumber = cutOid.LevelValue(1) - 1; if (columnNumber == prevColumnNumber) { rowNumber++; } else { rowNumber = 0; var tableRootOidLevels = tableRootOid.Levels(); tableViewDataGridView.Columns.Add(currentOid.CutAfterLevel(tableRootOidLevels + 2), currentOid.CutAfterLevel(tableRootOidLevels + 2)); } if (tableViewDataGridView.Rows.Count <= rowNumber) { tableViewDataGridView.Rows.Add(); } tableViewDataGridView.Rows[rowNumber].Cells[columnNumber].Value = entry.Value.ToString(); prevColumnNumber = columnNumber; } } } }
private void AddToMonitoredObjects(string oid) { try { var timer = new Timer { Interval = Settings.Default.MonitorInterval }; timer.Tick += (sender, eventArgs) => OnTick(sender, eventArgs, oid); _monitoredObjects.Add(oid, timer); timer.Start(); } catch (ArgumentException) { ErrorMessageBox.Show($"Object {oid} is already observed."); } }
public void Listen() { var ipEndPoint = new IPEndPoint(IPAddress.Any, 162); Task.Run(async() => { var run = true; while (run) { try { using (var udpListener = new UdpClient(ipEndPoint)) { var udpRecieveResult = await udpListener.ReceiveAsync(); var recievedData = udpRecieveResult.Buffer; int protocolVersion = SnmpPacket.GetProtocolVersion(recievedData, recievedData.Length); switch (protocolVersion) { case (int)SnmpVersion.Ver1: var snmpV1TrapPacket = new SnmpV1TrapPacket(); snmpV1TrapPacket.decode(recievedData, recievedData.Length); RecieveTrap(snmpV1TrapPacket); break; case (int)SnmpVersion.Ver2: var snmpV2Packet = new SnmpV2Packet(); snmpV2Packet.decode(recievedData, recievedData.Length); RecieveTrap(snmpV2Packet); break; case (int)SnmpVersion.Ver3: var snmpV3Packet = new SnmpV3Packet(); snmpV3Packet.decode(recievedData, recievedData.Length); RecieveTrap(snmpV3Packet); break; } } } catch (SocketException) { ErrorMessageBox.Show($"Port {ipEndPoint.Port} is already used."); run = false; } catch (Exception e) { ErrorMessageBox.Show($"{e.Message}"); } } }); }
private void ShowResult(Dictionary <Oid, AsnType> result, DataGridView target) { if (result == null) { ErrorMessageBox.Show("Request failed."); } else { foreach (KeyValuePair <Oid, AsnType> entry in result) { if (entry.Value.ToString().Equals("Null")) { ErrorMessageBox.Show("Request failed."); } else { target.Rows.Add(entry.Key.ToString(), entry.Value.ToString(), SnmpConstants.GetTypeName(entry.Value.Type), DateTime.Now.ToLongTimeString()); } } } }