System.Net.AutoWebProxyScriptWrapper.FindProxyForURL C# (CSharp) Method

FindProxyForURL() private method

private FindProxyForURL ( string url, string host ) : string
url string
host string
return string
        internal string FindProxyForURL(string url, string host)
        {
            if (url == null || host == null)
            {
                throw new ArgumentNullException(url == null ? "url" : "host");
            }
            if (closed != 0)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            EXCEPINFO exceptionInfo = new EXCEPINFO();
            object result = null;
            jscript.GetCurrentScriptThreadID(out interruptThreadId);
            TimerThread.Timer timer = s_TimerQueue.CreateTimer(s_InterruptCallback, this);
            activeTimer = timer;
            try
            {
                GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::FindProxyForURL() Calling url:" + url + " host:" + host);
                result = script.FindProxyForURL(url, host);
            }
            catch (Exception exception)
            {
                if (NclUtilities.IsFatal(exception)) throw;
                if (exception is TargetInvocationException)
                {
                    exception = exception.InnerException;
                }
                COMException comException = exception as COMException;
                if (comException == null || comException.ErrorCode != (int) HRESULT.SCRIPT_E_REPORTED)
                {
                    throw;
                }
                GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::FindProxyForURL() Script error:[" + this.host.ExceptionMessage == null ? "" : this.host.ExceptionMessage + "]");
            }
            catch {
                GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::FindProxyForURL() Script error:[Non-CLS Compliant Exception]");
                throw;
            }
            finally
            {
                activeTimer = null;
                timer.Cancel();
            }

            string proxy = result as string;
            if (proxy != null)
            {
                GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::FindProxyForURL() found:" + proxy);
                return proxy;
            }

            GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::FindProxyForURL() Returning null. result:" + ValidationHelper.ToString(exceptionInfo.bstrDescription) + " result:" + ValidationHelper.ToString(result) + " error:" + ValidationHelper.ToString(exceptionInfo.bstrDescription));
            return null;
        }

Usage Example

        public override bool GetProxies(Uri destination, out IList <string> proxyList)
        {
            try
            {
                proxyList = null;

                EnsureEngineAvailable();

                // after EnsureEngineAvailable we expect State to be CompilationSuccess, otherwise return.
                if (State != AutoWebProxyState.Completed)
                {
                    // the script can't run, say we're not ready and bypass
                    return(false);
                }

                bool result = false;
                try
                {
                    string proxyListString = scriptInstance.FindProxyForURL(destination.ToString(), destination.Host);
                    GlobalLog.Print("NetWebProxyFinder#" + ValidationHelper.HashString(this) + "::GetProxies() calling ExecuteFindProxyForURL() for destination:" + ValidationHelper.ToString(destination) + " returned scriptReturn:" + ValidationHelper.ToString(proxyList));

                    proxyList = ParseScriptResult(proxyListString);

                    result = true;
                }
                catch (Exception exception)
                {
                    if (Logging.On)
                    {
                        Logging.PrintWarning(Logging.Web, SR.GetString(SR.net_log_proxy_script_execution_error, exception));
                    }
                }

                return(result);
            }
            finally
            {
                // Reset state of 'aborted', since next call to GetProxies() must not use previous aborted state.
                aborted = false;
            }
        }
All Usage Examples Of System.Net.AutoWebProxyScriptWrapper::FindProxyForURL