コード例 #1
0
        public ScriptServices Build(IRepl repl)
        {
            //TODO: this need to be wired up properly using our own IoC container from caliburn.

            var underlyingLogger = LogManager.GetCurrentClassLogger();
            var replLogger = new ReplLogger(LogLevel.Info, repl, underlyingLogger);
            ILog logger = replLogger;

            var fileSystem = new FileSystem();
            var engine = new RoslynScriptEngine(new ReplScriptHostFactory(), logger);
            var filePreProcessor = new FilePreProcessor(fileSystem, logger, new ILineProcessor[] {new LoadLineProcessor(fileSystem), new ReferenceLineProcessor(fileSystem), new UsingLineProcessor() });
            var packageAssemblyResolver = new PackageAssemblyResolver(fileSystem, new PackageContainer(fileSystem, logger), logger);
            var installationProvider = new NugetInstallationProvider(fileSystem, logger);

            return new ScriptServices(
                fileSystem,
                packageAssemblyResolver,
                new ScriptExecutor(fileSystem, filePreProcessor, engine, logger),
                engine,
                filePreProcessor,
                new ScriptPackResolver(new IScriptPack[0]),
                new PackageInstaller(installationProvider, logger),
                null, //IObjectSerializer
                logger,
                new AssemblyResolver(fileSystem, packageAssemblyResolver, new AssemblyUtility(), logger),
                null, //IConsole
                installationProvider
                );
        }
コード例 #2
0
        private static void RefreshAssemblies(ILog log)
        {
            var fileSystem = new FileSystem();

            var packagesFolder = Path.Combine(fileSystem.CurrentDirectory, "packages");

            if(fileSystem.DirectoryExists(packagesFolder))
            {
                // Delete any blacklisted packages to avoid various issues with PackageAssemblyResolver
                // https://github.com/scriptcs/scriptcs/issues/511
                foreach (var packagePath in
                    _blacklistedPackages.SelectMany(packageName => Directory.GetDirectories(packagesFolder)
                                .Where(d => new DirectoryInfo(d).Name.StartsWith(packageName, StringComparison.InvariantCultureIgnoreCase)),
                                (packageName, packagePath) => new {packageName, packagePath})
                        .Where(t => fileSystem.DirectoryExists(t.packagePath))
                        .Select(t => @t.packagePath))
                {
                    fileSystem.DeleteDirectory(packagePath);
                }
            }

            var par = new PackageAssemblyResolver(fileSystem, new PackageContainer(fileSystem, log), log);

            _assemblies = par.GetAssemblyNames(fileSystem.CurrentDirectory).ToList();

            // Add the assemblies in the current directory
            _assemblies.AddRange(Directory.GetFiles(fileSystem.CurrentDirectory, "*.dll")
                .Where(a => new AssemblyUtility().IsManagedAssembly(a)));
        }