public void GetAllMatches() { XUriChildMap<string> map = new XUriChildMap<string>(); map.Add(new XUri("channel:///*"), "all"); map.Add(new XUri("channel:///deki/*"), "deki"); map.Add(new XUri("channel:///deki/pages/*"), "pages"); map.Add(new XUri("channel:///deki/pages/create"), "create"); map.Add(new XUri("channel:///deki/pages/mod"), "mod"); map.Add(new XUri("channel:///deki/pages/delete"), "delete"); map.Add(new XUri("channel:///deki/users/*"), "users"); map.Add(new XUri("channel:///deki/pages/*"), "pagesandusers"); map.Add(new XUri("channel:///deki/users/*"), "pagesandusers"); map.Add(new XUri("channel:///deki/pages/mod/*"), "mod2"); string[] expected = new string[] { "all", "deki", "pages", "create", "pagesandusers" }; IEnumerable<string> matches = map.GetMatches(new XUri("channel:///deki/pages/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "pages", "mod", "mod2", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages/mod")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "users", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/users/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "pages", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages")); CheckExpectations(expected, matches); }
public void GetAllMatches() { XUriChildMap <string> map = new XUriChildMap <string>(); map.Add(new XUri("channel:///*"), "all"); map.Add(new XUri("channel:///deki/*"), "deki"); map.Add(new XUri("channel:///deki/pages/*"), "pages"); map.Add(new XUri("channel:///deki/pages/create"), "create"); map.Add(new XUri("channel:///deki/pages/mod"), "mod"); map.Add(new XUri("channel:///deki/pages/delete"), "delete"); map.Add(new XUri("channel:///deki/users/*"), "users"); map.Add(new XUri("channel:///deki/pages/*"), "pagesandusers"); map.Add(new XUri("channel:///deki/users/*"), "pagesandusers"); map.Add(new XUri("channel:///deki/pages/mod/*"), "mod2"); string[] expected = new string[] { "all", "deki", "pages", "create", "pagesandusers" }; IEnumerable <string> matches = map.GetMatches(new XUri("channel:///deki/pages/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "pages", "mod", "mod2", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages/mod")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "users", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/users/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki", "pages", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages")); CheckExpectations(expected, matches); }
/// <summary> /// Override hook for modifying the selection of event listeners based on channel and resource matches. /// </summary> /// <param name="ev">Event to be dispatched.</param> /// <param name="result">The <see cref="Result"/>instance to be returned by this method.</param> /// <returns>Synchronization handle for the action's execution.</returns> protected virtual Yield GetListenersByChannelResourceMatch(DispatcherEvent ev, Result <Dictionary <XUri, List <DispatcherRecipient> > > result) { // dispatch to all subscriptions that listen for this event and its contents _log.Debug("trying dispatch based on channel matches"); ICollection <PubSubSubscription> listeningSubs = null; lock (_channelMap) { if (ev.Resource != null) { listeningSubs = _resourceMap.GetMatches(ev.Resource); } listeningSubs = _channelMap.GetMatches(ev.Channel, listeningSubs); } Dictionary <XUri, List <DispatcherRecipient> > listeners = new Dictionary <XUri, List <DispatcherRecipient> >(); foreach (PubSubSubscription sub in listeningSubs) { List <DispatcherRecipient> recipients; if (!listeners.TryGetValue(sub.Destination, out recipients)) { recipients = new List <DispatcherRecipient>(); listeners.Add(sub.Destination, recipients); } foreach (DispatcherRecipient recipient in sub.Recipients) { if (!recipients.Contains(recipient)) { recipients.Add(recipient); } } } result.Return(listeners); yield break; }
public void GetWildcardHostMatches() { XUriChildMap <string> map = new XUriChildMap <string>(); map.Add(new XUri("channel://*/*"), "all"); map.Add(new XUri("channel://deki1/deki/*"), "deki1"); map.Add(new XUri("channel://deki2/deki/*"), "deki2"); map.Add(new XUri("channel://*/deki/pages/*"), "allpages"); string[] expected = new string[] { "all", "deki1", "allpages" }; IEnumerable <string> matches = map.GetMatches(new XUri("channel://deki1/deki/pages/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki1" }; matches = map.GetMatches(new XUri("channel://deki1/deki/comments/mod")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki2", }; matches = map.GetMatches(new XUri("channel://deki2/deki/comments/create")); CheckExpectations(expected, matches); }
public void GetIdenticalMatches() { var map = new XUriChildMap <string>(); map.Add(new XUri("channel:///deki/a/b/c"), "x"); map.Add(new XUri("channel:///deki/a/b/c"), "y"); map.Add(new XUri("channel:///deki/a/b/*"), "z"); var expected = new[] { "x", "y", "z" }; IEnumerable <string> matches = map.GetMatches(new XUri("channel:///deki/a/b/c")); CheckExpectations(expected, matches); }
public void GetMatchesIgnoringScheme() { XUriChildMap <string> map = new XUriChildMap <string>(true); map.Add(new XUri("http://*/y/*"), "http1"); map.Add(new XUri("https://*/y/*"), "https1"); map.Add(new XUri("http://x/y/*"), "http2"); map.Add(new XUri("https://x/y/*"), "https2"); map.Add(new XUri("http://x/y/z"), "http3"); map.Add(new XUri("https://x/y/z"), "https3"); string[] expected = new string[] { "http1", "https1", "http2", "https2", "http3", "https3", }; IEnumerable <string> matches = map.GetMatches(new XUri("http://x/y/z")); CheckExpectations(expected, matches); expected = new string[] { "http1", "https1", "http2", "https2" }; matches = map.GetMatches(new XUri("https://x/y/y")); CheckExpectations(expected, matches); expected = new string[] { "http1", "https1" }; matches = map.GetMatches(new XUri("foo://y/y/z")); CheckExpectations(expected, matches); }
public void GetWildcardHostMatches() { XUriChildMap<string> map = new XUriChildMap<string>(); map.Add(new XUri("channel://*/*"), "all"); map.Add(new XUri("channel://deki1/deki/*"), "deki1"); map.Add(new XUri("channel://deki2/deki/*"), "deki2"); map.Add(new XUri("channel://*/deki/pages/*"), "allpages"); string[] expected = new string[] { "all", "deki1", "allpages" }; IEnumerable<string> matches = map.GetMatches(new XUri("channel://deki1/deki/pages/create")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki1" }; matches = map.GetMatches(new XUri("channel://deki1/deki/comments/mod")); CheckExpectations(expected, matches); expected = new string[] { "all", "deki2", }; matches = map.GetMatches(new XUri("channel://deki2/deki/comments/create")); CheckExpectations(expected, matches); }
public void GetMatchesRespectsScheme() { XUriChildMap<string> map = new XUriChildMap<string>(false); map.Add(new XUri("http://*/y/*"), "http1"); map.Add(new XUri("https://*/y/*"), "https1"); map.Add(new XUri("http://x/y/*"), "http2"); map.Add(new XUri("https://x/y/*"), "https2"); map.Add(new XUri("http://x/y/z"), "http3"); map.Add(new XUri("https://x/y/z"), "https3"); string[] expected = new string[] { "http1", "http2", "http3" }; IEnumerable<string> matches = map.GetMatches(new XUri("http://x/y/z")); CheckExpectations(expected, matches); expected = new string[] { "https1", "https2", "https3", }; matches = map.GetMatches(new XUri("https://x/y/z")); CheckExpectations(expected, matches); expected = new string[] { "http1", "http2", }; matches = map.GetMatches(new XUri("http://x/y/y")); CheckExpectations(expected, matches); expected = new string[] { "https1", "https2" }; matches = map.GetMatches(new XUri("https://x/y/y")); CheckExpectations(expected, matches); expected = new string[] { "http1", }; matches = map.GetMatches(new XUri("http://y/y/z")); CheckExpectations(expected, matches); expected = new string[] { "https1" }; matches = map.GetMatches(new XUri("https://y/y/z")); CheckExpectations(expected, matches); }
public void GetIdenticalMatches() { var map = new XUriChildMap<string>(); map.Add(new XUri("channel:///deki/a/b/c"), "x"); map.Add(new XUri("channel:///deki/a/b/c"), "y"); map.Add(new XUri("channel:///deki/a/b/*"), "z"); var expected = new[] { "x", "y", "z" }; IEnumerable<string> matches = map.GetMatches(new XUri("channel:///deki/a/b/c")); CheckExpectations(expected, matches); }