/// <summary>
        /// Generates the OpenID Providers that are capable of asserting ownership
        /// of a particular XRI claimed identifier.
        /// </summary>
        /// <param name="xrds">The XrdsDocument instance to use in this process.</param>
        /// <param name="userSuppliedIdentifier">The i-name supplied by the user.</param>
        /// <returns>A sequence of the providers that can assert ownership of the given identifier.</returns>
        private static IEnumerable <IdentifierDiscoveryResult> GenerateClaimedIdentifierServiceEndpoints(this IEnumerable <XrdElement> xrds, XriIdentifier userSuppliedIdentifier)
        {
            // Cannot use code contracts because this method uses yield return.
            ////Contract.Requires<ArgumentNullException>(xrds != null);
            ////Contract.Ensures(Contract.Result<IEnumerable<IdentifierDiscoveryResult>>() != null);
            ErrorUtilities.VerifyArgumentNotNull(xrds, "xrds");

            foreach (var service in xrds.FindClaimedIdentifierServices())
            {
                foreach (var uri in service.UriElements)
                {
                    // spec section 7.3.2.3 on Claimed Id -> CanonicalID substitution
                    if (service.Xrd.CanonicalID == null)
                    {
                        break; // skip on to next service
                    }
                    ErrorUtilities.VerifyProtocol(service.Xrd.IsCanonicalIdVerified, XrdsStrings.CIDVerificationFailed, userSuppliedIdentifier);

                    // In the case of XRI names, the ClaimedId is actually the CanonicalID.
                    var claimedIdentifier = new XriIdentifier(service.Xrd.CanonicalID);
                    var providerEndpoint  = new ProviderEndpointDescription(uri.Uri, service.TypeElementUris);
                    yield return(IdentifierDiscoveryResult.CreateForClaimedIdentifier(claimedIdentifier, userSuppliedIdentifier, service.ProviderLocalIdentifier, providerEndpoint, service.Priority, uri.Priority));
                }
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="IdentifierDiscoveryResult"/> class.
 /// </summary>
 /// <param name="providerEndpoint">The provider endpoint.</param>
 /// <param name="claimedIdentifier">The Claimed Identifier.</param>
 /// <param name="userSuppliedIdentifier">The User-supplied Identifier.</param>
 /// <param name="providerLocalIdentifier">The Provider Local Identifier.</param>
 /// <param name="servicePriority">The service priority.</param>
 /// <param name="uriPriority">The URI priority.</param>
 private IdentifierDiscoveryResult(ProviderEndpointDescription providerEndpoint, Identifier claimedIdentifier, Identifier userSuppliedIdentifier, Identifier providerLocalIdentifier, int? servicePriority, int? uriPriority)
 {
     this.ProviderEndpoint = providerEndpoint.Uri;
     this.Capabilities = new ReadOnlyCollection<string>(providerEndpoint.Capabilities);
     this.Version = providerEndpoint.Version;
     this.ClaimedIdentifier = claimedIdentifier;
     this.ProviderLocalIdentifier = providerLocalIdentifier ?? claimedIdentifier;
     this.UserSuppliedIdentifier = userSuppliedIdentifier;
     this.ServicePriority = servicePriority;
     this.ProviderEndpointPriority = uriPriority;
 }
 /// <summary>
 /// Creates a <see cref="IdentifierDiscoveryResult"/> instance to represent some Claimed Identifier.
 /// </summary>
 /// <param name="claimedIdentifier">The claimed identifier.</param>
 /// <param name="userSuppliedIdentifier">The user supplied identifier.</param>
 /// <param name="providerLocalIdentifier">The provider local identifier.</param>
 /// <param name="providerEndpoint">The provider endpoint.</param>
 /// <param name="servicePriority">The service priority.</param>
 /// <param name="uriPriority">The URI priority.</param>
 /// <returns>The created <see cref="IdentifierDiscoveryResult"/> instance</returns>
 internal static IdentifierDiscoveryResult CreateForClaimedIdentifier(Identifier claimedIdentifier, Identifier userSuppliedIdentifier, Identifier providerLocalIdentifier, ProviderEndpointDescription providerEndpoint, int? servicePriority, int? uriPriority)
 {
     return new IdentifierDiscoveryResult(providerEndpoint, claimedIdentifier, userSuppliedIdentifier, providerLocalIdentifier, servicePriority, uriPriority);
 }
        /// <summary>
        /// Creates a <see cref="IdentifierDiscoveryResult"/> instance to represent some OP Identifier.
        /// </summary>
        /// <param name="providerIdentifier">The provider identifier (actually the user-supplied identifier).</param>
        /// <param name="providerEndpoint">The provider endpoint.</param>
        /// <param name="servicePriority">The service priority.</param>
        /// <param name="uriPriority">The URI priority.</param>
        /// <returns>The created <see cref="IdentifierDiscoveryResult"/> instance</returns>
        internal static IdentifierDiscoveryResult CreateForProviderIdentifier(Identifier providerIdentifier, ProviderEndpointDescription providerEndpoint, int? servicePriority, int? uriPriority)
        {
            Protocol protocol = Protocol.Lookup(providerEndpoint.Version);

            return new IdentifierDiscoveryResult(
                providerEndpoint,
                protocol.ClaimedIdentifierForOPIdentifier,
                providerIdentifier,
                protocol.ClaimedIdentifierForOPIdentifier,
                servicePriority,
                uriPriority);
        }