Example #1
0
        /// <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 void createAppDomainAndLoadDll_MainTestCase()
        {
            string fullPathToDllToProcess = DI.config.ExecutingAssembly;  //Path.Combine(hardCodedO2DevelopmentLib, o2DllToProcess + ".exe");
            //AppDomainUtils.findDllInCurrentAppDomain(o2DllToProcess);
            Assert.That(File.Exists(fullPathToDllToProcess),
                        "fullPathToDllToProcess doesn't exist:" + fullPathToDllToProcess);

            // get test AppDomain in temp folder
            var o2AppDomainFactory = new O2AppDomainFactory();

            // load dll from it (this will fail until all dependencies are resolved
            Assert.That(o2AppDomainFactory.load(o2DllToProcess, fullPathToDllToProcess, true),
                        "Dll failed to load into AppDomain");

            // get assemblyDependencies 
            Dictionary<string, string> assemblyDependencies =
                new CecilAssemblyDependencies(fullPathToDllToProcess).calculateDependencies();
            DI.log.debug("There are {0} assembly dependencies to load", assemblyDependencies.Count);
            // load them and abort if we were not able to load all)
            Assert.That(o2AppDomainFactory.load(assemblyDependencies).Count == 0,
                        "There were assemblyDependencies that were not loaded");

            // double check that all is OK by dinamcally invoking some methods on the new AppDomain                           
            Assert.That(null != o2AppDomainFactory.invokeMethod("nameOfCurrentDomainStatic O2Proxy O2_Kernel", new object[0]),
                        "Could not invoke methods inside O2_CoreLib");
            o2AppDomainFactory.invokeMethod("logInfo O2Proxy O2_Kernel",
                                            new object[] {"Hello from createAppDomainInTempFolder UnitTest"});

            AppDomainUtils.closeAppDomain(o2AppDomainFactory.appDomain, onTestCompletionDeleteTempFilesCreated);
        }
        public static void executeInAppDomain(string appDomainName, string scriptToExecute)
        {
            O2Thread.mtaThread(
                () => {
                var o2AppDomain = new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);
                try
                {
                    o2AppDomain.load("O2_XRules_Database");
                    o2AppDomain.load("O2_Kernel");
                    o2AppDomain.load("O2_DotNetWrappers");

                    var o2Proxy = (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");

                    o2Proxy.InvokeInStaThread = true;
                    o2Proxy.staticInvocation("O2_External_SharpDevelop", "FastCompiler_ExtensionMethods", "executeSourceCode", new object[] { scriptToExecute });
                }
                catch (Exception ex)
                {
                    ex.log("inside new AppDomain");
                }

                PublicDI.log.showMessageBox("Click OK to close the '{0}' AppDomain (and close all open windows)".format(appDomainName));
                o2AppDomain.unLoadAppDomain();
            });
        }
Example #4
0
        public static string codeStreams_CreateInAppDomain(this Saved_MethodStream savedMethodStream)
        {
            //var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
            var script = "Saved_MethodStream.cs".local();

            "Creating new AppDomain".info();
            var appDomainName = 4.randomString();
            var o2AppDomain   = new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);

            o2AppDomain.load("O2_XRules_Database");
            o2AppDomain.load("O2_Kernel");
            o2AppDomain.load("O2_DotNetWrappers");
            var o2Proxy    = (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");
            var parameters = new object[]
            {
                savedMethodStream.Serialized_Saved_MethodStream_FileCache
//						sourceFolder,
//						resultsFolder,
//						methodFilter,
//						useCachedData,
//						references,
//						numberOfItemsToProcess
            };

            var result = (string)o2Proxy.staticInvocation("O2_External_SharpDevelop", "FastCompiler_ExtensionMethods", "executeFirstMethod", new object[] { script, parameters });

            "Result: {0}".info(result);
            o2AppDomain.sleep(2000);
            o2AppDomain.unLoadAppDomain();
            "AppDomain execution completed, Runing GCCollect".info();
            PublicDI.config.gcCollect();
            "GCCollect completed, returning result data: {0}".info(result);
            return(result);
        }
		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
			MessageBox.Show("Click OK to close the '{0}' AppDomain (and close all open windows)".format(appDomainName));
			o2AppDomain.unLoadAppDomain();
			return scriptToExecute;
		}
        public static string executeEngineOnSeparateAppDomain(string sourceFolder, string resultsFolder, string methodFilter, bool useCachedData, List <string> references, int numberOfItemsToProcess)
        {
            //var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
            var script = "MethodMappings_Engine.cs".local();

            "Creating new AppDomain".info();
            var appDomainName = 4.randomString();
            var o2AppDomain   = new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);

            o2AppDomain.load("O2_XRules_Database");
            o2AppDomain.load("O2_Kernel");
            o2AppDomain.load("O2_DotNetWrappers");
            var o2Proxy    = (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");
            var parameters = new object[]
            {
                sourceFolder,
                resultsFolder,
                methodFilter,
                useCachedData,
                references,
                numberOfItemsToProcess
            };

            var result = (string)o2Proxy.staticInvocation("O2_External_SharpDevelop", "FastCompiler_ExtensionMethods", "executeFirstMethod", new object[] { script, parameters });

            o2AppDomain.unLoadAppDomain();
            "AppDomain execution completed, Runing GCCollect".info();
            PublicDI.config.gcCollect();
            "GCCollect completed, returning result data: {0}".info(result);
            return(result);
        }
        public void Test_AppDomainLoadingAndUnloading()
        {
            List<String> dependentAssemblies = CecilAssemblyDependencies.getListOfDependenciesForType(typeof(StartCSharpScriptGui));
            var appDomainTempDirectory = DI.config.TempFolderInTempDirectory;
            var o2AppDomainFactory = new O2AppDomainFactory("testAppDomain", appDomainTempDirectory, dependentAssemblies);

            //o2AppDomainFactory.unLoadAppDomain();
            o2AppDomainFactory.unLoadAppDomainAndDeleteTempFolder();
        }
