public void Initialize()
        {
            var hostAssemblyPaths = _fileSystem.EnumerateBinaries(_fileSystem.HostBin, SearchOption.TopDirectoryOnly);

            AddAssemblyPaths(hostAssemblyPaths);

            var globalPaths = _resolver.GetAssemblyPaths(_fileSystem.GlobalFolder, true);

            AddAssemblyPaths(globalPaths);

            var scriptAssemblyPaths = _resolver.GetAssemblyPaths(_fileSystem.CurrentDirectory, true);

            AddAssemblyPaths(scriptAssemblyPaths);
        }
Exemple #2
0
        public CommandResult Execute()
        {
            try
            {
                _fileSystemMigrator.Migrate();

                var assemblyPaths    = Enumerable.Empty <string>();
                var workingDirectory = _fileSystem.GetWorkingDirectory(_script);
                if (workingDirectory != null)
                {
                    assemblyPaths = _assemblyResolver.GetAssemblyPaths(workingDirectory);
                }

                _composer.Compose(workingDirectory);

                _scriptExecutor.Initialize(assemblyPaths, _scriptPackResolver.GetPacks(), ScriptArgs);
                var scriptResult  = _scriptExecutor.Execute(_script, ScriptArgs);
                var commandResult = Inspect(scriptResult);
                _scriptExecutor.Terminate();
                return(commandResult);
            }
            catch (FileNotFoundException ex)
            {
                _logger.ErrorFormat("{0} - '{1}'.", ex, ex.Message, ex.FileName);
                return(CommandResult.Error);
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
                return(CommandResult.Error);
            }
        }
Exemple #3
0
        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c or blank to exit)\r\n");
            var repl = new Repl(_scriptArgs, _fileSystem, _scriptEngine, _logger, _console, _filePreProcessor, _replCommandService);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory, string.Empty);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            try
            {
                if (!string.IsNullOrWhiteSpace(_scriptName))
                {
                    _logger.Info(string.Format("Loading preseeded script: {0}", _scriptName));
                    repl.Execute(string.Format("#load {0}", _scriptName));
                }

                while (ExecuteLine(repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(CommandResult.Error);
            }

            repl.Terminate();
            return(CommandResult.Success);
        }
        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c to exit)" + Environment.NewLine);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            _repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            try
            {
                if (!string.IsNullOrWhiteSpace(_scriptName))
                {
                    _logger.Info(string.Format("Loading script: {0}", _scriptName));
                    _repl.Execute(string.Format("#load {0}", _scriptName));
                }

                while (ExecuteLine(_repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(CommandResult.Error);
            }

            _repl.Terminate();
            return(CommandResult.Success);
        }
Exemple #5
0
        public void Load(IModuleConfiguration config, string modulePackagesPath, string extension, params string[] moduleNames)
        {
            _logger.Debug("Loading modules from: " + modulePackagesPath);
            var paths   = _resolver.GetAssemblyPaths(modulePackagesPath);
            var catalog = new AggregateCatalog();

            foreach (var path in paths)
            {
                _addToCatalog(path, catalog);
            }

            var container   = new CompositionContainer(catalog);
            var lazyModules = _getModules(container);
            var modules     = lazyModules
                              .Where(m => moduleNames.Contains(m.Metadata.Name) ||
                                     (extension != null && m.Metadata.Extensions != null && (m.Metadata.Extensions.Split(',').Contains(extension))))
                              .Select(m => m.Value);

            _logger.Debug("Initializing modules");
            foreach (var module in modules)
            {
                _logger.Debug(string.Format("Initializing module:{0}", module.GetType().FullName));
                module.Initialize(config);
            }
            _logger.Debug("Modules initialized");
        }
        public CommandResult Execute()
        {
            try
            {
                _fileSystemMigrator.Migrate();

                var assemblyPaths    = Enumerable.Empty <string>();
                var workingDirectory = _fileSystem.GetWorkingDirectory(_script);
                if (workingDirectory != null)
                {
                    assemblyPaths = _assemblyResolver.GetAssemblyPaths(workingDirectory);
                }

                _composer.Compose(workingDirectory);

                _scriptExecutor.Initialize(assemblyPaths, _scriptPackResolver.GetPacks(), ScriptArgs);

                // HACK: This is a (dirty) fix for #1086. This might be a temporary solution until some further refactoring can be done.
                _scriptExecutor.ScriptEngine.CacheDirectory = Path.Combine(workingDirectory ?? _fileSystem.CurrentDirectory, _fileSystem.DllCacheFolder);
                var scriptResult  = _scriptExecutor.Execute(_script, ScriptArgs);
                var commandResult = Inspect(scriptResult);
                _scriptExecutor.Terminate();
                return(commandResult);
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error executing script '{0}'", ex, _script);
                return(CommandResult.Error);
            }
        }
Exemple #7
0
        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c or blank to exit)\r\n");
            var repl = new Repl(_scriptArgs, _fileSystem, _scriptEngine, _logger, _console, _filePreProcessor);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            repl.Initialize(assemblies, scriptPacks);

            try
            {
                while (ExecuteLine(repl))
                {
                }
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(CommandResult.Error);
            }

            repl.Terminate();
            return(CommandResult.Success);
        }
        private void AddPaths(IEnumerable <string> modulePackagesPaths, string hostBin, List <string> paths)
        {
            foreach (var modulePaths in modulePackagesPaths
                     .Select(modulePackagesPath => _resolver.GetAssemblyPaths(modulePackagesPath, true)))
            {
                paths.AddRange(modulePaths);
            }

            if (hostBin != null)
            {
                var assemblyPaths = _fileSystem.EnumerateBinaries(hostBin, SearchOption.TopDirectoryOnly);
                paths.AddRange(assemblyPaths);
            }
        }
