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);
            }

            lock (ThisLock)
            {
                // 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, this.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 UriPrefixTable(bool includePortInComparison, bool useWeakReferences)
 {
     this.includePortInComparison = includePortInComparison;
     this.useWeakReferences       = useWeakReferences;
     this.root        = new SegmentHierarchyNode <TItem>(null, useWeakReferences);
     this.lookupCache = new HopperCache(0x80, useWeakReferences);
 }
 public void RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
 {
     lock (this.ThisLock)
     {
         this.ClearCache();
         BaseUriWithWildcard          baseUri = new BaseUriWithWildcard(uri, hostNameComparisonMode);
         SegmentHierarchyNode <TItem> node    = this.FindOrCreateNode(baseUri);
         if (node.Data != null)
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(System.ServiceModel.SR.GetString("DuplicateRegistration", new object[] { uri })));
         }
         node.SetData(item, baseUri);
         this.count++;
     }
 }
        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);
        }
Exemplo n.º 5
0
        SegmentHierarchyNode <TItem> FindOrCreateNode(BaseUriWithWildcard baseUri)
        {
            Fx.Assert(baseUri != null, "FindOrCreateNode: baseUri is null");

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

            for (int i = 0; i < path.Length; ++i)
            {
                SegmentHierarchyNode <TItem> next;
                if (!current.TryGetChild(path[i], out next))
                {
                    next = new SegmentHierarchyNode <TItem>(path[i], useWeakReferences);
                    current.SetChildNode(path[i], next);
                }
                current = next;
            }
            return(current);
        }
        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);
            }
        }
Exemplo n.º 7
0
        public void RegisterUri(Uri uri, HostNameComparisonMode hostNameComparisonMode, TItem item)
        {
            Fx.Assert(HostNameComparisonModeHelper.IsDefined(hostNameComparisonMode), "RegisterUri: Invalid HostNameComparisonMode value passed in.");

            lock (ThisLock)
            {
                // Since every newly registered Uri could alter what Prefixes should have matched, we
                // should clear the cache of any existing results and start over
                ClearCache();
                BaseUriWithWildcard          key  = new BaseUriWithWildcard(uri, hostNameComparisonMode);
                SegmentHierarchyNode <TItem> node = FindOrCreateNode(key);
                if (node.Data != null)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.GetString(
                                                                                                                SR.DuplicateRegistration, uri)));
                }
                node.SetData(item, key);
                count++;
            }
        }
        private SegmentHierarchyNode <TItem> FindDataNode(string[] path, out bool exactMatch)
        {
            exactMatch = false;
            SegmentHierarchyNode <TItem> root  = this.root;
            SegmentHierarchyNode <TItem> node2 = null;

            for (int i = 0; i < path.Length; i++)
            {
                SegmentHierarchyNode <TItem> node3;
                if (!root.TryGetChild(path[i], out node3))
                {
                    return(node2);
                }
                if (node3.Data != null)
                {
                    node2      = node3;
                    exactMatch = i == (path.Length - 1);
                }
                root = node3;
            }
            return(node2);
        }
Exemplo n.º 9
0
        SegmentHierarchyNode <TItem> FindDataNode(string[] path, out bool exactMatch)
        {
            Fx.Assert(path != null, "FindDataNode: path is null");

            exactMatch = false;
            SegmentHierarchyNode <TItem> current = this.root;
            SegmentHierarchyNode <TItem> result  = null;

            for (int i = 0; i < path.Length; ++i)
            {
                SegmentHierarchyNode <TItem> next;
                if (!current.TryGetChild(path[i], out next))
                {
                    break;
                }
                else if (next.Data != null)
                {
                    result     = next;
                    exactMatch = (i == path.Length - 1);
                }
                current = next;
            }
            return(result);
        }
 public bool TryGetChild(string segment, out SegmentHierarchyNode <TData> value)
 {
     return(this.children.TryGetValue(segment, out value));
 }
 public void SetChildNode(string name, SegmentHierarchyNode <TData> node)
 {
     this.children[name] = node;
 }