Example #1
0
        private string ParseInstanceName()
        {
            var instanceName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (instanceName == null)
            {
                return(null);
            }

            try
            {
                if (instanceName.IndexOf('\\') != -1)
                {
                    var startOfValue = instanceName.IndexOf('\\') + 1;
                    var endOfValue   = instanceName.Length;
                    return((startOfValue > 0) ? instanceName.Substring(startOfValue, endOfValue - startOfValue) : null);
                }
            }
            catch
            {
                return(null);
            }

            return(null);
        }
Example #2
0
        private string ParseHost()
        {
            // Example of want we would need to process:
            // (DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)))
            // 111.21.31.99:1521/XE
            // username/password@myserver[:1521]/myservice:dedicated/instancename
            // username/password@//myserver:1521/my.service.com;
            // serverName

            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (host == null)
            {
                return(null);
            }

            if (host.Contains(StringSeparators.OpenParenChar))
            {
                var sections = host.Split(StringSeparators.OpenParen);
                foreach (var section in sections)
                {
                    if (!section.ToLowerInvariant().Contains("host="))
                    {
                        continue;
                    }

                    var startOfValue = section.IndexOf(StringSeparators.EqualSignChar) + 1;
                    return(section.Substring(startOfValue).Replace(_closeParen, string.Empty));
                }
            }
            else if (host.Contains(StringSeparators.AtSignChar))
            {
                var sections             = host.Split(StringSeparators.PathSeparator);
                var initialHostSection   = sections[1];
                var secondaryHostSection = sections[3];

                var possibleHost = initialHostSection.Substring(initialHostSection.IndexOf(StringSeparators.AtSignChar) + 1);
                if (!string.IsNullOrEmpty(possibleHost))
                {
                    var colonLocation = possibleHost.IndexOf(StringSeparators.ColonChar);
                    return(colonLocation == -1 ? possibleHost : possibleHost.Substring(0, colonLocation));
                }

                var endOfValue = secondaryHostSection.IndexOf(StringSeparators.ColonChar);
                possibleHost = (endOfValue > -1) ? secondaryHostSection.Substring(0, secondaryHostSection.IndexOf(StringSeparators.ColonChar)) : secondaryHostSection;
                if (!string.IsNullOrEmpty(possibleHost))
                {
                    return(possibleHost);
                }

                return(null);
            }
            else
            {
                var endOfHostname = host.IndexOfAny(_stopChars);
                return(endOfHostname == -1 ? host : host.Substring(0, endOfHostname));
            }

            return(null);
        }
Example #3
0
        private string ParsePortPathOrId()
        {
            var portPathOrId = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (portPathOrId == null)
            {
                return(null);
            }

            try
            {
                if (portPathOrId.IndexOf(',') != -1)
                {
                    var startOfValue = portPathOrId.IndexOf(',') + 1;
                    var endOfValue   = portPathOrId.Contains('\\')
                        ? portPathOrId.IndexOf('\\')
                        : portPathOrId.Length;
                    return((startOfValue > 0) ? portPathOrId.Substring(startOfValue, endOfValue - startOfValue) : null);
                }
            }
            catch
            {
                return(null);
            }

            return("default");
        }
Example #4
0
        private string ParseHost()
        {
            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (host == null)
            {
                return(null);
            }

            // Example of want we would need to process: win-database.pdx.vm.datanerd.us,1433\SQLEXPRESS
            try
            {
                var splitIndex = host.IndexOf(',');
                if (splitIndex == -1)
                {
                    splitIndex = host.IndexOf('\\');
                }
                host = splitIndex == -1 ? host : host.Substring(0, splitIndex);
            }
            catch
            {
                return(null);
            }
            return(host);
        }