Exemple #9
0
        public CommandResult Execute()
        {
            try
            {
                var assemblyPaths = Enumerable.Empty <string>();

                var workingDirectory = _fileSystem.GetWorkingDirectory(_script);
                if (workingDirectory != null)
                {
                    assemblyPaths = _assemblyResolver.GetAssemblyPaths(workingDirectory, _script);
                }

                _scriptExecutor.Initialize(assemblyPaths, _scriptPackResolver.GetPacks(), ScriptArgs);
                var result = _scriptExecutor.Execute(_script, ScriptArgs);
                _scriptExecutor.Terminate();

                if (result == null)
                {
                    return(CommandResult.Error);
                }

                if (result.CompileExceptionInfo != null)
                {
                    _logger.Error(result.CompileExceptionInfo.SourceException.Message);
                    _logger.Debug(result.CompileExceptionInfo.SourceException);
                    return(CommandResult.Error);
                }

                if (result.ExecuteExceptionInfo != null)
                {
                    _logger.Error(result.ExecuteExceptionInfo.SourceException);
                    return(CommandResult.Error);
                }

                return(CommandResult.Success);
            }
            catch (FileNotFoundException fnfex)
            {
                _logger.ErrorFormat("{0} - {1}", fnfex.Message, fnfex.FileName);
                return(CommandResult.Error);
            }
            catch (Exception ex)
            {
                _logger.Error(ex.Message);
                return(CommandResult.Error);
            }
        }
Exemple #10
0
        public CommandResult Execute()
        {
            _fileSystemMigrator.Migrate();

            _console.WriteLine("scriptcs (ctrl-c to exit or :help for help)" + Environment.NewLine);

            var workingDirectory = _fileSystem.CurrentDirectory;
            var assemblies       = _assemblyResolver.GetAssemblyPaths(workingDirectory);
            var scriptPacks      = _scriptPackResolver.GetPacks();

            _composer.Compose(workingDirectory);

            _repl.Initialize(assemblies, scriptPacks, ScriptArgs);

            if (!string.IsNullOrWhiteSpace(_scriptName))
            {
                _logger.InfoFormat("Executing script '{0}'", _scriptName);
                try
                {
                    _repl.Execute(string.Format("#load {0}", _scriptName));
                }
                catch (Exception ex)
                {
                    _logger.ErrorException("Error executing script '{0}'", ex, _scriptName);
                    return(CommandResult.Error);
                }
            }

            try
            {
                while (ExecuteLine(_repl))
                {
                }

                _console.WriteLine();
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error executing REPL", ex);
                return(CommandResult.Error);
            }

            _repl.Terminate();
            return(CommandResult.Success);
        }