Example #1
0
        public void PatternTest2()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*", 1 },
                { "A*", 2 },
                { "AB*", 3 },
                { "AC*", 4 },
                { "aksjdf;oiajdfkjas*", 5 },
                { "", 6 }
            };

            var finds = PatDict.Collect("A");

            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));

            finds = PatDict.Collect("AB");
            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));
            Assert.IsTrue(finds.Contains(3));

            finds = PatDict.Collect("aksjdf;oiajdfkjas");
            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(5));

            finds = PatDict.Collect("aksjdf;oiajdfkjas_hey!!!!");
            Assert.AreEqual(2, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(5));
        }
Example #2
0
        public void PatternTest4()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*X*X*", 1 }
            };

            var finds = PatDict.Collect("A");

            Assert.AreEqual(0, finds.Count);

            var finds2 = PatDict.Collect("AA");

            Assert.AreEqual(1, finds2.Count);
            Assert.IsTrue(finds2.Contains(1));
        }
Example #3
0
        public void PatternTest7()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "A*A*X*", 1 }
            };

            var finds = PatDict.Collect("AAB");

            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(1));

            finds = PatDict.Collect("AAAAAAACCCCCAAAABBBB");
            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(1));
        }
Example #4
0
 private void Call(IEnumerable <TContent> args)
 {
     if (dict.Collect(args).Count > 0)
     {
         action?.Invoke(args);
     }
 }
Example #5
0
        public void PatternTest0()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "hey", 0 }
            };
            var finds = PatDict.Collect("hey");

            Assert.AreEqual(1, finds.Count);
        }
Example #6
0
        public void PatternTest1()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "", 0 },
                { "0X 12 23 34", 1 },
                { "01 12 2X 34", 2 },
                { "XX XX XX XX", 3 }
            };

            var finds = PatDict.Collect("01 12 23 34");

            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1));
            Assert.IsTrue(finds.Contains(2));
            Assert.IsTrue(finds.Contains(3));

            finds = PatDict.Collect("FF FF FF FF");
            Assert.AreEqual(1, finds.Count);
            Assert.IsTrue(finds.Contains(3));
        }
Example #7
0
        public void PatternTest3()
        {
            PatDict = new PatternDictionary <char, int>('X', '*')
            {
                { "*", 1 },
                { "*A", 2 },
                { "A*", 3 }
            };
            var finds = PatDict.Collect("A");

            Assert.AreEqual(3, finds.Count);
            Assert.IsTrue(finds.Contains(1) && finds.Contains(2) && finds.Contains(3));
        }
Example #8
0
        /// <summary>
        /// Handle to provide to the Message Received Event handle.
        /// </summary>
        /// <param name="args"></param>
        private void OnReceived(IEnumerable <TContent> args)
        {
            IList <TaskCompletionSource <IEnumerable <TContent> > > toCall;

            // Collect all sources for the received message.
            pattern_lock.EnterReadLock();
            try
            {
                toCall = Patterns.Collect(args);
            }
            finally { pattern_lock.ExitReadLock(); }

            foreach (TaskCompletionSource <IEnumerable <TContent> > t in toCall)
            {
                t.TrySetResult(args);
            }
        }