/// <summary> /// Add the pair with locking. /// </summary> /// <param name="pattern"></param> /// <param name="source"></param> private void AddPattern(IEnumerable <TContent> pattern, TaskCompletionSource <IEnumerable <TContent> > source) { pattern_lock.EnterWriteLock(); try { Patterns.Add(pattern, source); } finally { pattern_lock.ExitWriteLock(); } }
/// <summary> /// Construct a new WhileMatching construct utilizing an existing PatternDictionary. /// </summary> /// <param name="dict">The pattern dictionary to match from.</param> /// <param name="toCall">The TaskCompletionSource to trigger on match.</param> /// <param name="patterns">The set of patterns to match.</param> public WhileMatching(PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > > dict, TaskCompletionSource <IEnumerable <TContent> > toCall, params IEnumerable <TContent>[] patterns) { this.dict = dict; this.patterns = patterns; this.toCall = toCall; foreach (var p in patterns) { dict.Add(p, toCall); } }
/// <summary> /// Construct a new WhileMatching construct with pattern recognition particular /// to the defined <paramref name="genericPiece"/> and /// <paramref name="genericSeries"/>. /// </summary> /// <param name="genericPiece">Defines a generic piece in the patterns.</param> /// <param name="genericSeries">Defines a generic series in the patterns.</param> /// <param name="toCall">The TaskCompletionSource to trigger on call.</param> /// <param name="patterns">The set of patterns to match.</param> public WhileMatching(TContent genericPiece, TContent genericSeries, TaskCompletionSource <IEnumerable <TContent> > toCall, params IEnumerable <TContent>[] patterns) { dict = new PatternDictionary <TContent, TaskCompletionSource <IEnumerable <TContent> > >(genericPiece, genericSeries); this.patterns = patterns; this.toCall = toCall; foreach (var p in patterns) { dict.Add(p, toCall); } }