private void toolStripAddCom_Click(object sender, EventArgs e) { if (dlgNewSerial == null) { dlgNewSerial = new DebugViewNewSerialForm(); } dlgNewSerial.InitializeUI(); // add new serial port connection: if (dlgNewSerial.ShowDialog() == DialogResult.OK) { try { // create new reference to the serial port: DebugSerialPortSource source = new DebugSerialPortSource(dlgNewSerial.PortName, dlgNewSerial.PortBaudRate, dlgNewSerial.PortEncoding, dlgNewSerial.PortParity, dlgNewSerial.PortDataBits, dlgNewSerial.PortStopBits); // try to start listening and overwrite existing settings of already opened port: if (DebugViewMonitor.AddSource(source, true, true)) { MessageBox.Show(SharedStrings.DebugView_SerialPortReplaced, DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Information); } toolStripCloseSource.Enabled = DebugViewMonitor.Sources.Count > 0; } catch (Exception ex) { MessageBox.Show(ex.Message, DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public void CaptureMessageFromCustomSource() { UserDebugSource s = new UserDebugSource("Custom Broadcaster", "My custom source"); DebugViewMonitor.AddSource(s, false, true); s.Write("Message1"); s.Write("Message2\r\nMessage2a\r\n\r\nMessage2b"); WaitForResults(); Assert.IsTrue(numberOfMessagesReceived > 0, "Number of received debug messages should be greater than zero!"); }
public void AddRemoveSources() { UserDebugSource s1 = new UserDebugSource("S1", "Dummy source 1"); UserDebugSource s2 = new UserDebugSource("S2", "Dummy source 2"); UserDebugSource s3 = new UserDebugSource("S3", "Dummy source 3"); // add sources without overriding the existing ones: DebugViewMonitor.RemoveSources(); DebugViewMonitor.AddSource(s1, false, false); DebugViewMonitor.AddSource(s2, false, false); DebugViewMonitor.AddSource(s3, false, false); IList <IDbgSource> sources = DebugViewMonitor.Sources; Assert.IsNotNull(sources, "Number of sources can not be null, because 3 of them has been just added."); Assert.IsTrue(sources.Count == 3, "Not 3 sources added!"); // remove 2 sources: DebugViewMonitor.RemoveSource(s1); DebugViewMonitor.RemoveSource(s2); sources = DebugViewMonitor.Sources; Assert.IsNotNull(sources, "Number of sources can not be null, because there is still one added."); Assert.IsTrue(sources.Count == 1, "Not 1 sources added!"); // override, so it will replace the existing element, // the detection is based on name: UserDebugSource s4 = new UserDebugSource("S3", "Dummy source 3"); DebugViewMonitor.AddSource(s4, true, false); sources = DebugViewMonitor.Sources; Assert.IsNotNull(sources, "Number of sources can not be null, because there is still one added."); Assert.IsTrue(sources.Count == 1, "Not 1 source added!"); // add once again the same instance: DebugViewMonitor.AddSource(s3, false, false); sources = DebugViewMonitor.Sources; Assert.IsNotNull(sources, "Number of sources can not be null, because there is still one added."); Assert.IsTrue(sources.Count == 1, "Not 1 sources added!"); }