public static string executeScriptInSeparateAppDomain(this string scriptToExecute, bool showLogViewer, bool openScriptGui) { var appDomainName = 12.randomLetters(); var o2AppDomain = new O2AppDomainFactory(appDomainName); /* o2AppDomain.load("O2_XRules_Database"); o2AppDomain.load("O2_Kernel"); o2AppDomain.load("O2_DotNetWrappers"); var o2Proxy = (O2Proxy)o2AppDomain.getProxyObject("O2Proxy"); if (o2Proxy.isNull()) { "in executeScriptInSeparateAppDomain, could not create O2Proxy object".error(); return null; } o2Proxy.InvokeInStaThread = true; if (showLogViewer) o2Proxy.executeScript( "O2Gui.open<Panel>(\"Util - LogViewer\", 400,140).add_LogViewer();"); if (openScriptGui) o2Proxy.executeScript("O2Gui.open<Panel>(\"Script editor\", 700, 300)".line() + " .add_Script(false)".line() + " .onCompileExecuteOnce()".line() + " .Code = \"hello\";".line() + "//O2File:Scripts_ExtensionMethods.cs"); o2Proxy.executeScript(scriptToExecute); PublicDI.log.showMessageBox("Click OK to close the '{0}' AppDomain (and close all open windows)".format(appDomainName)); */ o2AppDomain.unLoadAppDomain(); return scriptToExecute; }
/// <summary> /// This will generate an anonymous appDomain proxy (good for tests but _note that the AppDomain will not be terminated /// </summary> /// <param name="assemblyName"></param> /// <param name="typeToCreateSimpleName"></param> /// <returns></returns> public static object getProxy(string assemblyName, string typeToCreateSimpleName) { string appDomainName = Path.GetFileNameWithoutExtension(DI.config.TempFileNameInTempDirectory) + "_" + typeToCreateSimpleName; // make sure each appDomainName is unique var tempAppDomainFactory = new O2AppDomainFactory(appDomainName); return(tempAppDomainFactory.getProxyObject(typeToCreateSimpleName)); }
//public static object createObject() public static object loadTypeAndExecuteMethodInAppDomain(AppDomain appDomain, string dllWithType, string typeToCreateAndUnwrap, string methodToExecute, object[] methodParameters) { var appDomainHelper = new O2AppDomainFactory(appDomain); object proxyObject = appDomainHelper.createAndUnWrap(dllWithType, typeToCreateAndUnwrap); if (proxyObject == null) DI.log.error("in loadTypeAndExecuteMethodInAppDomain, proxy == null"); /// var proxy = appDomain.CreateInstanceAndUnwrap(dllToLoad, typeToCreateAndUnwrap); //if (proxy == null) // log.error("in loadTypeAndExecuteMethodInAppDomain, proxy == null"); else { MethodInfo methodInfo = DI.reflection.getMethod(proxyObject.GetType(), methodToExecute, methodParameters); if (methodInfo == null) DI.log.error("in loadTypeAndExecuteMethodInAppDomain, methodInfo == null"); else return DI.reflection.invoke(proxyObject, methodInfo, methodParameters); } return null; }
/// <summary> /// This will generate an anonymous appDomain proxy (good for tests but _note that the AppDomain will not be terminated /// </summary> /// <param name="assemblyName"></param> /// <param name="typeToCreateSimpleName"></param> /// <returns></returns> public static object getProxy(string assemblyName, string typeToCreateSimpleName) { string appDomainName = Path.GetFileNameWithoutExtension(DI.config.TempFileNameInTempDirectory) + "_" + typeToCreateSimpleName; // make sure each appDomainName is unique var tempAppDomainFactory = new O2AppDomainFactory(appDomainName); return tempAppDomainFactory.getProxyObject(typeToCreateSimpleName); }