public void Interrupt() { // See http://e.craft.free.fr/ActiveScriptingLostFAQ/hostrun.htm // And https://github.com/jango2015/VS-Macros/tree/master/ExecutionEngine/ActiveScript%20Interfaces if (IsRunning()) { try { EXCEPINFO ei = new EXCEPINFO { wCode = 1000, scode = 0, bstrSource = "Interrupt", bstrDescription = "Interrupt", bstrHelpFile = "Interrupt", pfnDeferredFillIn = IntPtr.Zero, dwHelpContext = 0, wReserved = 0, pvReserved = IntPtr.Zero, }; _scriptEngine.InterruptScriptThread(SCRIPTTHREADID_BASE, ref ei, 0); } catch (Exception e) { Console.WriteLine(string.Format("Exception while interrupting thread '{0}'\nException: {1}", _processThread.Name, e)); } } }
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); }
public int AddError(string pszPropName, System.Runtime.InteropServices.ComTypes.EXCEPINFO pExcepInfo) { if (_errors == null) { _errors = new List <ErrorItem>(); } _errors.Add(new ErrorItem(pszPropName, pExcepInfo)); return(_errors.Count); }
/// <summary> /// Adds the specified code to the scripting engine under the specified namespace. /// The code that is added will be available only under the namespace specified /// instead of in the global scope of the script. The script name will be used /// to provide more useful error information if an error occurs during the execution /// of the code that was added. /// </summary> /// <param name="code">The code to be added.</param> /// <param name="namespaceName">The name of the namespace to add the code to.</param> /// <param name="scriptName">The script name that the code came from.</param> /// <exception cref="ArgumentNullException">If code is null.</exception> /// <exception cref="ArgumentException">If code is blank.</exception> public void AddCode(string code, string namespaceName, string scriptName) { if (code == null) { throw new ArgumentNullException("code"); } if (string.IsNullOrEmpty(code)) { throw new ArgumentException("code parameter must contain code", "code"); } if (namespaceName != null) { activeScript.AddNamedItem(namespaceName, ScriptItemFlags.CodeOnly | ScriptItemFlags.IsVisible); } try { /* * In the event that the passed in script is not valid syntax * an error will be thrown by the script engine. This will be * handled by the OnScriptError event before the exception * is thrown here so we need to set this variable to use * in the OnScriptError block to figure out the script name * since it won't have been added to the script list. */ scriptToParse = scriptName; EXCEPINFO exceptionInfo = new EXCEPINFO(); ulong cookie = (ulong)scripts.Count; parser.ParseScriptText( code: code, itemName: namespaceName, context: null, delimiter: null, sourceContext: cookie, startingLineNumber: 1u, flags: ScriptTextFlags.IsVisible, pVarResult: IntPtr.Zero, excepInfo: out exceptionInfo); ScriptInfo si = new ScriptInfo() { Code = code, ScriptName = scriptName }; scripts.Add(cookie, si); } finally { scriptToParse = null; } }
public void CreateException(string Text) { System.Runtime.InteropServices.ComTypes.EXCEPINFO ExcInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); ExcInfo.wCode = 1006; //Вид пиктограммы ExcInfo.bstrDescription = Text; ExcInfo.bstrSource = c_AddinName; Data1C.ErrorLog.AddError("", ref ExcInfo); throw new COMException("An exception has occurred."); }
/// <summary> /// Interrupts script execution and causes the script engine to throw an exception. /// </summary> /// <remarks> /// This method can be called safely from any thread. /// </remarks> public override void Interrupt() { VerifyNotDisposed(); var excepInfo = new EXCEPINFO { scode = RawCOMHelpers.HResult.E_ABORT }; activeScript.InterruptScriptThread(ScriptThreadID.Base, ref excepInfo, ScriptInterruptFlags.None); }
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; }
private bool ReflectUserMode() { Guid id = Guid.Empty; var prm = new DISPPARAMS(); uint lcid = 0; ushort wFlags = 2; dynamic result; var ei = new EXCEPINFO(); _site.Invoke(ActiveXConstants.DISPID_AMBIENT_USERMODE, ref id, lcid, wFlags, ref prm, out result, ref ei, null); return(result); }
int IProxyManager.Invoke( UInt32 dispIdMember, IntPtr outerProxy, IntPtr pVarResult, IntPtr pExcepInfo ) { try { ComProxy comProxy = null; Guid riid; if ((dispIdMember == 1)) { riid = typeof(IChannelOptions).GUID; } else if ((dispIdMember == 2)) { riid = typeof(IChannelCredentials).GUID; } else { return(HR.DISP_E_MEMBERNOTFOUND); } FindOrCreateProxyInternal(outerProxy, ref riid, out comProxy); TagVariant variant = new TagVariant(); variant.vt = (ushort)VarEnum.VT_DISPATCH; IntPtr tearOffDispatch = IntPtr.Zero; comProxy.QueryInterface(ref riid, out tearOffDispatch); variant.ptr = tearOffDispatch; Marshal.StructureToPtr(variant, pVarResult, true); return(HR.S_OK); } catch (Exception e) { if (Fx.IsFatal(e)) { throw; } if (pExcepInfo != IntPtr.Zero) { System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); e = e.GetBaseException(); exceptionInfo.bstrDescription = e.Message; exceptionInfo.bstrSource = e.Source; exceptionInfo.scode = Marshal.GetHRForException(e); Marshal.StructureToPtr(exceptionInfo, pExcepInfo, false); } return(HR.DISP_E_EXCEPTION); } }
internal HRESULT ParseScriptText( string code, string itemName, [MarshalAs(UnmanagedType.IUnknown)] object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, [MarshalAs(UnmanagedType.Struct)] out object result, out System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { return(this.FAsp32 != null?this.FAsp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo) : this.FAsp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo)); }
public override DispatchResult Invoke( int id, uint lcid, DispatchFlags wFlags, object[] args, out System.Runtime.InteropServices.ComTypes.EXCEPINFO pExcepInfo, out uint puArgErr, out object ret) { pExcepInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); puArgErr = 0; ret = this.Handler(args); return DispatchResult.Ok; }
private static string GetErrorDescription(System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { string description = exceptionInfo.bstrDescription; if (description.Equals("Object required")) { description = Resources.NoActiveDocumentErrorMessage; } else if (string.IsNullOrEmpty(description)) { description = Resources.CommandNotValid; } return(description); }
protected void Error(string message) { try { var ei = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); ei.wCode = (short)ERRORCODE.ADDIN_E_FAIL; ei.bstrSource = this.ToString(); ei.bstrDescription = message; _errorLog.AddError(null, ref ei); } catch { } }
// invoke a method on the target IDispatchEx object public static object Invoke(object target, string method, params object[] args) { var dispEx = target as IDispatchEx; if (dispEx == null) { throw new InvalidComObjectException(); } var dp = new System.Runtime.InteropServices.ComTypes.DISPPARAMS(); try { // repack arguments if (args.Length > 0) { // should be using stackalloc for DISPPARAMS arguments, but don't want enforce "/unsafe" int size = SIZE_OF_VARIANT * args.Length; dp.rgvarg = Marshal.AllocCoTaskMem(size); ZeroMemory(dp.rgvarg, size); // zero'ing is equal to VariantInit dp.cArgs = args.Length; for (int i = 0; i < dp.cArgs; i++) { Marshal.GetNativeVariantForObject(args[i], dp.rgvarg + SIZE_OF_VARIANT * (args.Length - i - 1)); } } int dispid; dispEx.GetDispID(method, fdexNameCaseSensitive, out dispid); var ei = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); var result = Type.Missing; dispEx.InvokeEx(dispid, 0, DISPATCH_METHOD, ref dp, ref result, ref ei, null); return(result); } finally { if (dp.rgvarg != IntPtr.Zero) { for (var i = 0; i < dp.cArgs; i++) { VariantClear(dp.rgvarg + SIZE_OF_VARIANT * i); } Marshal.FreeCoTaskMem(dp.rgvarg); } } }
/// <summary> /// Отправить служебное сообщение 1С /// </summary> /// <param name="message"></param> /// <param name="propName"></param> protected void PathMessageToErrorLog(string message, string propName) { var pExcepInfo = new EXCEPINFO { bstrDescription = message, bstrSource = AddInName, pfnDeferredFillIn = (IntPtr)null, pvReserved = (IntPtr)null, scode = (int)S_OK, wCode = ADDIN_E_INFO, wReserved = 0, bstrHelpFile = "", dwHelpContext = 0 }; ErrorLog.AddError(propName, ref pExcepInfo); }
public void AddScriptlet( string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, ulong sourceContext, uint startingLineNumber, ScriptTextFlags flags, out string name, out EXCEPINFO excepInfo) { if (is64Bit) { activeScriptParse64.AddScriptlet( defaultName, code, itemName, subItemName, eventName, delimiter, sourceContext, startingLineNumber, flags, out name, out excepInfo); } else { activeScriptParse32.AddScriptlet( defaultName, code, itemName, subItemName, eventName, delimiter, (uint)sourceContext, startingLineNumber, flags, out name, out excepInfo); } }
/// <summary> /// Evaluates the specified code inside the context of the script and returns /// the result, or null if no result was returned. /// </summary> /// <param name="code">The code to evaluate.</param> /// <returns>The result of the evaluation.</returns> /// <exception cref="ArgumentNullException">If code is null.</exception> /// <exception cref="ArgumentException">If code is blank.</exception> public object Evaluate(string code) { if (code == null) { throw new ArgumentNullException("code"); } if (string.IsNullOrEmpty(code)) { throw new ArgumentException("code parameter must contain code", "code"); } EXCEPINFO exceptionInfo = new EXCEPINFO(); ulong cookie = (ulong)scripts.Count; IntPtr result = Marshal.AllocCoTaskMem(1024); try { parser.ParseScriptText( code: code, itemName: null, context: null, delimiter: null, sourceContext: cookie, startingLineNumber: 1u, flags: ScriptTextFlags.IsExpression, pVarResult: result, excepInfo: out exceptionInfo); if (result != IntPtr.Zero) { return(Marshal.GetObjectForNativeVariant(result)); } } finally { Marshal.FreeCoTaskMem(result); } return(null); }
internal void AddScriptlet( string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name, out System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { if (this.FAsp32 != null) { this.FAsp32.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } else { this.FAsp64.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } }
internal void ParseScriptText( string code, string itemName, [MarshalAs(UnmanagedType.IUnknown)] object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, [MarshalAs(UnmanagedType.Struct)] out object result, out EXCEPINFO exceptionInfo) { if (asp32 != null) { asp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo); } else { asp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo); } }
public void ParseScriptText( string code, string itemName, object context, string delimiter, ulong sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo) { if (is64Bit) { activeScriptParse64.ParseScriptText( code, itemName, context, delimiter, sourceContext, startingLineNumber, flags, pVarResult, out excepInfo); } else { activeScriptParse32.ParseScriptText( code, itemName, context, delimiter, (uint)sourceContext, startingLineNumber, flags, pVarResult, out excepInfo); } }
internal void AddScriptlet( string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name, out EXCEPINFO exceptionInfo) { if (asp32 != null) { asp32.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } else { asp64.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } }
public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo) { activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt64(), startingLineNumber, flags, pVarResult, out excepInfo); }
public static T Invoke <T>(object source, InvokeFlags invokeFlags, string name, params object[] args) { if (source == null) { throw new ArgumentNullException("source"); } if (!Enum.IsDefined(typeof(InvokeFlags), invokeFlags)) { throw new ArgumentOutOfRangeException("invokeFlags"); } if (args == null) { throw new ArgumentNullException("args"); } var memoryAllocationsToFree = new List <IntPtr>(); IntPtr rgdispidNamedArgs; int cNamedArgs; if (invokeFlags == InvokeFlags.DISPATCH_PROPERTYPUT) { // There must be at least one argument specified; only one if it is a non-indexed property and // multiple if there are index values as well as the value to set to if (args.Length < 1) { throw new ArgumentException("At least one argument must be specified for DISPATCH_PROPERTYPUT"); } var pdPutID = Marshal.AllocCoTaskMem(sizeof(Int64)); Marshal.WriteInt64(pdPutID, DISPID_PROPERTYPUT); memoryAllocationsToFree.Add(pdPutID); rgdispidNamedArgs = pdPutID; cNamedArgs = 1; } else { rgdispidNamedArgs = IntPtr.Zero; cNamedArgs = 0; } var variantsToClear = new List <IntPtr>(); IntPtr rgvarg; if (args.Length == 0) { rgvarg = IntPtr.Zero; } else { // We need to allocate enough memory to store a variant for each argument (and then populate this // memory) rgvarg = Marshal.AllocCoTaskMem(SizeOfNativeVariant * args.Length); memoryAllocationsToFree.Add(rgvarg); for (var index = 0; index < args.Length; index++) { // Note: The "IDispatch::Invoke method (Automation)" page // (http://msdn.microsoft.com/en-us/library/windows/desktop/ms221479(v=vs.85).aspx) states that // "Arguments are stored in pDispParams->rgvarg in reverse order" so we'll reverse them here var arg = args[(args.Length - 1) - index]; // According to http://stackoverflow.com/a/1866268 it seems like using ToInt64 here will be valid // for both 32 and 64 bit machines. While this may apparently not be the most performant approach, // it should do the job. // Don't think we have to worry about pinning any references when we do this manipulation here // since we are allocating the array in unmanaged memory and so the garbage collector won't be // moving anything around (and GetNativeVariantForObject copies the reference and automatic // pinning will prevent the GC from interfering while this is happening). var pVariant = new IntPtr( rgvarg.ToInt64() + (SizeOfNativeVariant * index) ); Marshal.GetNativeVariantForObject(arg, pVariant); variantsToClear.Add(pVariant); } } var dispParams = new System.Runtime.InteropServices.ComTypes.DISPPARAMS() { cArgs = args.Length, rgvarg = rgvarg, cNamedArgs = cNamedArgs, rgdispidNamedArgs = rgdispidNamedArgs }; try { var dispId = GetDispId(source, name); var IID_NULL = new Guid("00000000-0000-0000-0000-000000000000"); UInt32 pArgErr = 0; object varResult; var excepInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); var hrRet = ((IDispatch)source).Invoke ( dispId, ref IID_NULL, LOCALE_SYSTEM_DEFAULT, (ushort)invokeFlags, ref dispParams, out varResult, ref excepInfo, out pArgErr ); if (hrRet != 0) { var message = "Failing attempting to invoke method with DispId " + dispId + ": "; if ((excepInfo.bstrDescription ?? "").Trim() == "") { message += "Unspecified error"; } else { message += excepInfo.bstrDescription; } var errorType = GetErrorMessageForHResult(hrRet); if (errorType != CommonErrors.Unknown) { message += " [" + errorType.ToString() + "]"; } throw new ArgumentException(message); } return((T)varResult); } finally { foreach (var variantToClear in variantsToClear) { VariantClear(variantToClear); } foreach (var memoryAllocationToFree in memoryAllocationsToFree) { Marshal.FreeCoTaskMem(memoryAllocationToFree); } } }
/// <summary> /// Informs the host that the script has completed execution /// </summary> /// <param name="result">A variable that contains the script result, or null if the script /// produced no result</param> /// <param name="exceptionInfo">Contains exception information generated when the script /// terminated, or null if no exception was generated</param> public virtual void OnScriptTerminate(object result, EXCEPINFO exceptionInfo) { }
public void OnScriptTerminate(IntPtr pVarResult, ref EXCEPINFO excepInfo) { }
public void OnScriptTerminate(IntPtr pVarResult, ref EXCEPINFO excepInfo) { }
public abstract void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags);
public override void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags) { var del = RawCOMHelpers.GetMethodDelegate<RawInterruptScriptThread>(pActiveScript, 14); del(pActiveScript, scriptThreadID, ref excepInfo, flags); }
int IProxyManager.Invoke( UInt32 dispIdMember, IntPtr outerProxy, IntPtr pVarResult, IntPtr pExcepInfo ) { try { ComProxy comProxy = null; Guid riid; if ((dispIdMember == 1)) riid = typeof(IChannelOptions).GUID; else if ((dispIdMember == 2)) riid = typeof(IChannelCredentials).GUID; else return HR.DISP_E_MEMBERNOTFOUND; FindOrCreateProxyInternal(outerProxy, ref riid, out comProxy); TagVariant variant = new TagVariant(); variant.vt = (ushort)VarEnum.VT_DISPATCH; IntPtr tearOffDispatch = IntPtr.Zero; comProxy.QueryInterface(ref riid, out tearOffDispatch); variant.ptr = tearOffDispatch; Marshal.StructureToPtr(variant, pVarResult, true); return HR.S_OK; } catch (Exception e) { if (Fx.IsFatal(e)) throw; if (pExcepInfo != IntPtr.Zero) { System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); e = e.GetBaseException(); exceptionInfo.bstrDescription = e.Message; exceptionInfo.bstrSource = e.Source; exceptionInfo.scode = Marshal.GetHRForException(e); Marshal.StructureToPtr(exceptionInfo, pExcepInfo, false); } return HR.DISP_E_EXCEPTION; } }
public override DispatchResult Invoke( int dispId, uint lcid, DispatchFlags wFlags, object[] args, out ComEXCEPINFO pExcepInfo, out uint puArgErr, out object ret) { pExcepInfo = new ComEXCEPINFO(); puArgErr = 0; DispatchType dispType = (DispatchType)wFlags; switch (dispId) { case DispId_Invoke: if (dispType.IsMethod()) { ret = this.agent.InvokeRemoteDelegate(this.targetId, args); return DispatchResult.Ok; } else if (dispType.IsPropertyGet()) { ret = ToString(); return DispatchResult.Ok; } break; case DispId_ToString: if (dispType.IsMethod()) { ret = ToString(); return DispatchResult.Ok; } else if (dispType.IsPropertyGet()) { // int toStringDispId = this.target.GetMethodId("ToString"); // JsDelegateAdapter adapter = new JsDelegateAdapter(this.target, toStringDispId); // return adapter.IDispatch; ret = null; return DispatchResult.MemberNotFound; } break; case DispId_Apply: Console.WriteLine("Apply"); break; case DispId_Call: Console.WriteLine("Call"); break; default: ret = null; return DispatchResult.MemberNotFound; } ret = null; return DispatchResult.MemberNotFound; }
internal void ParseScriptText( string code, string itemName, [MarshalAs(UnmanagedType.IUnknown)] object context, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, [MarshalAs(UnmanagedType.Struct)] out object result, out EXCEPINFO exceptionInfo) { if (asp32 != null) { asp32.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo); } else { asp64.ParseScriptText(code, itemName, context, delimiter, sourceContextCookie, startingLineNumber, flags, out result, out exceptionInfo); } }
internal void AddScriptlet( string defaultName, string code, string itemName, string subItemName, string eventName, string delimiter, IntPtr sourceContextCookie, uint startingLineNumber, ScriptText flags, out string name, out EXCEPINFO exceptionInfo) { if (asp32 != null) { asp32.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } else { asp64.AddScriptlet(defaultName, code, itemName, subItemName, eventName, delimiter, sourceContextCookie, startingLineNumber, flags, out name, out exceptionInfo); } }
public void OnScriptTerminate(object result, EXCEPINFO exceptionInfo) { }
public abstract void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags);
public override void InterruptScriptThread(uint scriptThreadID, ref EXCEPINFO excepInfo, ScriptInterruptFlags flags) { var del = RawCOMHelpers.GetMethodDelegate <RawInterruptScriptThread>(pActiveScript, 14); del(pActiveScript, scriptThreadID, ref excepInfo, flags); }
public void OnScriptTerminate(ref object result, ref EXCEPINFO info) { }
public abstract void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo);
public int OnScriptTerminate(ref object result, ref System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { return(HResult.S_OK); }
public void OnScriptTerminate(object result, System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { }
int IPseudoDispatch.Invoke( UInt32 dispIdMember, UInt32 cArgs, UInt32 cNamedArgs, IntPtr rgvarg, [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 2)] UInt32[] rgdispidNamedArgs, IntPtr pVarResult, IntPtr pExcepInfo, out UInt32 pArgErr ) { pArgErr = 0; try { if (cNamedArgs > 0) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.NamedArgsNotSupported), HR.DISP_E_BADPARAMCOUNT)); MethodInfo mInfo = null; if (!dispToOperationDescription.TryGetValue(dispIdMember, out mInfo)) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.BadDispID, dispIdMember), HR.DISP_E_MEMBERNOTFOUND)); object[] ins = null; object[] outs = null; string action = null; if (mInfo.paramList.Count != cArgs) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.BadDispID, dispIdMember), HR.DISP_E_BADPARAMCOUNT)); ins = new object[mInfo.opDesc.Messages[0].Body.Parts.Count]; outs = new object[mInfo.opDesc.Messages[1].Body.Parts.Count]; if (cArgs > 0) { if (mInfo.opDesc.Messages[0].Body.Parts.Count > 0) { for (int index = 0; index < mInfo.opDesc.Messages[0].Body.Parts.Count; index++) ins[index] = null; } if (!mInfo.opDesc.IsOneWay && (mInfo.opDesc.Messages[1].Body.Parts.Count > 0)) { for (int index = 0; index < mInfo.opDesc.Messages[1].Body.Parts.Count; index++) outs[index] = null; } } action = mInfo.opDesc.Messages[0].Action; // First we take care of positional arguments int inCount = 0; for (int index = 0; index < cArgs; index++) { if (mInfo.paramList[index].inIndex != -1) { try { object val = null; if (!mInfo.paramList[index].type.IsArray) val = FetchVariant(rgvarg, (int)(cArgs - index - 1), mInfo.paramList[index].type); else val = FetchVariants(rgvarg, (int)(cArgs - index - 1), mInfo.paramList[index].type); ins[mInfo.paramList[index].inIndex] = val; inCount++; } catch (ArgumentNullException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(SR.GetString(SR.VariantArrayNull, cArgs - index - 1)); } } } if (inCount != ins.Length) throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new COMException(SR.GetString(SR.BadParamCount), HR.DISP_E_BADPARAMCOUNT)); object result = null; try { result = SendMessage(mInfo.opDesc, action, ins, outs); } catch (Exception e) { if (Fx.IsFatal(e)) throw; if (pExcepInfo != IntPtr.Zero) { System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); e = e.GetBaseException(); exceptionInfo.bstrDescription = e.Message; exceptionInfo.bstrSource = e.Source; exceptionInfo.scode = Marshal.GetHRForException(e); Marshal.StructureToPtr(exceptionInfo, pExcepInfo, false); } return HR.DISP_E_EXCEPTION; } if (!mInfo.opDesc.IsOneWay) { if (outs != null) { bool[] filled = new bool[outs.Length]; for (UInt32 index = 0; index < filled.Length; index++) filled[index] = false; for (int index = 0; index < cArgs; index++) { if (mInfo.paramList[index].outIndex != -1) { try { if (IsByRef(rgvarg, (int)(cArgs - index - 1))) { PopulateByRef(rgvarg, (int)(cArgs - index - 1), outs[mInfo.paramList[index].outIndex]); } } catch (ArgumentNullException) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(SR.GetString(SR.VariantArrayNull, cArgs - index - 1)); } filled[mInfo.paramList[index].outIndex] = true; } } } if ((result != null) && (pVarResult != IntPtr.Zero)) { if (!result.GetType().IsArray) Marshal.GetNativeVariantForObject(result, pVarResult); else { Array arr = result as Array; Array arrDest = Array.CreateInstance(typeof(object), arr.Length); arr.CopyTo(arrDest, 0); Marshal.GetNativeVariantForObject(arrDest, pVarResult); } } } return HR.S_OK; } catch (Exception e) { if (Fx.IsFatal(e)) throw; e = e.GetBaseException(); return Marshal.GetHRForException(e); } }
public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo) { activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt64(), startingLineNumber, flags, pVarResult, out excepInfo); }
public void OnScriptTerminate(ref object result, ref EXCEPINFO info) { }
public abstract void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo);
void IActiveScriptSite.OnScriptTerminate(object result, EXCEPINFO exceptionInfo) { //Trace.WriteLine("OnScriptTerminate result=" + result); }
internal AutoWebProxyState Compile(Uri engineScriptLocation, string scriptBody, byte[] buffer) { if (closed != 0) { throw new ObjectDisposedException(GetType().Name); } if (jscriptObject != null) { jscript.Close(); } scriptText = null; scriptBytes = null; jscriptObject = new JScriptEngine(); jscript = (IActiveScript) jscriptObject; host = new ScriptHost(); GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::Compile() Binding to ScriptHost#" + ValidationHelper.HashString(this)); jscriptParser = new ActiveScriptParseWrapper(jscriptObject); jscriptParser.InitNew(); jscript.SetScriptSite(host); jscript.SetScriptState(ScriptState.Initialized); // // Inform the script engine that this host implements the IInternetHostSecurityManager interface, which // is used to prevent the script code from using any ActiveX objects. // IObjectSafety objSafety = jscript as IObjectSafety; if (objSafety != null) { Guid guid = Guid.Empty; GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::Compile() Setting up IInternetHostSecurityManager"); objSafety.SetInterfaceSafetyOptions(ref guid, ComConstants.INTERFACE_USES_SECURITY_MANAGER, ComConstants.INTERFACE_USES_SECURITY_MANAGER); objSafety = null; } EXCEPINFO exceptionInfo = new EXCEPINFO(); object result = null; try { jscriptParser.ParseScriptText(scriptBody, null, null, null, IntPtr.Zero, 0, ScriptText.IsPersistent | ScriptText.IsVisible, out result, out exceptionInfo); GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::Compile() ParseScriptText() success:" + ValidationHelper.ToString(exceptionInfo.bstrDescription) + " result:" + ValidationHelper.ToString(result)); } 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) + "::Compile() Script load error:[" + host.ExceptionMessage == null ? "" : host.ExceptionMessage + "]"); throw new COMException(SR.GetString(SR.net_jscript_load, host.ExceptionMessage), comException.ErrorCode); } catch { GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::Compile() Script load error:[Non-CLS Compliant Exception]"); throw; } jscript.AddNamedItem(c_ScriptHelperName, ScriptItem.GlobalMembers | ScriptItem.IsPersistent | ScriptItem.IsVisible); // This part can run global code - time it out if necessary. jscript.GetCurrentScriptThreadID(out interruptThreadId); TimerThread.Timer timer = s_TimerQueue.CreateTimer(s_InterruptCallback, this); activeTimer = timer; try { jscript.SetScriptState(ScriptState.Started); jscript.SetScriptState(ScriptState.Connected); } finally { activeTimer = null; timer.Cancel(); } jscript.GetScriptDispatch(null, out script); GlobalLog.Print("AutoWebProxyScriptWrapper#" + ValidationHelper.HashString(this) + "::Compile() Got IDispatch:" + ValidationHelper.ToString(dispatch)); scriptText = scriptBody; scriptBytes = buffer; return AutoWebProxyState.CompilationSuccess; }
public void OnScriptTerminate(object result, EXCEPINFO exceptionInfo) { GlobalLog.Print("AutoWebProxyScriptWrapper.ScriptHost#" + ValidationHelper.HashString(this) + "::OnScriptTerminate() result:" + ValidationHelper.ToString(result) + " error:" + ValidationHelper.ToString(exceptionInfo.bstrDescription)); }
int IActiveScriptSite.OnScriptTerminate(object result, System.Runtime.InteropServices.ComTypes.EXCEPINFO exceptionInfo) { return(0); }
public virtual DispatchResult Invoke(int id, uint lcid, DispatchFlags flags, object[] args, out System.Runtime.InteropServices.ComTypes.EXCEPINFO pExcepInfo, out uint puArgErr, out object ret) { pExcepInfo = new System.Runtime.InteropServices.ComTypes.EXCEPINFO(); puArgErr = 0; ret = null; return DispatchResult.NotImpl; }