public string ReadAddress(bool validate) { OscSerializationToken token = ReadNextToken(out string value); if (token != OscSerializationToken.Literal) { throw new OscException(OscError.ErrorParsingOscAdress, $"Unexpected serialization token {token}"); } string address = value.Trim(); if (validate != true) { return(address); } if (string.IsNullOrWhiteSpace(address)) { throw new Exception("Address was empty"); } if (OscAddress.IsValidAddressPattern(address) == false) { throw new Exception("Invalid address"); } return(address); }
public void IsValidAddressPatternTest_Bad() { for (int i = 0; i < UnitTestHelper.Bad_AddressPatterns.Length; i++) { string address = UnitTestHelper.Bad_AddressPatterns[i]; bool result = OscAddress.IsValidAddressPattern(address); Assert.IsFalse(result, String.Format("Incorrectly validated address pattern {0} '{1}'", i, address)); } }
public void IsValidAddressPatternTest_Good() { for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++) { string address = UnitTestHelper.Good_AddressPatterns[i]; bool result = OscAddress.IsValidAddressPattern(address); Assert.IsTrue(result, String.Format("Failed to validate address pattern {0} '{1}'", i, address)); } }
public void IsValidAddressPatternTest_Bad() { for (int i = 0; i < UnitTestHelper.Bad_AddressPatterns.Length; i++) { string address = UnitTestHelper.Bad_AddressPatterns[i]; bool result = OscAddress.IsValidAddressPattern(address); Assert.False(result, $"Incorrectly validated address pattern {i} '{address}'"); } }
public void IsValidAddressPatternTest_Good() { for (int i = 0; i < UnitTestHelper.Good_AddressPatterns.Length; i++) { string address = UnitTestHelper.Good_AddressPatterns[i]; bool result = OscAddress.IsValidAddressPattern(address); Assert.True(result, $"Failed to validate address pattern {i} '{address}'"); } }
private void ListenerAddress_TextChanged(object sender, EventArgs e) { // try to parse the osc address literal if (OscAddress.IsValidAddressPattern(m_ListenerAddress.Text) == true) { // if it parsed ok then green m_ListenerAddress.BackColor = Color.LightGreen; } else { // if there was a problem parsing the address then red (pink) m_ListenerAddress.BackColor = Color.Pink; } }
/// <summary> /// Construct a OSC message /// </summary> /// <param name="origin">the origin of the OSC message</param> /// <param name="address">An OSC address that is the destination for this message</param> /// <param name="args"> /// Object array of OSC argument values. The type tag string will be created automatically according to /// each argument type /// </param> /// <example>OscMessage message = new OscMessage("/test/test", 1, 2, 3);</example> public OscMessage(Uri origin, string address, params object[] args) { Origin = origin; Address = address; arguments = args; if (string.IsNullOrWhiteSpace(Address)) { throw new ArgumentNullException(nameof(address)); } if (OscAddress.IsValidAddressPattern(address) == false) { throw new ArgumentException($"The address '{address}' is not a valid osc address", nameof(address)); } if (args == null) { throw new ArgumentNullException(nameof(args)); } CheckArguments(arguments); }