Ejemplo n.º 1
0
        public void Execute()
        {
            var filePaths      = new List <string>();
            var directoryPaths = new List <string>
            {
                Assembly.GetExecutingAssembly().LocalDirectoryPath()
            };

            var resolutionPaths = AppDomainResolutionPaths.WithFilesAndDirectories(
                Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath),
                filePaths,
                directoryPaths);
            Func <string, AppDomainPaths, AppDomain> builder = (name, paths) => AppDomainBuilder.Assemble(name, resolutionPaths);

            var projects = new Mock <ILinkToProjects>();

            using (var host = new ScriptHost(projects.Object, builder))
            {
                var output = string.Empty;
                using (var writer = new ScriptOutputPipe())
                {
                    writer.OnScriptOutput += (s, e) => output += e.Text;
                    var tuple = host.Execute(ScriptLanguage.IronPython, "print \"hello\"", writer);

                    Assert.IsTrue(host.IsExecutingScript);

                    tuple.Item1.Wait();
                    Assert.IsFalse(host.IsExecutingScript);
                    Assert.AreEqual("hello" + Environment.NewLine, output);
                }
            }
        }
Ejemplo n.º 2
0
        private static AppDomainResolutionPaths AppDomainResolutionPathsFor(AppDomainPaths paths)
        {
            List <string> filePaths      = new List <string>();
            List <string> directoryPaths = new List <string>();

            if ((paths & AppDomainPaths.Core) == AppDomainPaths.Core)
            {
                directoryPaths.Add(Assembly.GetExecutingAssembly().LocalDirectoryPath());
            }

            if ((paths & AppDomainPaths.Plugins) == AppDomainPaths.Plugins)
            {
                // Plugins can be found in:
                // - The plugins directory in the main app directory (i.e. <INSTALL_DIRECTORY>\plugins)
                // - In the machine location for plugins (i.e. <COMMON_APPLICATION_DATA>\<COMPANY>\plugins)
                // - In the user location for plugins (i.e. <LOCAL_APPLICATION_DATA>\<COMPANY>\plugins)
                directoryPaths.Add(Path.Combine(Assembly.GetExecutingAssembly().LocalDirectoryPath(), PluginsDirectoryName));
                directoryPaths.Add(Path.Combine(FileConstants.CompanyCommonPath(), PluginsDirectoryName));
                directoryPaths.Add(Path.Combine(FileConstants.CompanyUserPath(), PluginsDirectoryName));
            }

            return(AppDomainResolutionPaths.WithFilesAndDirectories(
                       Path.GetDirectoryName(new Uri(Assembly.GetExecutingAssembly().CodeBase).LocalPath),
                       filePaths,
                       directoryPaths));
        }
        public void RunGuarded()
        {
            // Define the base path for the AppDomain. By default the assembly resolution will look for DLLs here
            var baseDirectory = @"c:\myapplication\plugins";

            // Define any additional files that should be resolved
            var additionalFiles = new[]
            {
                @"c:\myapplication\mylibrary.dll"
            };

            // Define any additional directories from where assemblies should be resolved
            var additionalDirectories = new[]
            {
                @"c:\myapplication\"
            };

            var assemblyResolutionPaths = AppDomainResolutionPaths.WithFilesAndDirectories(
                baseDirectory,
                additionalFiles,
                additionalDirectories);
            var appDomain = AppDomainBuilder.Assemble("MyAppDomain", assemblyResolutionPaths);

            Assert.IsNotNull(appDomain);
        }