コード例 #1
0
        public void ParseTest_NestedQuoteString()
        {
            string     str      = UnitTestHelper.MessageString_NestedQuoteString;
            OscMessage expected = UnitTestHelper.Message_NestedQuoteString();
            OscMessage actual;

            actual = OscMessage.Parse(str);
            UnitTestHelper.AreEqual(expected, actual);
        }
コード例 #2
0
ファイル: OscPacket.cs プロジェクト: HakanL/Haukcode.Osc
 public static OscPacket Parse(string str, IFormatProvider provider)
 {
     if (str.Trim().StartsWith(OscBundle.BundleIdent) == true)
     {
         return(OscBundle.Parse(str, provider));
     }
     else
     {
         return(OscMessage.Parse(str, provider));
     }
 }
コード例 #3
0
        /// <summary>
        /// toolStripMenuItemSendMessage DropDownItemClicked task called by event or programmatically.
        /// </summary>
        /// <param name="text">
        /// DropDownItem text to be processed.
        /// </param>
        private void toolStripMenuItemSendMessage_DropDownItemClicked_Task(string text)
        {
            // Create message from string
            string oscMessageString;

            if (text == "...")
            {
                FormGetValue formGetValue = new FormGetValue();
                formGetValue.CheckString += (delegate(string currentValue)
                {
                    try
                    {
                        OscMessage.Parse(currentValue);
                        return(true);
                    }
                    catch
                    {
                        return(false);
                    }
                });
                formGetValue.ShowDialog();
                try
                {
                    if (formGetValue.value == "")
                    {
                        return;
                    }
                    OscMessage.Parse(formGetValue.value);
                    oscMessageString = formGetValue.value;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand);
                    return;
                }
            }
            else
            {
                oscMessageString = text;
            }

            // Update message list
            if (!sentMessageStrings.Contains(oscMessageString))
            {
                sentMessageStrings.Add(oscMessageString);
                sentMessageStrings.Sort();
            }
            toolStripMenuItemSendMessage.DropDownItems.Clear();
            foreach (string s in sentMessageStrings)
            {
                toolStripMenuItemSendMessage.DropDownItems.Add(s);
            }
            toolStripMenuItemSendMessage.DropDownItems.Add("...");

            // Check selected port
            foreach (ToolStripMenuItem toolStripMenuItem in toolStripMenuItemSendMessage.DropDownItems)
            {
                if (toolStripMenuItem.Text == oscMessageString)
                {
                    toolStripMenuItem.Checked = true;
                }
            }

            // Set selected send message
            selectedSendMessage = OscMessage.Parse(oscMessageString);
        }
コード例 #4
0
        // 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);
                }
            }
        }