Match() private method

private Match ( string host, int port, string authenticationType ) : bool
host string
port int
authenticationType string
return bool
コード例 #1
0
        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (authenticationType == null)
            {
                throw new ArgumentNullException("authenticationType");
            }
            if (host.Length == 0)
            {
                throw new ArgumentException(SR.GetString("net_emptystringcall", new object[] { "host" }));
            }
            if (port < 0)
            {
                throw new ArgumentOutOfRangeException("port");
            }
            NetworkCredential     credential = null;
            IDictionaryEnumerator enumerator = this.cacheForHosts.GetEnumerator();

            while (enumerator.MoveNext())
            {
                CredentialHostKey key = (CredentialHostKey)enumerator.Key;
                if (key.Match(host, port, authenticationType))
                {
                    credential = (NetworkCredential)enumerator.Value;
                }
            }
            return(credential);
        }
コード例 #2
0
ファイル: CredentialCache.cs プロジェクト: schaabs/corefx
        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            if (host == null)
            {
                throw new ArgumentNullException("host");
            }
            if (authenticationType == null)
            {
                throw new ArgumentNullException("authenticationType");
            }
            if (host.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, "host"));
            }
            if (port < 0)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            bool globalLogEnabled = GlobalLog.IsEnabled;

            if (globalLogEnabled)
            {
                GlobalLog.Print("CredentialCache::GetCredential(host=\"" + host + ":" + port.ToString() + "\", authenticationType=\"" + authenticationType + "\")");
            }

            NetworkCredential match = null;

            IDictionaryEnumerator credEnum = _cacheForHosts.GetEnumerator();

            // Enumerate through every credential in the cache
            while (credEnum.MoveNext())
            {
                CredentialHostKey key = (CredentialHostKey)credEnum.Key;

                // Determine if this credential is applicable to the current Uri/AuthType
                if (key.Match(host, port, authenticationType))
                {
                    match = (NetworkCredential)credEnum.Value;
                }
            }

            if (globalLogEnabled)
            {
                GlobalLog.Print("CredentialCache::GetCredential returning " + ((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")"));
            }
            return(match);
        }
コード例 #3
0
        public NetworkCredential GetCredential(string host, int port, string authenticationType)
        {
            if (host == null)
            {
                throw new ArgumentNullException(nameof(host));
            }
            if (authenticationType == null)
            {
                throw new ArgumentNullException(nameof(authenticationType));
            }
            if (host.Length == 0)
            {
                throw new ArgumentException(SR.Format(SR.net_emptystringcall, "host"));
            }
            if (port < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(port));
            }

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("CredentialCache::GetCredential(host=\"" + host + ":" + port.ToString() + "\", authenticationType=\"" + authenticationType + "\")");
            }

            NetworkCredential match = null;

            // Enumerate through every credential in the cache
            foreach (KeyValuePair <CredentialHostKey, NetworkCredential> pair in _cacheForHosts)
            {
                CredentialHostKey key = pair.Key;

                // Determine if this credential is applicable to the current Uri/AuthType
                if (key.Match(host, port, authenticationType))
                {
                    match = pair.Value;
                }
            }

            if (GlobalLog.IsEnabled)
            {
                GlobalLog.Print("CredentialCache::GetCredential returning " + ((match == null) ? "null" : "(" + match.UserName + ":" + match.Domain + ")"));
            }
            return(match);
        }