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 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 O2AppDomainFactory(appDomainName);

            o2AppDomain.appDomain().load("FluentSharp.CoreLib.dll");
            var o2Proxy    = (O2Proxy)(o2AppDomain.appDomain().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.appDomain().unLoadAppDomain();
            "AppDomain execution completed, Runing GCCollect".info();
            PublicDI.config.gcCollect();
            "GCCollect completed, returning result data: {0}".info(result);
            return(result);
        }
        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);
        }
Example #4
0
        public static O2AppDomainFactory        createAppDomain(this string appDomainName)
        {
            var o2AppDomainFactory = new O2AppDomainFactory(appDomainName);

            o2AppDomainFactory.appDomain().loadMainO2Dlls();
            return(o2AppDomainFactory);
        }
        public static void executeInAppDomain(string appDomainName, string scriptToExecute)
        {
            O2Thread.mtaThread(
                () => {
                var o2AppDomain = new 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();
            });
        }
        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);
        }
Example #7
0
 public static Control loadControl(this O2AppDomainFactory o2AppDomainFactory, Type ascxControlToLoad,
                                   bool showAsFloat, String name)
 {
     return((Control)o2AppDomainFactory.proxyInvokeStatic(
                "O2_CoreLib", "O2DockPanel", "loadControl",
                new object[] { ascxControlToLoad, showAsFloat, name }));
 }
        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 O2AppDomainFactory(appDomainName);

            //o2AppDomain.load("O2_XRules_Database");
            //o2AppDomain.load("O2_Kernel");
            //o2AppDomain.load("O2_DotNetWrappers");
            o2AppDomain.load("FluentSharp.CoreLib");
            o2AppDomain.load("FluentSharp.WinForms");
            o2AppDomain.load("FluentSharp.REPL");
            o2AppDomain.load("FluentSharp.SharpDevelopEditor.dll");
            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);
        }
Example #9
0
        public static Form openO2Gui(this O2AppDomainFactory o2AppDomainFactory)
        {
            var o2Gui = (Form)o2AppDomainFactory.proxyInvokeInstance("O2_CoreLib", "O2GuiWithDockPanel", "");

            O2Kernel_O2Thread.staThread(() => o2Gui.ShowDialog());
            return(o2Gui);
        }
        public void launchO2AscxGui()
        {
            O2AppDomainFactory.create(appDomainName); // move this here so that we can execute this test from O2


            Assert.That(PublicDI.appDomainsControledByO2Kernel.ContainsKey(appDomainName), "Cound not find appDomainName:{0}", appDomainName);
            var o2AppDomainFactory = PublicDI.appDomainsControledByO2Kernel[appDomainName];

            Assert.That(o2AppDomainFactory.Name == appDomainName, "o2AppDomainFactory.Name != appDomainName");
            PublicDI.log.info("Created appDomain Name: {0}", o2AppDomainFactory.Name);
            // StringsAndLists.showListContents(o2AppDomainFactory.FilesInAppDomainBaseDirectory);

            var o2AscxGuiForm = o2AppDomainFactory.getProxyObject("O2AscxGUI O2_External_WinFormsUI");

            Assert.That(o2AscxGuiForm != null, "o2AscxGuiForm object was null");
            var lauchResult = o2AppDomainFactory.invoke(o2AscxGuiForm, "launch");

            Assert.That(lauchResult != null && lauchResult is bool && (bool)lauchResult, "prob with lauchResult");
            o2AppDomainFactory.invoke(o2AscxGuiForm, "logDebug", new object[] { "message from Unit Test" });


            Processes.Sleep(2000);
            var closeResult = o2AppDomainFactory.invoke(o2AscxGuiForm, "close");

            Assert.That(closeResult != null && closeResult is bool && (bool)closeResult, "prob with closeResult");
            //DI.log.info("type : {0}", o2AscxGuiForm.GetType().FullName);

            //appDomainName
        }
        //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 static DialogResult showMessageBox(this O2AppDomainFactory o2AppDomainFactory, string message,
                                           string messageBoxTitle, MessageBoxButtons messageBoxButtons)
 {
     return((DialogResult)o2AppDomainFactory.proxyInvokeStatic("O2_Kernel", "O2Proxy", "showMessageBox",
                                                               new object[]
                                                               { message, messageBoxTitle, messageBoxButtons }));
 }
