public void GetFilteredMatches() { 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"); List<string> filter = new List<string>(); filter.Add("deki"); filter.Add("users"); filter.Add("pagesandusers"); string[] expected = new string[] { "deki", "pagesandusers" }; IEnumerable<string> matches = map.GetMatches(new XUri("channel:///deki/pages/create"),filter); CheckExpectations(expected, matches); expected = new string[] { "deki", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages/mod"), filter); CheckExpectations(expected, matches); expected = new string[] { "deki", "users", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/users/create"), filter); CheckExpectations(expected, matches); expected = new string[] { "deki", "pagesandusers" }; matches = map.GetMatches(new XUri("channel:///deki/pages"), filter); 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 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 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); }
/// <summary> /// Override hook for modifying/augmenting the calculation of the combined subscription set. /// </summary> /// <returns>Returns all subscription sets used to calculate the new combined set.</returns> protected virtual PubSubSubscription[] CalculateCombinedSubscriptions() { PubSubSubscription[] allSubs; lock(_subscriptionsByOwner) { XUriChildMap<PubSubSubscription> tempChannelMap = new XUriChildMap<PubSubSubscription>(); XUriChildMap<PubSubSubscription> tempResourceMap = new XUriChildMap<PubSubSubscription>(true); Dictionary<DispatcherRecipient, List<XUri>> tempRecipients = new Dictionary<DispatcherRecipient, List<XUri>>(); Dictionary<XUri, List<PubSubSubscriptionSet>> tempSubs = new Dictionary<XUri, List<PubSubSubscriptionSet>>(); List<PubSubSubscription> allSubsList = new List<PubSubSubscription>(); foreach(PubSubSubscriptionSet set in _subscriptionsByOwner.Values) { foreach(PubSubSubscription sub in set.Subscriptions) { tempChannelMap.AddRange(sub.Channels, sub); if(sub.Resources != null && sub.Resources.Length > 0) { tempResourceMap.AddRange(sub.Resources, sub); } else { tempResourceMap.Add(new XUri("x://*/*"), sub); } allSubsList.Add(sub); List<PubSubSubscriptionSet> sets; if(!tempSubs.TryGetValue(sub.Destination, out sets)) { sets = new List<PubSubSubscriptionSet>(); tempSubs.Add(sub.Destination, sets); } if(!sets.Contains(set)) { sets.Add(set); } foreach(DispatcherRecipient recipient in sub.Recipients) { List<XUri> destinations; if(!tempRecipients.TryGetValue(recipient, out destinations)) { destinations = new List<XUri>(); tempRecipients.Add(recipient, destinations); } if(!destinations.Contains(sub.Destination)) { destinations.Add(sub.Destination); } } } } allSubs = allSubsList.ToArray(); lock(_channelMap) { _channelMap = tempChannelMap; _resourceMap = tempResourceMap; } lock(_subscriptionsByDestination) { _subscriptionsByDestination = tempSubs; } lock(_destinationsByRecipient) { _destinationsByRecipient = tempRecipients; } } return allSubs; }