| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using CoreWCF.Collections.Generic; |
| | | 6 | | |
| | | 7 | | namespace CoreWCF |
| | | 8 | | { |
| | | 9 | | public class UriSchemeKeyedCollection : SynchronizedKeyedCollection<string, Uri> |
| | | 10 | | { |
| | | 11 | | internal UriSchemeKeyedCollection(object syncRoot) |
| | 591 | 12 | | : base(syncRoot) |
| | | 13 | | { |
| | 591 | 14 | | } |
| | | 15 | | |
| | 587 | 16 | | public UriSchemeKeyedCollection(params Uri[] addresses) |
| | | 17 | | { |
| | 587 | 18 | | if (addresses == null) |
| | | 19 | | { |
| | 0 | 20 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(addresses)); |
| | | 21 | | } |
| | | 22 | | |
| | 1354 | 23 | | for (int i = 0; i < addresses.Length; i++) |
| | | 24 | | { |
| | 90 | 25 | | Add(addresses[i]); |
| | | 26 | | } |
| | 587 | 27 | | } |
| | | 28 | | |
| | | 29 | | protected override string GetKeyForItem(Uri item) |
| | | 30 | | { |
| | 777 | 31 | | return item.Scheme + ":" + item.Port; |
| | | 32 | | } |
| | | 33 | | |
| | | 34 | | protected override void InsertItem(int index, Uri item) |
| | | 35 | | { |
| | 691 | 36 | | ValidateBaseAddress(item, "item"); |
| | 691 | 37 | | if (Contains(item.Scheme)) |
| | | 38 | | { |
| | 0 | 39 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(item), SR.Format(SR.BaseAddressDupli |
| | | 40 | | } |
| | | 41 | | |
| | 691 | 42 | | base.InsertItem(index, item); |
| | 691 | 43 | | } |
| | | 44 | | |
| | | 45 | | protected override void SetItem(int index, Uri item) |
| | | 46 | | { |
| | 0 | 47 | | ValidateBaseAddress(item, "item"); |
| | 0 | 48 | | if (this[index].Scheme != item.Scheme) |
| | | 49 | | { |
| | 0 | 50 | | if (Contains(item.Scheme)) |
| | | 51 | | { |
| | 0 | 52 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(item), SR.Format(SR.BaseAddressD |
| | | 53 | | } |
| | | 54 | | } |
| | 0 | 55 | | base.SetItem(index, item); |
| | 0 | 56 | | } |
| | | 57 | | |
| | | 58 | | internal static void ValidateBaseAddress(Uri uri, string argumentName) |
| | | 59 | | { |
| | 691 | 60 | | if (uri == null) |
| | | 61 | | { |
| | 0 | 62 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(argumentName); |
| | | 63 | | } |
| | | 64 | | |
| | 691 | 65 | | if (!uri.IsAbsoluteUri) |
| | | 66 | | { |
| | 0 | 67 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressMustBeAbsolute) |
| | | 68 | | } |
| | | 69 | | |
| | 691 | 70 | | if (!string.IsNullOrEmpty(uri.UserInfo)) |
| | | 71 | | { |
| | 0 | 72 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveUserI |
| | | 73 | | } |
| | | 74 | | |
| | 691 | 75 | | if (!string.IsNullOrEmpty(uri.Query)) |
| | | 76 | | { |
| | 0 | 77 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveQuery |
| | | 78 | | } |
| | | 79 | | |
| | 691 | 80 | | if (!string.IsNullOrEmpty(uri.Fragment)) |
| | | 81 | | { |
| | 0 | 82 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(argumentName, SR.BaseAddressCannotHaveFragm |
| | | 83 | | } |
| | 691 | 84 | | } |
| | | 85 | | } |
| | | 86 | | } |