/// <summary> /// Start the proxy manually. This method will block until the proxy is connected. /// </summary> /// <param name="authenticationMethod">authentication method</param> /// <param name="instance">instance; to bind any available port use port 0. You can find the port number using GetPort()</param> /// <param name="credentials">credential file or json</param> public async Task <ProxyInstance> StartProxyAsync(AuthenticationMethod authenticationMethod, string instance, string credentials) { var proxyInstance = new ProxyInstance(ref _instance, instance); if (tcss.ContainsKey(instance)) { var rr = await tcss[instance].Task.ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(rr)) { throw new Exception(rr); } proxyCounter[instance]++; return(proxyInstance); } tcss.TryAdd(instance, new TaskCompletionSource <string>()); proxyCounter.TryAdd(instance, 1); var thread = new Thread(RunJob); thread.Start(new JobParams() { Platform = string.Copy(Platform), AuthenticationMethod = authenticationMethod, Instance = string.Copy(instance), Credentials = string.Copy(credentials) }); var result = await tcss[instance].Task.ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(result)) { throw new Exception(result); } return(proxyInstance); }
/// <summary> /// Start the proxy manually. This method will block until the proxy is connected. /// </summary> /// <param name="authenticationMethod">authentication method</param> /// <param name="instance">instance; to bind any available port use port 0. You can find the port number using GetPort()</param> /// <param name="credentials">credential file or json</param> public ProxyInstance StartProxy(AuthenticationMethod authenticationMethod, string instance, string credentials) { var proxyInstance = new ProxyInstance(ref _instance, instance); Task <string> task; string result; if (tcss.ContainsKey(instance)) { task = tcss[instance].Task; task.Wait(); result = task.Result; if (!string.IsNullOrWhiteSpace(result)) { throw new Exception(result); } proxyCounter[instance]++; return(proxyInstance); } tcss.TryAdd(instance, new TaskCompletionSource <string>()); var thread = new Thread(RunJob); proxyCounter.TryAdd(instance, 1); thread.Start(new JobParams() { Platform = string.Copy(Platform), AuthenticationMethod = authenticationMethod, Instance = string.Copy(instance), Credentials = string.Copy(credentials) }); task = tcss[instance].Task; task.Wait(); result = task.Result; if (!string.IsNullOrWhiteSpace(result)) { throw new Exception(result); } return(proxyInstance); }