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 void compileTestFileAndCheckIfAllIsStillThere()
        {
            if (false == compiledAssemblySettings.dontCompileIfFileExists ||
                false == File.Exists(compiledAssemblySettings.pathToCreatedAssemblyFile))
            {
                Assembly compiledExeFile = new CompileEngine().compileSourceCode(compiledAssemblySettings.sourceCode,
                                                                                 compiledAssemblySettings.exeMainClass,
                                                                                 compiledAssemblySettings.outputAssemblyName);
                // copy all dependentDlls to current directly (so that we can load this exe)

                Assert.That(compiledExeFile != null, "in MockObjects_CompiledExe.compileTestFileAndCheckIfAllIsStillThere Compiled Assembly was null");
                CecilAssemblyDependencies.copyAssemblyDependenciesToAssemblyDirectory(compiledExeFile.Location,
                                                                                      new List <string>
                {
                    DI.config.
                    hardCodedO2LocalBuildDir
                });

                Assert.That(compiledExeFile != null, "Compilation failed");
                Assert.That(File.Exists(compiledExeFile.Location), "Could not find assembly on disk!");
                DI.log.info("test Assembly file compiled into: {0}", compiledExeFile);
                compiledAssemblySettings.pathToCreatedAssemblyFile = compiledExeFile.Location;
                Assert.That(compiledAssemblySettings.checkIfAssemblyWasCreatedOK(), "Created assembly was not OK");
            }
        }
Пример #3
0
        public void test_ExeCreation_manual()
        {
            var targetMethod = DI.reflection.getMethod(typeof(TestClass), "TestMethod", null);

            Assert.That(targetMethod != null, "targetMethod was null");

            var standAloneExe = StandAloneExe.createMainPointingToMethodInfo(targetMethod);

            Assert.That(File.Exists(standAloneExe), "standAloneExe file didn't exist: " + standAloneExe);

            var createdDirectory = CecilAssemblyDependencies.populateDirectoryWithAllDependenciesOfAssembly(standAloneExe);

            Assert.That(Directory.Exists(createdDirectory), "createdDirectory didn't exist");
            var exeInCreatedDirectory = Path.Combine(createdDirectory, Path.GetFileName(standAloneExe));

            Assert.That(File.Exists(exeInCreatedDirectory), "exeInCreatedDirectory diddnt exit");

            var newDirectoryName = DI.config.getTempFolderInTempDirectory(targetMethod.Name);

            Files.copyFilesFromDirectoryToDirectory(createdDirectory, newDirectoryName);
            Files.deleteFolder(createdDirectory);

            var exeInFinalDirectory = Path.Combine(newDirectoryName, Path.GetFileName(standAloneExe));
            var pdbFile             = IL.createPdb(exeInFinalDirectory, false);

            Assert.That(File.Exists(pdbFile), "pdbFile was not created");

            DI.log.info("New exe and pdb are on directory {0}", newDirectoryName);
        }
        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);
        }
Пример #5
0
        public void loadCSharpScriptsGuiOnSeparateAppDomainUsingWCF_ManualWay()
        {
            // create Wcf Host
            var wcfHostName = "loadCSharpScriptsGui";
            var wcfHost     = O2WcfUtils.createWcfHostAndStartIt(wcfHostName);
            IO2WcfKernelMessage o2WcfClientProxy = wcfHost.getClientProxy();

            Assert.That(o2WcfClientProxy.allOK(), "o2WcfProxy was not OK");

            // create separateAppDomain
            var testAppDomain    = "AppDomainWithCSharpScripts";
            var targetAssemblies = new List <string> {
                typeof(StartCSharpScriptGui).Assembly.Location
            };
            var directoryWithSourceAssemblies = DI.config.hardCodedO2LocalBuildDir;
            var dependentAssemblies           = new CecilAssemblyDependencies(targetAssemblies, new List <string> {
                directoryWithSourceAssemblies
            }).calculateDependencies();

            o2WcfClientProxy.createAppDomainWithDlls(testAppDomain, new List <string>(dependentAssemblies.Values));

            // will just open an empty O2 Gui
            //o2WcfClientProxy.invokeOnAppDomainObject(testAppDomain, "O2AscxGUI", "launch",null);

            // open the CSharpScripts O2 Module by simulating the Main execution invocation
            o2WcfClientProxy.invokeOnAppDomainObject(testAppDomain, typeof(StartCSharpScriptGui).FullName, "Main", new object[0]);

            o2WcfClientProxy.invokeOnAppDomainObject(testAppDomain, "O2AscxGUI", "logInfo", new[] { "Hello from Unit test" });
            //   Processes.Sleep(2000);
            o2WcfClientProxy.invokeOnAppDomainObject(testAppDomain, "O2AscxGUI", "close", null);
            //  o2WcfClientProxy.invokeOnAppDomainObject(testAppDomain);
            //O2WcfUtils.
            wcfHost.stopHost();
        }