Example #8
0
        public void createAppDomainWithPreloadedDlls()
        {
            var appDomainName = "AppDomin with preloaded Dlls";
            var appDomainTempDirectory = DI.config.TempFolderInTempDirectory;
            var assembliesToLoadInNewAppDomain = new List<string> {"O2_Kernel.exe", "O2_DotNetWrappers.dll" };
            var o2AppDomainFactory = new O2AppDomainFactory(appDomainName, appDomainTempDirectory, assembliesToLoadInNewAppDomain);
            Assert.That(o2AppDomainFactory != null, "o2AppDomainFactory was null");
            DI.log.info("AppDomain base directory:{0}", o2AppDomainFactory.BaseDirectory); 
            Assert.That(o2AppDomainFactory.Name == appDomainName, "o2AppDomainFactory.Name != appDomainName");
//            Assert.That(o2AppDomainFactory.AssembliesInBaseDirectory.Count ==2, "There should only be two Assemblies in AppDomain Directory"
            //.createAppDomainWithDlls(newAppDomain, dllToLoadInNewAppDomain);
        }
        public void Test_CreateAppDomainWithO2CoreLibDll()
        {
            const string dynamicCommand_InitialTest = "nameOfCurrentDomain O2Proxy O2_Kernel";
            // get test AppDomain in temp folder
            o2AppDomainFactory =
                CecilAssemblyDependencies.getO2AppDomainFactoryOnTempDirWithAllDependenciesResolved(
                    fullPathToAssemblyToProcess);
            Assert.That(o2AppDomainFactory != null, "o2AppDomainFactory was null");
            // send message to DebugView (will not show in NUnit since this is from a different AppDomain)
            o2AppDomainFactory.invokeMethod("logInfo O2Proxy O2_Kernel",
                                            new object[]
                                                {"Testing appDomain from Test_OpenO2CoreLibFormFromAppDomain UnitTest"});

            //Assert.That(o2AppDomainFactory.load(appDomainProxyDll, fullPathToAppDomainProxyDll, true), "problem loading appDomainProxyDll");            
            // do a quick dynamic invokation to confirm that all is 
            Assert.That(
                o2AppDomainFactory.appDomain.FriendlyName ==
                (string) o2AppDomainFactory.invokeMethod(dynamicCommand_InitialTest),
                "Problem doing dynamic invoke of method nameOfCurrentDomain which returns the current appDomain name");
            DI.log.info("o2AppDomainFactory is created ready for use :)");
        }
