Exemple #1
0
        /// <summary>
        /// Does a address match a address pattern
        /// </summary>
        /// <param name="addressPattern">address pattern (may include wildcards and lists)</param>
        /// <param name="address">literal address</param>
        /// <returns>true if the addess matches the pattern</returns>
        public static bool IsMatch(string addressPattern, string address)
        {
            if (IsValidAddressLiteral(address) == false)
            {
                return(false);
            }

            // are they both literals
            if (IsValidAddressLiteral(addressPattern) == true)
            {
                // preform a string match
                return(addressPattern.Equals(address));
            }

            if (IsValidAddressPattern(addressPattern) == false)
            {
                return(false);
            }

            // create a new pattern for the match
            OscAddress pattern = new OscAddress(addressPattern);

            // return the result
            return(pattern.Match(address));
        }
        /// <summary>
        /// Invoke any event that matches the address on the message
        /// </summary>
        /// <param name="message">the message argument</param>
        /// <returns>true if there was a listener to invoke otherwise false</returns>
        public bool Invoke(OscMessage message)
        {
            bool       invoked    = false;
            OscAddress oscAddress = null;

            List <OscLiteralEvent> shouldInvoke        = new List <OscLiteralEvent>();
            List <OscPatternEvent> shouldInvoke_Filter = new List <OscPatternEvent>();

            do
            {
                lock (m_Lock)
                {
                    if (OscAddress.IsValidAddressLiteral(message.Address) == true)
                    {
                        OscLiteralEvent container;

                        if (m_LiteralAddresses.TryGetValue(message.Address, out container) == true)
                        {
                            //container.Invoke(message);
                            shouldInvoke.Add(container);
                            invoked = true;
                        }
                    }
                    else
                    {
                        oscAddress = new OscAddress(message.Address);

                        foreach (KeyValuePair <string, OscLiteralEvent> value in m_LiteralAddresses)
                        {
                            if (oscAddress.Match(value.Key) == true)
                            {
                                //value.Value.Invoke(message);
                                shouldInvoke.Add(value.Value);
                                invoked = true;
                            }
                        }
                    }

                    if (m_PatternAddresses.Count > 0)
                    {
                        if (oscAddress == null)
                        {
                            oscAddress = new OscAddress(message.Address);
                        }

                        foreach (KeyValuePair <OscAddress, OscPatternEvent> value in m_PatternAddresses)
                        {
                            if (oscAddress.Match(value.Key) == true)
                            {
                                //value.Value.Invoke(message);
                                shouldInvoke_Filter.Add(value.Value);
                                invoked = true;
                            }
                        }
                    }
                }
            }while (invoked == false && OnUnknownAddress(message.Address) == true);

            foreach (OscLiteralEvent @event in shouldInvoke)
            {
                @event.Invoke(message);
            }

            foreach (OscPatternEvent @event in shouldInvoke_Filter)
            {
                @event.Invoke(message);
            }

            return(invoked);
        }