Пример #6
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();
        }
 public void showDependenciesForFile(string fileToProcess)
 {
     clearDependenciesOnViewControls();
     if (File.Exists(fileToProcess))
     {
         var cecilDependencies = new CecilAssemblyDependencies(fileToProcess);
         var dependencies      = cecilDependencies.calculateDependencies();
         updateDependenciesFlatList(dependencies);
     }
 }
Пример #8
0
        private static string populateDirectoryWithAllDependencies(List <String> compiledXRulesFiles, O2Thread.FuncVoid onStepEvent)
        {
            var targetDirectory = XRules_Config.PathTo_XRulesCompiledDlls;

            Files.deleteFilesFromDirThatMatchPattern(targetDirectory, "*.dll");
            foreach (var compiledFile in compiledXRulesFiles)
            {
                CecilAssemblyDependencies.populateDirectoryWithAllDependenciesOfAssembly(targetDirectory, compiledFile,
                                                                                         null);
                onStepEvent();
            }
            return(targetDirectory);
        }
Пример #9
0
        public void showAssemblyDependencies()
        {
            var assemblyToProcess = @"E:\O2\_Bin_(O2_Binaries)\_O2_Scanner_DotNet.exe";
            var dependencies      = CecilAssemblyDependencies.getListOfDependenciesForAssemblies(new List <string>()
            {
                assemblyToProcess
            });

            // DC: weird but in one of my dev boxes the code below doesn't compile :(
            //var dependencies2 = CecilAssemblyDependencies.getListOfDependenciesForAssembly(assemblyToProcess);
            foreach (var dependency in dependencies)
            {
                log.write(@"//O2Tag_AddReferenceFile:{0}", dependency);
            }
        }
        public static bool arePostSharpDllsAddedAsReferences(string pathToAssembly)
        {
            var dependencies = CecilAssemblyDependencies.getListOfDependenciesForAssemblies(new List <string> {
                pathToAssembly
            });

            foreach (var dependency in dependencies)
            {
                if (dependency == "PostSharp.Public")//if (Path.GetFileName(dependency) == "PostSharp.Laos.dll")
                {
                    return(true);
                }
            }
            return(false);
        }
        public void findAllDependenciesForDll()
        {
            string fullPathToDllToProcess = DI.config.ExecutingAssembly; //Path.Combine(hardCodedO2DevelopmentLib, o2DllToProcess + ".exe");
            // AppDomainUtils.findDllInCurrentAppDomain(o2DllToProcess);
            var cecilAssemblyDependencies = new CecilAssemblyDependencies(fullPathToDllToProcess);
            Dictionary <string, string> assemblyDependencies = cecilAssemblyDependencies.calculateDependencies();

            Assert.That(assemblyDependencies != null && assemblyDependencies.Count > 0,
                        " problem calculating assemblyDependencies");

            DI.log.debug("There are {0} assembly dependencies to resolve", assemblyDependencies.Count);
            foreach (string assemblyToResolve in assemblyDependencies.Keys)
            {
                DI.log.info("{0} : {1}", assemblyDependencies[assemblyToResolve], assemblyToResolve);
            }
        }
        public static bool doesAssemblyReferenceNUnit(string file)
        {
            var fileExtension = Path.GetExtension(file);

            if (fileExtension == ".dll" || fileExtension == ".exe")
            {
                if (CecilUtils.isDotNetAssembly(file))
                {
                    //DI.log.info("file: {0}", file);
                    var dependencies = CecilAssemblyDependencies.getDictionaryOfDependenciesForAssembly_WithNoRecursiveSearch(file);
                    foreach (var dependency in dependencies.Values)
                    {
                        //  DI.log.debug("   d: {0}", dependency);
                        if (dependency == nUnit_ReferenceDll)
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Пример #13
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 :)");
        }
        public void test_openCirDataControlOnSeparateAppDomainViaWcf()
        {
            // First we need to figure out which DLL has the type we need
            var targetAssemblies = new List <string> {
                typeof(ascx_CirAnalysis).Assembly.Location, typeof(O2AscxGUI).Assembly.Location
            };
            //Assert.That(File.Exists(targetAssembly), "could not find assembly: " + targetAssembly);

            var dependentAssemblies = new CecilAssemblyDependencies(targetAssemblies, new List <string> {
                DI.config.hardCodedO2LocalBuildDir
            }).calculateDependencies();

            Assert.That(dependentAssemblies.Count > 0, "There we no dependencies calculated");
            DI.log.info("There are {0} dependent assemblies", dependentAssemblies.Count);
            // StringsAndLists.showListContents(dependentAssemblies);  // uncoment to see list of dlls
            var wcfHost = O2WcfUtils.createWcfHostForThisO2KernelProcess();
            IO2WcfKernelMessage o2WcfProxy = O2WcfUtils.getClientProxyForThisO2KernelProcess();

            runTestsViaWcfProxy(o2WcfProxy);
            // now that all tests are completed close host
            wcfHost.stopHost();
        }
        public void runTestsViaWcfProxy(IO2WcfKernelMessage o2WcfProxy)
        {
            // first thing to do is to create a new AppDomain that has all the required dlls for the two main types we want to load ascx_CirAnalysis and O2AscxGUI
            var testAppDomain    = "AppDomainWithCirData";
            var targetAssemblies = new List <string> {
                typeof(ascx_CirAnalysis).Assembly.Location, typeof(O2AscxGUI).Assembly.Location
            };
            var dependentAssemblies = new CecilAssemblyDependencies(targetAssemblies, new List <string> {
                DI.config.hardCodedO2LocalBuildDir
            }).calculateDependencies();

            o2WcfProxy.createAppDomainWithDlls(testAppDomain, new List <string>(dependentAssemblies.Values));

            // remote O2 Kernel is all set, now let's open the ascx_CirAnalyis control
            var ascxControlName = "Cir Analysis";

            o2WcfProxy.invokeOnAppDomainObject(testAppDomain, typeof(O2AscxGUI).FullName, "openAscxAsForm", new object[] { typeof(ascx_CirAnalysis).FullName, ascxControlName });

            // make sure it is there
            Assert.That((bool)o2WcfProxy.invokeOnAppDomainObject(testAppDomain, typeof(O2AscxGUI).FullName, "isAscxLoaded", new object[] { ascxControlName }), "isAscxLoaded should be true here");
            Assert.That(false == (bool)o2WcfProxy.invokeOnAppDomainObject(testAppDomain, typeof(O2AscxGUI).FullName, "isAscxLoaded", new object[] { "dummyControlName" }), "isAscxLoaded should be false here");

            // now load some CirData into it
            o2WcfProxy.O2Messages("executeOnAscxSync", new object[] { ascxControlName, "loadO2CirDataFile", new [] { DI.config.ExecutingAssembly } });

            // and retrive the data as string lists
            var cirClasses   = o2WcfProxy.getStringListFromAscxControl(ascxControlName, "getClasses", new string[0]);
            var cirFunctions = o2WcfProxy.getStringListFromAscxControl(ascxControlName, "getFunctions", new string[0]);

            Assert.That(cirClasses.Count > 0 && cirFunctions.Count > 0, "There were no classes or functions returned in cirClasses");
            DI.log.info("There were {0} classes returned", cirClasses.Count);
            DI.log.info("There were {0} functions returned", cirFunctions.Count);

            // close the control and its parant form
            o2WcfProxy.invokeOnAppDomainObject(testAppDomain, typeof(O2AscxGUI).FullName, "closeAscxParent", new object[] { ascxControlName });
        }
        public static void createAppDomainViaWcfClient(O2WcfClient wcfClient, List <Type> typesToLoadWithAllDependencies)
        {
            List <String> dependentAssemblies = CecilAssemblyDependencies.getListOfDependenciesForTypes(typesToLoadWithAllDependencies);

            wcfClient.createRemoteAppDomainWithAssemblies(wcfClient.RemoteAppDomainName, new List <string>(dependentAssemblies));
        }
Пример #17
0
 public void makeSureAllDependentAssembliesExistInTempDirectory(string targetAssembly)
 {
     CecilAssemblyDependencies.copyAssemblyDependenciesToAssemblyDirectory(targetAssembly);
 }