示例#1
0
 /// <summary>
 /// Standard constructor
 /// </summary>
 public ProxyServerConnection(Socket incomingConnection, ProxyServer server)
 {
     IncomingConnection = incomingConnection;
     Server = server;
 }
示例#2
0
        /// <summary>
        /// Creates a proxy server from the server in the given connection string using the default construction parameters and starts the proxy
        /// </summary>
        /// <param name="connectionString">Connection string to the server to proxy</param>
        /// <param name="newConnectionString">Connection string to the proxy server (using the same parameters as <paramref name="connectionString"/>)</param>
        /// <returns>The created and started proxy server</returns>
        public static ProxyServer CreateAndStartProxy(string connectionString, out string newConnectionString)
        {
            // Build builders
            SqlConnectionStringBuilder connStringbuilder = new SqlConnectionStringBuilder(connectionString);
            DataSourceBuilder dataSourceBuilder = new DataSourceBuilder(connStringbuilder.DataSource);

            // Setup proxy
            Task<System.Net.IPHostEntry> ipEntryTask = Dns.GetHostEntryAsync(dataSourceBuilder.ServerName);
            ipEntryTask.Wait();
            System.Net.IPHostEntry serverIpEntry = ipEntryTask.Result;

            ProxyServer proxy = new ProxyServer();
            proxy.RemoteEndpoint = new IPEndPoint(serverIpEntry.AddressList[0], dataSourceBuilder.Port ?? 1433);
            proxy.Start();

            // Switch connection over
            dataSourceBuilder.Protocol = "tcp";
            dataSourceBuilder.ServerName = "127.0.0.1";
            dataSourceBuilder.Port = proxy.LocalPort;
            connStringbuilder.DataSource = dataSourceBuilder.ToString();
            connStringbuilder.Remove("Network Library");

            newConnectionString = connStringbuilder.ToString();
            return proxy;
        }