/// <summary> /// Retrieves the proxy that will be used for the given URL. The result will /// be a string in PAC format. For more details about PAC format, please see /// http://en.wikipedia.org/wiki/Proxy_auto-config /// </summary> /// <param name="instance">An <code>InstanceHandle</code> identifying one /// instance of a module.</param> /// <param name="url">A string containing a URL.</param> /// <returns>Error code</returns> public static PPError GetProxyForURL(Instance instance, string url) { var cbwoAction = new Action <PPError, PPVar>( (result, proxy) => { HandleProxyForUrl?.Invoke(instance, new ProxyInfo(result, ((Var)proxy).AsString())); } ); var cbwo = new CompletionCallbackWithOutput <PPVar>(new CompletionCallbackWithOutputFunc <PPVar>(cbwoAction)); return((PPError)PPBNetworkProxy.GetProxyForURL(instance, new Var(url), out cbwo.OutputAdapter.output, cbwo)); }
private static async Task <ProxyInfo> GetProxyForURLAsyncCore(Instance instance, string url, MessageLoop messageLoop = null) { var tcs = new TaskCompletionSource <ProxyInfo>(); EventHandler <ProxyInfo> handler = (s, e) => { tcs.TrySetResult(e); }; try { HandleProxyForUrl += handler; if (messageLoop == null) { GetProxyForURL(instance, url); } else { Action <PPError> action = new Action <PPError>((e) => { var output = new PPVar(); var presult = (PPError)PPBNetworkProxy.GetProxyForURL(instance, new Var(url), out output, new BlockUntilComplete()); tcs.TrySetResult(new ProxyInfo(presult, ((Var)output).AsString())); } ); messageLoop.PostWork(action); } return(await tcs.Task); } catch (Exception exc) { Console.WriteLine(exc.Message); tcs.SetException(exc); return(new ProxyInfo(PPError.Aborted, string.Empty)); } finally { HandleProxyForUrl -= handler; } }