public void OscBundleManyMessagesTest_1() { OscBundle target = OscBundle.Parse("#bundle, 0, { /ping }, { /moop }, { /ping }, { /ping }, { /ping }"); OscBundle expected = new OscBundle(new OscTimeTag(0), new OscMessage("/ping"), new OscMessage("/moop"), new OscMessage("/ping"), new OscMessage("/ping"), new OscMessage("/ping")); UnitTestHelper.AreEqual(target, expected); }
public void Nested_ParseTest() { string str = UnitTestHelper.DoubleNestedBundleString; OscBundle expected = UnitTestHelper.DoubleNestedBundle(); OscBundle actual; actual = OscBundle.Parse(str); UnitTestHelper.AreEqual(expected, actual); }
public void OscBundleManyMessagesTest_2() { OscBundle target = OscBundle.Parse("#bundle, 0, { /ping }, { /moop }, { /ping }, { /ping }, { /ping }"); OscBundle expected = new OscBundle(new OscTimeTag(0), new OscMessage("/ping"), new OscMessage("/moop"), new OscMessage("/ping"), new OscMessage("/ping"), new OscMessage("/ping")); byte[] targetBytes = target.ToByteArray(); OscBundle actual = OscBundle.Read(targetBytes, targetBytes.Length); UnitTestHelper.AreEqual(actual, expected); }
// Loop for listening and updating dashboard data. static void ListenLoop() { try { while (Receiver.State != OscSocketState.Closed) { if (Receiver.State == OscSocketState.Connected) { // Get the next message, this will block until one arrives or the socket is closed. OscPacket Packet = Receiver.Receive(); // Slap the packet in the most recent message variable. App.Current.Dispatcher.InvokeAsync(() => { // Parses the packet into a message array. OscBundle MessageBundle = OscBundle.Parse(Packet.ToString()); foreach (OscPacket MessagePacket in MessageBundle.ToArray()) { // Get the latest message. OscMessage LatestMessage = OscMessage.Parse(MessagePacket.ToString()); // Determine if the message should be overwritten. bool OverwriteMessage = false; int OverwriteMessageIndex = 0; foreach (OscData Message in ReceivedOscData) { if (Message.Path == LatestMessage.Address) { OverwriteMessageIndex = ReceivedOscData.IndexOf(Message); OverwriteMessage = true; } } // Cut the address out of the data string. string DataString = ""; string[] DataArray = LatestMessage.ToString().Split(','); for (int i = 1; i < DataArray.Length; i++) { DataString += DataArray[i]; } // Add the message to the data grid, or overwrite its data. if (OverwriteMessage) { ReceivedOscData.RemoveAt(OverwriteMessageIndex); ReceivedOscData.Insert(OverwriteMessageIndex, new OscData() { Path = LatestMessage.Address, Data = DataString }); } else { ReceivedOscData.Add(new OscData() { Path = LatestMessage.Address, Data = DataString }); } } }); } } } catch (Exception Ex) { // Display the exeception if it occurred, while receiving. if (Receiver.State == OscSocketState.Connected) { MessageBox.Show(Ex.Message, "Exception Occurred", MessageBoxButton.OK, MessageBoxImage.Warning); } } }