Exemplo n.º 1
0
        public bool TryLookupUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, out TItem item)
        {
            BaseUriWithWildcard key = new BaseUriWithWildcard(uri, hostNameComparisonMode);

            if (TryCacheLookup(key, out item))
            {
                return(item != null);
            }

            using (AsyncLock.TakeLock())
            {
                // exact match failed, perform the full lookup (which will also
                // catch case-insensitive variations that aren't yet in our cache)
                bool dummy;
                SegmentHierarchyNode <TItem> node = FindDataNode(
                    UriSegmenter.ToPath(key.BaseAddress, hostNameComparisonMode, includePortInComparison), out dummy);
                if (node != null)
                {
                    item = node.Data;
                }
                // We want to cache both positive AND negative results
                AddToCache(key, item);
                return(item != null);
            }
        }
        public bool IsRegistered(BaseUriWithWildcard key)
        {
            bool flag;
            SegmentHierarchyNode <TItem> node;

            string[] path = UriSegmenter <TItem> .ToPath(key.BaseAddress, key.HostNameComparisonMode, this.includePortInComparison);

            lock (this.ThisLock)
            {
                node = this.FindDataNode(path, out flag);
            }
            return((flag && (node != null)) && (node.Data != null));
        }
Exemplo n.º 3
0
        public bool IsRegistered(BaseUriWithWildcard key)
        {
            Uri uri = key.BaseAddress;

            // don't need to normalize path since SegmentHierarchyNode is
            // already OrdinalIgnoreCase
            string[] paths = UriSegmenter.ToPath(uri, key.HostNameComparisonMode, includePortInComparison);
            bool     exactMatch;
            SegmentHierarchyNode <TItem> node;

            using (AsyncLock.TakeLock())
            {
                node = FindDataNode(paths, out exactMatch);
            }
            return(exactMatch && node != null && node.Data != null);
        }
Exemplo n.º 4
0
        private SegmentHierarchyNode <TItem> FindOrCreateNode(BaseUriWithWildcard baseUri)
        {
            Fx.Assert(baseUri != null, "FindOrCreateNode: baseUri is null");

            string[] path = UriSegmenter.ToPath(baseUri.BaseAddress, baseUri.HostNameComparisonMode, _includePortInComparison);
            SegmentHierarchyNode <TItem> current = _root;

            for (int i = 0; i < path.Length; ++i)
            {
                if (!current.TryGetChild(path[i], out SegmentHierarchyNode <TItem> next))
                {
                    next = new SegmentHierarchyNode <TItem>(path[i], _useWeakReferences);
                    current.SetChildNode(path[i], next);
                }
                current = next;
            }
            return(current);
        }
        private SegmentHierarchyNode <TItem> FindOrCreateNode(BaseUriWithWildcard baseUri)
        {
            string[] strArray = UriSegmenter <TItem> .ToPath(baseUri.BaseAddress, baseUri.HostNameComparisonMode, this.includePortInComparison);

            SegmentHierarchyNode <TItem> root = this.root;

            for (int i = 0; i < strArray.Length; i++)
            {
                SegmentHierarchyNode <TItem> node2;
                if (!root.TryGetChild(strArray[i], out node2))
                {
                    node2 = new SegmentHierarchyNode <TItem>(strArray[i], this.useWeakReferences);
                    root.SetChildNode(strArray[i], node2);
                }
                root = node2;
            }
            return(root);
        }
        public void UnregisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode)
        {
            lock (this.ThisLock)
            {
                this.ClearCache();
                string[] path = UriSegmenter <TItem> .ToPath(uri, hostNameComparisonMode, this.includePortInComparison);

                if (path.Length == 0)
                {
                    this.root.RemoveData();
                }
                else
                {
                    this.root.RemovePath(path, 0);
                }
                this.count--;
            }
        }
Exemplo n.º 7
0
 public void UnregisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode)
 {
     using (AsyncLock.TakeLock())
     {
         // Since every removed Uri could alter what Prefixes should have matched, we
         // should clear the cache of any existing results and start over
         ClearCache();
         string[] path = UriSegmenter.ToPath(uri, hostNameComparisonMode, includePortInComparison);
         // Never remove the root
         if (path.Length == 0)
         {
             root.RemoveData();
         }
         else
         {
             root.RemovePath(path, 0);
         }
         count--;
     }
 }
        public bool TryLookupUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, out TItem item)
        {
            BaseUriWithWildcard key = new BaseUriWithWildcard(uri, hostNameComparisonMode);

            if (this.TryCacheLookup(key, out item))
            {
                return(((TItem)item) != null);
            }
            lock (this.ThisLock)
            {
                bool flag;
                SegmentHierarchyNode <TItem> node = this.FindDataNode(UriSegmenter <TItem> .ToPath(key.BaseAddress, hostNameComparisonMode, this.includePortInComparison), out flag);
                if (node != null)
                {
                    item = node.Data;
                }
                this.AddToCache(key, item);
                return(((TItem)item) != null);
            }
        }