Example #5
0
        public ConnectionInfo GetConnectionInfo()
        {
            // Other than the hosts, these are MOST of the other possibilities.
            // Not since they all contain and "=" I am filtering by that.
            //var options = new[]
            //{
            //	"abortConnect=","allowAdmin=","channelPrefix=","connectRetry=","connectTimeout=",
            //	"configChannel=","defaultDatabase=","keepAlive=","name=","password="******"proxy=","resolveDns=","serviceName=","ssl=","sslHost=",
            //	"syncTimeout=","tiebreaker=","version=","writeBuffer="
            //};

            // Example connection string: localhost,resolvedns=1
            // Example connection string: localhost,abortConnect=true
            // Example connection string: localhost,password=awesomesuace, name=stuffandthings

            var sections = _connectionString.Split(StringSeparators.Comma);

            foreach (var section in sections)
            {
                if (section.Contains('='))
                {
                    continue;
                }

                // We can only capture the first server we detect.  It could be that there are many....
                var hostPortPair = section.Split(StringSeparators.Colon);
                var port         = hostPortPair.Length == 2 ? hostPortPair[1] : null;
                return(new ConnectionInfo(ConnectionStringParserHelper.NormalizeHostname(hostPortPair[0]), port, null));
            }

            return(new ConnectionInfo(null, null, null));
        }
Example #6
0
        public ConnectionInfo GetConnectionInfo()
        {
            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            var hasMultipleHosts = host != null && host.IndexOf(',') != -1;

            if (hasMultipleHosts)
            {
                host = null;
            }
            else if (host != null)
            {
                host = ConnectionStringParserHelper.NormalizeHostname(host);
            }

            var portPathOrId = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _portKeys)?.Value;

            if (portPathOrId == null && host != null)
            {
                portPathOrId = "default";
            }

            var databaseName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _databaseNameKeys)?.Value;

            return(new ConnectionInfo(host, portPathOrId, databaseName));
        }
Example #7
0
        private string ParsePortPathOrId()
        {
            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (host == null)
            {
                return(null);
            }

            if (host.Contains(StringSeparators.OpenParenChar))
            {
                var sections = host.Split(StringSeparators.OpenParen);
                foreach (var section in sections)
                {
                    if (!section.ToLowerInvariant().Contains("port="))
                    {
                        continue;
                    }

                    var startOfValue = section.IndexOf(StringSeparators.EqualSignChar) + 1;
                    return(section.Substring(startOfValue).Replace(_closeParen, string.Empty));
                }
            }

            else if (host.Contains(StringSeparators.AtSignChar))
            {
                var sections             = host.Split(StringSeparators.PathSeparator);
                var initialPortSection   = sections[1];
                var secondaryPortSection = sections[3];

                var startOfValue = initialPortSection.IndexOf(StringSeparators.ColonChar);
                if (startOfValue > -1)
                {
                    return(initialPortSection.Substring(startOfValue + 1));
                }

                startOfValue = secondaryPortSection.IndexOf(StringSeparators.ColonChar);
                if (startOfValue > -1)
                {
                    return(secondaryPortSection.Substring(startOfValue + 1));
                }

                return("default");
            }
            else
            {
                var startOfValue = host.IndexOf(StringSeparators.ColonChar) + 1;
                var endOfValue   = host.IndexOf(StringSeparators.PathSeparatorChar, startOfValue);

                if (endOfValue == -1)
                {
                    endOfValue = host.Length;
                }

                return(host.Substring(startOfValue, endOfValue - startOfValue));
            }

            return(null);
        }
Example #8
0
        private string ParseHost()
        {
            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (host == null)
            {
                return(null);
            }

            var endOfHostname = host.IndexOf(':');

            return(endOfHostname == -1 ? host : host.Substring(0, endOfHostname));
        }
Example #9
0
        public ConnectionInfo GetConnectionInfo()
        {
            var host = ParseHost();

            if (host != null)
            {
                host = ConnectionStringParserHelper.NormalizeHostname(host);
            }
            var portPathOrId = ParsePortPathOrId();
            var databaseName = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _databaseNameKeys)?.Value;

            return(new ConnectionInfo(host, portPathOrId, databaseName));
        }
Example #10
0
        private string ParsePortPathOrId()
        {
            var host = ConnectionStringParserHelper.GetKeyValuePair(_connectionStringBuilder, _hostKeys)?.Value;

            if (host == null)
            {
                return(null);
            }

            if (host.Contains(':'))
            {
                return(host.Substring(host.IndexOf(':') + 1));
            }

            return("default");
        }