示例#1
0
        /// <exception cref="InvalidOperationException">Cannot add a Uri mapping once the configuration has been done.</exception>
        /// <exception cref="ArgumentException">Cannot use a Type as the resourceKey. NotifyAsync an <see cref="IType"/> instead or assign the <see cref="TypeSystem"/> property.</exception>
        public void Add(UriRegistration registration)
        {
            if (_templates.IsReadOnly)
            {
                throw new InvalidOperationException("Cannot add a Uri mapping once the configuration has been done.");
            }
            var resourceKey = EnsureIsNotType(registration.ResourceKey);
            var descriptor  = new UrlDescriptor
            {
                Uri = new UriTemplate(registration.UriTemplate),

                Culture      = registration.UriCulture,
                ResourceKey  = resourceKey,
                UriName      = registration.UriName,
                Registration = registration
            };

            _templates.KeyValuePairs.Add(new KeyValuePair <UriTemplate, object>(descriptor.Uri, descriptor));
            _templates.BaseAddress = new Uri("http://localhost/").IgnoreAuthority();
            var keys = UriNamesForKey(resourceKey);

            if (registration.UriName != null)
            {
                keys.Add(registration.UriName);
            }
        }
        public UriRegistration Match(Uri uriToMatch)
        {
            if (uriToMatch == null)
            {
                return(null);
            }
            var tableMatches = _templates.Match(uriToMatch.IgnoreSchemePortAndAuthority());

            if (tableMatches == null || tableMatches.Count == 0)
            {
                return(null);
            }
            var urlDescriptor = (UrlDescriptor)tableMatches[0].Data;

            var result = new UriRegistration(urlDescriptor.Uri.ToString(), urlDescriptor.ResourceKey, urlDescriptor.UriName, urlDescriptor.Culture);

            foreach (var tableMatch in tableMatches)
            {
                var allVariables = new NameValueCollection
                {
                    tableMatch.PathSegmentVariables,
                    tableMatch.QueryStringVariables
                };
                result.UriTemplateParameters.Add(allVariables);
            }

            return(result);
        }
        public bool Remove(UriRegistration item)
        {
            var pairToRemove = _templates.KeyValuePairs
                               .Where(x => ((UrlDescriptor)x.Value).Registration == item)
                               .ToList();

            if (pairToRemove.Count > 0)
            {
                _templates.KeyValuePairs.Remove(pairToRemove[0]);
                return(true);
            }

            return(false);
        }
        public bool Remove(UriRegistration item)
        {
            var pairToRemove = this.templates.KeyValuePairs
                .Where(x => ((UrlDescriptor)x.Value).Registration == item)
                .ToList();

            if (pairToRemove.Count > 0)
            {
                this.templates.KeyValuePairs.Remove(pairToRemove[0]);
                
                return true;
            }

            return false;
        }
 /// <exception cref="InvalidOperationException">Cannot add a Uri mapping once the configuration has been done.</exception>
 /// <exception cref="ArgumentException">Cannot use a Type as the resourceKey. Use an <see cref="IType"/> instead or assign the <see cref="TypeSystem"/> property.</exception>
 public void Add(UriRegistration registration)
 {
     if (_templates.IsReadOnly)
         throw new InvalidOperationException("Cannot add a Uri mapping once the configuration has been done.");
     var resourceKey = EnsureIsNotType(registration.ResourceKey);
     var descriptor = new UrlDescriptor
     {
         Uri = new UriTemplate(registration.UriTemplate),
         Culture = registration.UriCulture,
         ResourceKey = resourceKey,
         UriName = registration.UriName,
         Registration = registration
     };
     _templates.KeyValuePairs.Add(new KeyValuePair<UriTemplate, object>(descriptor.Uri, descriptor));
     _templates.BaseAddress = new Uri("http://localhost/").IgnoreAuthority();
 }
示例#6
0
        public bool Remove(UriRegistration registration)
        {
            var pairToRemove = _templates.KeyValuePairs
                               .Where(x => ((UrlDescriptor)x.Value).Registration == registration)
                               .ToList();

            if (pairToRemove.Count <= 0)
            {
                return(false);
            }

            _templates.KeyValuePairs.Remove(pairToRemove[0]);
            if (registration.UriName != null)
            {
                UriNames[registration.ResourceKey].Remove(registration.UriName);
            }
            return(true);
        }
 public void CopyTo(UriRegistration[] array, int arrayIndex)
 {
     this.ToList().CopyTo(array, arrayIndex);
 }
 public bool Contains(UriRegistration item)
 {
     return this.Any(x => x == item);
 }
        public UriRegistration Match(Uri uriToMatch)
        {
            if (uriToMatch == null)
            {
                return null;
            }

            var tableMatches = this.templates.Match(uriToMatch.IgnoreSchemePortAndAuthority());
            
            if (tableMatches == null || tableMatches.Count == 0)
            {
                return null;
            }

            var urlDescriptor = (UrlDescriptor)tableMatches[0].Data;
            var result = new UriRegistration(urlDescriptor.Uri.ToString(), urlDescriptor.ResourceKey, urlDescriptor.UriName, urlDescriptor.Culture);
            
            foreach (var tableMatch in tableMatches)
            {
                var allVariables = new NameValueCollection
                {
                    tableMatch.BoundVariables, 
                    tableMatch.QueryParameters
                };
                
                result.UriTemplateParameters.Add(allVariables);
            }

            return result;
        }
 public bool Contains(UriRegistration item)
 {
     return(this.Any(x => x == item));
 }
示例#11
0
 public bool Remove(UriRegistration item)
 {
     return(_inner.Remove(item));
 }
示例#12
0
 public bool Contains(UriRegistration item)
 {
     return(_inner.Contains(item));
 }
示例#13
0
 public void Add(UriRegistration item)
 {
     _inner.Add(item);
 }