예제 #1
0
        private static bool TryParseAuth(string str, out RPCCredentialString connectionString)
        {
            str = str.Trim();
            if (str.Equals("default", StringComparison.OrdinalIgnoreCase) || string.IsNullOrEmpty(str))
            {
                connectionString = new RPCCredentialString();
                return(true);
            }

            if (str.StartsWith("cookiefile=", StringComparison.OrdinalIgnoreCase))
            {
                var path = str.Substring("cookiefile=".Length);
                connectionString            = new RPCCredentialString();
                connectionString.CookieFile = path;
                return(true);
            }

            if (str.IndexOf(':') != -1)
            {
                var parts = str.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length >= 2)
                {
                    parts[1]         = string.Join(":", parts.Skip(1).ToArray());
                    connectionString = new RPCCredentialString();
                    connectionString.UserPassword = new NetworkCredential(parts[0], parts[1]);
                    return(true);
                }
            }

            connectionString = null;
            return(false);
        }
예제 #2
0
        public static bool TryParse(string str, out RPCCredentialString connectionString)
        {
            connectionString = null;
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            var    parts      = str.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
            string walletName = null;
            string server     = null;

            foreach (var part in parts)
            {
                if (part == parts[parts.Length - 1])
                {
                    TryParseAuth(part, out connectionString);
                    break;
                }
                if (part.StartsWith("wallet=", StringComparison.OrdinalIgnoreCase))
                {
                    walletName = part.Substring("wallet=".Length);
                }
                else if (part.StartsWith("server=", StringComparison.OrdinalIgnoreCase))
                {
                    server = part.Substring("server=".Length);
                }
                else
                {
                    return(false);
                }
            }

            if (connectionString == null)
            {
                return(false);
            }
            connectionString.WalletName = walletName;
            connectionString.Server     = server;
            return(true);
        }