Example #10
0
        //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;
        }
        public void createAppDomainAndAllDependencies()
        {
            string fullPathToDllToProcess = Path.Combine(hardCodedO2DevelopmentLib, o2DllToProcess + ".exe");
            // AppDomainUtils.findDllInCurrentAppDomain(o2DllToProcess);
            DI.log.debug("For the dll: {0}", o2DllToProcess);

            Dictionary<string, string> assemblyDependencies =
                new CecilAssemblyDependencies(fullPathToDllToProcess).calculateDependencies();
            DI.log.debug("There are {0} assembly dependencies to load", assemblyDependencies.Count);
            var o2AppDomainFactory = new O2AppDomainFactory();

            Assert.That(o2AppDomainFactory.load(assemblyDependencies).Count == 0,
                        "There were assemblyDependencies that were not loaded");


            DI.log.d("List of loaded Assemblies");
            foreach (string assembly in o2AppDomainFactory.getAssemblies(true))
                DI.log.d("  -  " + assembly);

            AppDomainUtils.closeAppDomain(o2AppDomainFactory.appDomain, onTestCompletionDeleteTempFilesCreated);
        }
 public void Test_AppdomainsWithUniqueBaseDirectories()
 {
     string pathToproxyDll = DI.config.ExecutingAssembly; // Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".exe");            
     string appDomain1TempDir = copyO2ProxyToTempFolder(pathToproxyDll, "appDomain1TempDir");
     string appDomain2TempDir = copyO2ProxyToTempFolder(pathToproxyDll, "appDomain2TempDir");
     Assert.That(
         Directory.Exists(appDomain1TempDir) && Directory.Exists(appDomain2TempDir) &&
         appDomain1TempDir != appDomain2TempDir, "Something is wrong with temp dirs");
     var appDomain1 = new O2AppDomainFactory("appDomain1", appDomain1TempDir);
     var appDomain2 = new O2AppDomainFactory("appDomain2", appDomain2TempDir);
     Assert.That(appDomain1.BaseDirectory != appDomain2.BaseDirectory,
                 "Something is wrong with AppDomain's temp dirs");
     object appDomain1invocationResult =
         appDomain1.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);
     object appDomain2invocationResult =
         appDomain2.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);
     Assert.That(appDomain1invocationResult != null && appDomain2invocationResult != null,
                 "appDomainXinvocationResult == null");
     DI.log.info("{0} != {1}", appDomain1invocationResult, appDomain2invocationResult);
     Assert.That(appDomain1invocationResult != appDomain2invocationResult,
                 "appDomainXinvocationResult were not different");
 }
		public static O2AppDomainFactory openO2ReplInClojureFolder(this API_Clojure apiClojure, bool openScriptInEditor_InsteadOfExecutingIt)
		{			
			var defaultAssemblies = new List<string>() 
				{ 
					"FluentSharp.CoreLib.dll".assembly_Location(), 
					"FluentSharp.BCL.dll".assembly_Location(), 
					"FluentSharp.REPL.exe".assembly_Location(),
					"O2_Platform_External_SharpDevelop.dll".assembly_Location()};

			var name = "Clojure".add_RandomLetters(4);
			var baseFolder = apiClojure.RootFolder;
			//var o2ScriptsFolder = apiClojure.RootFolder.append("O2");
			var o2ScriptsFolder = apiClojure.RootFolder;
			var clojureExe = apiClojure.ClojureExe;
			if (baseFolder.dirExists().isFalse())
			{
				"in openO2ReplInClojureFolder, provided base folder didn't exist: {0}".error(baseFolder);
				apiClojure.script_Me();
				return null;
			}
			"Clojure-icon.png".local().file_Copy(o2ScriptsFolder);
			"Launch Clojure REPL.h2".local().file_Copy(o2ScriptsFolder);
			"API_Clojure.cs".local().file_Copy(o2ScriptsFolder);
			
			"[openO2ReplInClojureFolder] creating AppDomain on folder {0}".info(baseFolder);
			var o2AppDomain = new O2AppDomainFactory(name, baseFolder, defaultAssemblies);
					
			var scriptToExecute = "Launch Clojure REPL.h2".local().fileContents();		
			//"Script to execute: {0}".info(scriptToExecute);
			var script_Base64Encoded = scriptToExecute.base64Encode();
			if (openScriptInEditor_InsteadOfExecutingIt)
				scriptToExecute = "open.scriptEditor().inspector.set_Script(\"{0}\".base64Decode()).waitForClose();".line().format(script_Base64Encoded);
			
			o2AppDomain.executeScriptInAppDomain(scriptToExecute, false, false);  
			return o2AppDomain;
		}
    public static O2AppDomainFactory getO2AppDomainFactoryOnTempDirWithAllDependenciesResolved(
        string fullPathToDllToProcess)
    {
        var o2AppDomainFactory = new O2AppDomainFactory();
        if (false ==
            o2AppDomainFactory.load(Path.GetFileNameWithoutExtension(fullPathToDllToProcess), fullPathToDllToProcess,
                                    true))
            return null;
        Dictionary<string, string> assemblyDependencies =
            new CecilAssemblyDependencies(fullPathToDllToProcess).calculateDependencies();
 
        if (o2AppDomainFactory.load(assemblyDependencies).Count == 0)
            return o2AppDomainFactory;
        PublicDI.log.error(
            "in getO2AppDomainFactoryOnTempDirWithAllDependenciesResolved, there were assemblyDependencies that were not loaded, for: " +
            fullPathToDllToProcess);
        return null;
    }
