private void btnTest_Click(object sender, EventArgs e) { try { ScriptProxyClientFactory factory = new ScriptProxyClientFactory(); factory.Script = textBoxScript.Text; IWebProxyScript proxy = factory.GetProxyInstance(); if (proxy != null) { Uri u = new Uri(textBoxUrl.Text, UriKind.Absolute); MessageBox.Show(this, String.Format(Properties.Resources.ConfigurePacScriptForm_TestReturned, proxy.Run(u.AbsoluteUri, u.Host))); } else { MessageBox.Show(this, Properties.Resources.ConfigurePacScriptForm_CannotUseProxyScript, Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { TargetInvocationException tex = ex as TargetInvocationException; MessageBox.Show(this, tex != null ? tex.InnerException.Message : ex.Message, Properties.Resources.MessageBox_ErrorString, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
internal AutoWebProxyScriptWrapper() { Exception exception = null; if ((s_ProxyScriptHelperLoadError == null) && (s_ProxyScriptHelperType == null)) { lock (s_ProxyScriptHelperLock) { if ((s_ProxyScriptHelperLoadError == null) && (s_ProxyScriptHelperType == null)) { try { s_ProxyScriptHelperType = Type.GetType("System.Net.VsaWebProxyScript, Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true); } catch (Exception exception2) { exception = exception2; } if (s_ProxyScriptHelperType == null) { s_ProxyScriptHelperLoadError = (exception == null) ? new InternalException() : exception; } } } } if (s_ProxyScriptHelperLoadError != null) { throw new TypeLoadException(SR.GetString("net_cannot_load_proxy_helper"), (s_ProxyScriptHelperLoadError is InternalException) ? null : s_ProxyScriptHelperLoadError); } this.CreateAppDomain(); exception = null; try { ObjectHandle handle = Activator.CreateInstance(this.scriptDomain, s_ProxyScriptHelperType.Assembly.FullName, s_ProxyScriptHelperType.FullName, false, BindingFlags.CreateInstance | BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null, null, null); if (handle != null) { this.site = (IWebProxyScript)handle.Unwrap(); } } catch (Exception exception3) { exception = exception3; } if (this.site == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null) { s_ProxyScriptHelperLoadError = (exception == null) ? new InternalException() : exception; } } throw new TypeLoadException(SR.GetString("net_cannot_load_proxy_helper"), (s_ProxyScriptHelperLoadError is InternalException) ? null : s_ProxyScriptHelperLoadError); } }
internal AutoWebProxyScriptWrapper() { Exception exception = null; if ((s_ProxyScriptHelperLoadError == null) && (s_ProxyScriptHelperType == null)) { lock (s_ProxyScriptHelperLock) { if ((s_ProxyScriptHelperLoadError == null) && (s_ProxyScriptHelperType == null)) { try { s_ProxyScriptHelperType = Type.GetType("System.Net.VsaWebProxyScript, Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true); } catch (Exception exception2) { exception = exception2; } if (s_ProxyScriptHelperType == null) { s_ProxyScriptHelperLoadError = (exception == null) ? new InternalException() : exception; } } } } if (s_ProxyScriptHelperLoadError != null) { throw new TypeLoadException(SR.GetString("net_cannot_load_proxy_helper"), (s_ProxyScriptHelperLoadError is InternalException) ? null : s_ProxyScriptHelperLoadError); } this.CreateAppDomain(); exception = null; try { ObjectHandle handle = Activator.CreateInstance(this.scriptDomain, s_ProxyScriptHelperType.Assembly.FullName, s_ProxyScriptHelperType.FullName, false, BindingFlags.CreateInstance | BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, null, null, null, null); if (handle != null) { this.site = (IWebProxyScript) handle.Unwrap(); } } catch (Exception exception3) { exception = exception3; } if (this.site == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null) { s_ProxyScriptHelperLoadError = (exception == null) ? new InternalException() : exception; } } throw new TypeLoadException(SR.GetString("net_cannot_load_proxy_helper"), (s_ProxyScriptHelperLoadError is InternalException) ? null : s_ProxyScriptHelperLoadError); } }
/// <summary> /// Create client /// </summary> /// <param name="logger">The logger to use</param> /// <returns>The new proxy client</returns> public override ProxyClient Create(Utils.Logger logger) { IWebProxyScript proxyScript = GetProxyInstance(); if (proxyScript == null) { logger.LogError(Properties.Resources.ScriptProxyFactory_CannotCreateScript); return(new IpProxyClient()); } else { return(new ScriptProxyClient(proxyScript)); } }
/// <summary> /// Get the proxy script instance /// </summary> /// <returns>The proxy instance</returns> public IWebProxyScript GetProxyInstance() { if (_proxyScript == null) { if ((webProxyScriptType != null) && (webProxyScriptHelperType != null)) { _proxyScript = (IWebProxyScript)Activator.CreateInstance(webProxyScriptType); _proxyScript.Load(_scriptUri ?? new Uri("http://www.contextis.co.uk", UriKind.Absolute), _script, webProxyScriptHelperType); } } return(_proxyScript); }
internal AutoWebProxyScriptWrapper() { GlobalLog.Print("AutoWebProxyScriptWrapper::.ctor() Creating AppDomain: " + c_appDomainName); Exception exception = null; if (s_ProxyScriptHelperLoadError == null && s_ProxyScriptHelperType == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null && s_ProxyScriptHelperType == null) { // Try to load the type late-bound out of Microsoft.JScript. try { s_ProxyScriptHelperType = Type.GetType("System.Net.VsaWebProxyScript, Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true); } catch (Exception ex) { exception = ex; } if (s_ProxyScriptHelperType == null) { s_ProxyScriptHelperLoadError = exception == null ? new InternalException() : exception; } } } } if (s_ProxyScriptHelperLoadError != null) { throw new TypeLoadException(SR.GetString(SR.net_cannot_load_proxy_helper), s_ProxyScriptHelperLoadError is InternalException ? null : s_ProxyScriptHelperLoadError); } CreateAppDomain(); exception = null; try { GlobalLog.Print("AutoWebProxyScriptWrapper::CreateInstance() Creating Object. type.Assembly.FullName: [" + s_ProxyScriptHelperType.Assembly.FullName + "] type.FullName: [" + s_ProxyScriptHelperType.FullName + "]"); ObjectHandle handle = Activator.CreateInstance(scriptDomain, s_ProxyScriptHelperType.Assembly.FullName, s_ProxyScriptHelperType.FullName, false, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, null, null, null); if (handle != null) { site = (IWebProxyScript) handle.Unwrap(); } GlobalLog.Print("AutoWebProxyScriptWrapper::CreateInstance() Create script site:" + ValidationHelper.HashString(site)); } catch (Exception ex) { exception = ex; } if (site == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null) { s_ProxyScriptHelperLoadError = exception == null ? new InternalException() : exception; } } throw new TypeLoadException(SR.GetString(SR.net_cannot_load_proxy_helper), s_ProxyScriptHelperLoadError is InternalException ? null : s_ProxyScriptHelperLoadError); } }
internal AutoWebProxyScriptWrapper() { GlobalLog.Print("AutoWebProxyScriptWrapper::.ctor() Creating AppDomain: " + c_appDomainName); Exception exception = null; if (s_ProxyScriptHelperLoadError == null && s_ProxyScriptHelperType == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null && s_ProxyScriptHelperType == null) { // Try to load the type late-bound out of Microsoft.JScript. try { s_ProxyScriptHelperType = Type.GetType("System.Net.VsaWebProxyScript, Microsoft.JScript, Version=8.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", true); } catch (Exception ex) { exception = ex; } if (s_ProxyScriptHelperType == null) { s_ProxyScriptHelperLoadError = exception == null ? new InternalException() : exception; } } } } if (s_ProxyScriptHelperLoadError != null) { throw new TypeLoadException(SR.GetString(SR.net_cannot_load_proxy_helper), s_ProxyScriptHelperLoadError is InternalException ? null : s_ProxyScriptHelperLoadError); } CreateAppDomain(); exception = null; try { GlobalLog.Print("AutoWebProxyScriptWrapper::CreateInstance() Creating Object. type.Assembly.FullName: [" + s_ProxyScriptHelperType.Assembly.FullName + "] type.FullName: [" + s_ProxyScriptHelperType.FullName + "]"); ObjectHandle handle = Activator.CreateInstance(scriptDomain, s_ProxyScriptHelperType.Assembly.FullName, s_ProxyScriptHelperType.FullName, false, BindingFlags.CreateInstance | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.InvokeMethod, null, null, null, null, null); if (handle != null) { site = (IWebProxyScript)handle.Unwrap(); } GlobalLog.Print("AutoWebProxyScriptWrapper::CreateInstance() Create script site:" + ValidationHelper.HashString(site)); } catch (Exception ex) { exception = ex; } if (site == null) { lock (s_ProxyScriptHelperLock) { if (s_ProxyScriptHelperLoadError == null) { s_ProxyScriptHelperLoadError = exception == null ? new InternalException() : exception; } } throw new TypeLoadException(SR.GetString(SR.net_cannot_load_proxy_helper), s_ProxyScriptHelperLoadError is InternalException ? null : s_ProxyScriptHelperLoadError); } }
/// <summary> /// Constructor /// </summary> /// <param name="proxyScript">The proxy script object</param> public ScriptProxyClient(IWebProxyScript proxyScript) { _proxyScript = proxyScript; }
/// <summary> /// Get the proxy script instance /// </summary> /// <returns>The proxy instance</returns> public IWebProxyScript GetProxyInstance() { if (_proxyScript == null) { if ((webProxyScriptType != null) && (webProxyScriptHelperType != null)) { _proxyScript = (IWebProxyScript)Activator.CreateInstance(webProxyScriptType); _proxyScript.Load(_scriptUri ?? new Uri("http://www.contextis.co.uk", UriKind.Absolute), _script, webProxyScriptHelperType); } } return _proxyScript; }
/// <summary> /// Constructor /// </summary> /// <param name="proxyScript">The proxy script object</param> public ScriptProxyClient(IWebProxyScript proxyScript) { _proxyScript = proxyScript; }