Example #13
0
        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");
        }
Example #14
0
        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 #15
0
 public static void springExec(this O2AppDomainFactory o2AppDomainFactory, string springFileToLoad)
 {
     O2Kernel_O2Thread.staThread(() =>
                                 o2AppDomainFactory.proxyInvokeStatic("O2_CoreLib", "SpringExec",
                                                                      "loadConfigAndStartGUI",
                                                                      new object[] { springFileToLoad })
                                 );
     //O2Kernel_Lambda.runLambdaOnNewSTAThread(() =>
     //    );
 }
        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);
        }
Example #17
0
        public void test_InstanceInvocation()
        {
            // test by invoking itseft
            object proxy = O2AppDomainFactory.getProxy(assemblyName, typeToCreateSimpleName + " " + assemblyName);

            Assert.That(proxy != null, "proxy was null");
            // test via direct cast
            var    simpleAppDomainProxy      = (O2Proxy)proxy;
            string resultUsingDirectCall     = simpleAppDomainProxy.nameOfCurrentDomain();
            var    resultUsingReflectionCall =
                (string)simpleAppDomainProxy.instanceInvocation("O2Proxy", "nameOfCurrentDomainStatic", new object[0]);

            Assert.That(resultUsingDirectCall != null && resultUsingReflectionCall != "",
                        "direct cast : result values were null ");
            DI.log.info("{0} == {1}", resultUsingDirectCall, resultUsingReflectionCall);
            Assert.That(resultUsingDirectCall == resultUsingReflectionCall, "direct cast : return values are not equal");
        }
        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);
        }
Example #19
0
        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)");
        }
Example #20
0
        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 #21
0
        public static O2Proxy                           executeScriptInAppDomain(this O2AppDomainFactory o2AppDomain, string scriptToExecute, bool showLogViewer, bool openScriptGui)
        {
            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("open.logViewer();");
            }
            if (openScriptGui)
            {
                o2Proxy.executeScript("open.scriptEditor().inspector.set_Script(\"return 42;\");");
            }

            o2Proxy.executeScript(scriptToExecute);
            return(o2Proxy);
        }
        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);
        }
 public static DialogResult showMessageBox(this O2AppDomainFactory o2AppDomainFactory, string message)
 {
     return(showMessageBox(o2AppDomainFactory, message, "Message from O2 AppDomain Central", MessageBoxButtons.OK));
 }
 public static void logError(this O2AppDomainFactory o2AppDomainFactory, string errorMessage)
 {
     o2AppDomainFactory.proxyInvokeStatic("O2_Kernel", "O2Proxy", "logError", new object[] { errorMessage });
 }
 public static void logDebug(this O2AppDomainFactory o2AppDomainFactory, string debugMessage)
 {
     o2AppDomainFactory.proxyInvokeStatic("O2_Kernel", "O2Proxy", "logDebug", new object[] { debugMessage });
 }
 public static void logInfo(this O2AppDomainFactory o2AppDomainFactory, string infoMessage)
 {
     o2AppDomainFactory.proxyInvokeStatic("O2_Kernel", "O2Proxy", "logInfo", new object[] { infoMessage });
 }
Example #27
0
        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 #28
0
 public static AppDomain                 appDomain(this O2AppDomainFactory appDomainFactory)
 {
     return(appDomainFactory.notNull() ? appDomainFactory.AppDomain : null);
 }
Example #29
0
        public static O2AppDomainFactory        appDomain_New(this string appDomainName)
        {
            var appDomain = new O2AppDomainFactory(appDomainName);

            return(appDomain);
        }
Example #30
0
 public static void closeO2Gui(this O2AppDomainFactory o2AppDomainFactory)
 {
     o2AppDomainFactory.proxyInvokeStatic("O2_CoreLib", "O2GuiWithDockPanel", "CloseThisForm");
 }