コード例 #1
0
        public static SqliteConnectionParameters Parse(string connectionString)
        {
            ParametersParser parser = new ParametersParser(connectionString);

            SqliteConnectionParameters connParams = new SqliteConnectionParameters
            {
                Group      = parser.GetValue(AliasesGroup),
                Connection = parser.GetValue(AliasesConnection),
                Template   = parser.GetValue(AliasesTemplate),
                Login      = parser.GetValue(AliasesLogin)
            };

            return(connParams);
        }
コード例 #2
0
        public static NetworkInformationConnection Parse(string connectionString)
        {
            ParametersParser parser = new ParametersParser(connectionString);
            ProtocolType     protocol;
            int port    = 0;
            int timeout = 0;

            if (!Enum.TryParse(parser.GetValue(AliasesProtocol), true, out protocol))
            {
                protocol = ProtocolType.Tcp;
            }

            if (!int.TryParse(parser.GetValue(AliasesPort), out port))
            {
                switch (protocol)
                {
                case ProtocolType.Tcp:
                case ProtocolType.Udp:
                    port = 80;                             // assing default port for tcp/udp
                    break;

                case ProtocolType.Icmp:
                    port = 1;
                    break;
                }
            }

            if (!int.TryParse(parser.GetValue(AliasesTimeout), out timeout))
            {
                // timeout is not defined explicitly
                // default value will be used
                timeout = 0;
            }

            string host = parser.GetValue(AliasesHost);

            if (string.IsNullOrEmpty(host))
            {
                host = connectionString;                 // assume that connection string is a host name
            }

            return(new NetworkInformationConnection(
                       host,
                       port,
                       protocol,
                       timeout
                       ));
        }