Example #15
0
        public static string executeEngineOnSeparateAppDomain(string sourceFolder, string resultsFolder, string methodFilter, bool useCachedData, List<string> references, int numberOfItemsToProcess)
        {
        	//var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
        	var script = "MethodMappings_Engine.cs".local();
        	"Creating new AppDomain".info();
 			var appDomainName = 4.randomString();
			var o2AppDomain =  new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);			
			o2AppDomain.load("O2_XRules_Database"); 	
			o2AppDomain.load("O2_Kernel");
			o2AppDomain.load("O2_DotNetWrappers");
			var o2Proxy =  (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");
			var parameters = new object[]
					{ 
						sourceFolder,
						resultsFolder,
						methodFilter,
						useCachedData,
						references,
						numberOfItemsToProcess                        
					};					

    	    var result =(string)o2Proxy.staticInvocation("O2_External_SharpDevelop","FastCompiler_ExtensionMethods","executeFirstMethod",new object[]{script, parameters});	
    	    o2AppDomain.unLoadAppDomain(); 
    	    "AppDomain execution completed, Runing GCCollect".info();
    	    PublicDI.config.gcCollect();
        	"GCCollect completed, returning result data: {0}".info(result);
        	return result;
        }
		public static string codeStreams_CreateInAppDomain(this Saved_MethodStream savedMethodStream)
	    {
	    	//var script = @"C:\O2\_XRules_Local\Ast_Test.cs";
	    	var script = "Saved_MethodStream.cs".local();
	    	"Creating new AppDomain".info();
			var appDomainName = 4.randomString();
			var o2AppDomain =  new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);			
			o2AppDomain.load("FluentSharp.CoreLib.dll"); 						
			var o2Proxy =  (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");
			var parameters = new object[]
					{ 
						savedMethodStream.Serialized_Saved_MethodStream_FileCache
//						sourceFolder,
//						resultsFolder,
//						methodFilter,
//						useCachedData,
//						references,
//						numberOfItemsToProcess                        
					};					
	
		    var result =(string)o2Proxy.staticInvocation("O2_External_SharpDevelop","FastCompiler_ExtensionMethods","executeFirstMethod",new object[]{script, parameters});	
		    "Result: {0}".info(result);
		    o2AppDomain.sleep(2000);
		    o2AppDomain.unLoadAppDomain(); 
		    "AppDomain execution completed, Runing GCCollect".info();
		    PublicDI.config.gcCollect();
	    	"GCCollect completed, returning result data: {0}".info(result);
	    	return result;
	    }				
        public void Test_PropertiesAndMethodsWithParameters()
        {
            var propertyValue = "value";
            var intvalue = 2009;
            var appDomain = new O2AppDomainFactory("testAppDomain", AppDomain.CurrentDomain.BaseDirectory);
            appDomain.load(assemblyName);

            // invoke using direct cast
            var proxy = (O2Proxy) appDomain.getProxyObject(typeToCreateSimpleName);
            Assert.That(proxy != null, "proxy was null");
            proxy.Property = propertyValue;
            Assert.That(proxy.Property == propertyValue, "proxy.Property != propertyValue");
            Assert.That(proxy.returnConcatParamData(proxy.Property, intvalue) == proxy.Property + intvalue,
                        "error in returnConcatParamData");

            // invoke using O2AppDomainFactory methods

            Assert.Ignore(
                "todo: invoke using O2AppDomainFactory methods (need to implement Set and Get wrapper methods)");
        }
        public void Test_LoadingCodeIntoMultipleAppDomains()
        {
            // test current AppDomain            
            string pathToproxyDll = DI.config.ExecutingAssembly; // Path.Combine(AppDomain.CurrentDomain.BaseDirectory, assemblyName + ".exe");
            string testAppDomainDirectory = copyO2ProxyToTempFolder(pathToproxyDll, assemblyName);

            object resultInCurrentAppDomain = LoadTypes.loadTypeAndExecuteMethodInAppDomain(AppDomain.CurrentDomain,
                                                                                            assemblyName, typeToCreate,
                                                                                            methodToInvoke, methodParams);
            Assert.IsNotNull(resultInCurrentAppDomain, "result");
            DI.log.debug("{0} = {1}", "resultIncurrentAppDomain", resultInCurrentAppDomain);

            // test creating new AppDomain
            var newAppDomain = new O2AppDomainFactory("newAppDomain", testAppDomainDirectory);
            Assert.IsNotNull(newAppDomain, "newAppDomain");
            newAppDomain.load(assemblyName);
            object resultInNewAppDomain = LoadTypes.loadTypeAndExecuteMethodInAppDomain(newAppDomain.appDomain,
                                                                                        assemblyName, typeToCreate,
                                                                                        methodToInvoke, methodParams);
            Assert.IsNotNull(resultInNewAppDomain, "result");
            DI.log.debug("{0} = {1}", "resultInNewAppDomain", resultInNewAppDomain);
            Assert.That(resultInCurrentAppDomain != resultInNewAppDomain,
                        "resultIncurrentAppDomain == resultInNewAppDomain");

            // test creating new AppDomain just using the O2AppDomainFactory
            var appDomainFactory = new O2AppDomainFactory("appDomainFactory", testAppDomainDirectory);
            appDomainFactory.load(assemblyName);
            List<string> loadedAssemblies = appDomainFactory.getAssemblies(false);
            Assert.That(loadedAssemblies.Count > 0 && loadedAssemblies.Contains(assemblyName),
                        "Loaded assembly was not there");
            object proxyObject = appDomainFactory.getProxyObject((typeToCreate));
            Assert.IsNotNull(proxyObject, "proxyObject was null");
            object resultInAppDomainFactory = appDomainFactory.invoke(proxyObject, methodToInvoke, methodParams);
            DI.log.debug("{0} = {1}", "resultInAppDomainFactory", resultInAppDomainFactory);
            Assert.That(
                (resultInCurrentAppDomain != resultInAppDomainFactory) &&
                (resultInNewAppDomain != resultInAppDomainFactory), "All results should be different");

            // test creating objects using the format {type} {assembly}
            var appDomainFactory2 = new O2AppDomainFactory("appDomainFactory2", testAppDomainDirectory);
            appDomainFactory.load(assemblyName);
            object proxyObject2 = appDomainFactory2.getProxyObject(typeToCreate + " " + assemblyName);
            Assert.IsNotNull(proxyObject2, "proxyObject2 was null");
            DI.log.debug("{0} = {1}", "appDomainFactory2", appDomainFactory.invoke(proxyObject2, methodToInvoke));

            // test if we can get a MethodInfo using using the format {method} {type} {assembly}
            var appDomainFactory3 = new O2AppDomainFactory("appDomainFactory3", testAppDomainDirectory);
            appDomainFactory.load(assemblyName);
            var methodInfoFromappDomainFactory3 =
                (MethodInfo) appDomainFactory3.getProxyMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);
            Assert.That(methodInfoFromappDomainFactory3 != null, "methodInfoFromappDomainFactory3 was null");
            DI.log.debug("{0} MethodInfo = {1}", "from appDomainFactory3", methodInfoFromappDomainFactory3.ToString());
            // we can't invoke this guy because we don't have the proxy

            // test if we can invoke a MethodInfo using using the format {method} {type} {assembly}
            var appDomainFactory4 = new O2AppDomainFactory("appDomainFactory4", testAppDomainDirectory);
            appDomainFactory.load(assemblyName);
            object invocationResult4 =
                appDomainFactory4.invokeMethod(methodToInvoke + " " + typeToCreate + " " + assemblyName);
            Assert.That(invocationResult4 != null, "invocationResult4 was null");
            DI.log.debug("[{0}] {1} {2} {3} = {4}", "from appDomainFactory4", assemblyName, typeToCreate, methodToInvoke,
                         invocationResult4); // we can't invoke this guy because we don't have the proxy
        }
Example #19
0
 /// <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 void executeInAppDomain(string appDomainName,string scriptToExecute)
		{
				O2Thread.mtaThread(
					()=>{
							var o2AppDomain =  new O2.Kernel.Objects.O2AppDomainFactory(appDomainName);
							try
							{
								o2AppDomain.load("O2_XRules_Database"); 	
								o2AppDomain.load("O2_Kernel");
								o2AppDomain.load("O2_DotNetWrappers");
							
								var o2Proxy =  (O2Proxy)o2AppDomain.getProxyObject("O2Proxy");
								 
								o2Proxy.InvokeInStaThread = true;
								o2Proxy.staticInvocation("O2_External_SharpDevelop","FastCompiler_ExtensionMethods","executeSourceCode",new object[]{ scriptToExecute });								
							}
							catch(Exception ex)
							{
								ex.log("inside new AppDomain"); 
							}
							
							DebugMsg.showMessageBox("Click OK to close the '{0}' AppDomain (and close all open windows)".format(appDomainName));							
							o2AppDomain.unLoadAppDomain();
						});
		  }