Пример #1
0
        private static async Task <int> RunScript(string file, bool debugMode, IEnumerable <string> args, bool interactive)
        {
            if (!File.Exists(file))
            {
                throw new Exception($"Couldn't find file '{file}'");
            }

            var absoluteFilePath = Path.IsPathRooted(file) ? file : Path.Combine(Directory.GetCurrentDirectory(), file);
            var directory        = Path.GetDirectoryName(absoluteFilePath);

            using (var filestream = new FileStream(absoluteFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var sourceText = SourceText.From(filestream);
                var context    = new ScriptContext(sourceText, directory, args, absoluteFilePath, debugMode);

                if (interactive)
                {
                    var compiler = GetScriptCompiler(debugMode);
                    var runner   = new InteractiveRunner(compiler, compiler.Logger, ScriptConsole.Default);
                    await runner.RunLoopWithSeed(debugMode, context);

                    return(0);
                }

                return(await Run(debugMode, context));
            }
        }
Пример #2
0
        private static async Task <int> RunScript(string file, bool debugMode, bool useRestoreCache, LogFactory logFactory, OptimizationLevel optimizationLevel, IEnumerable <string> args, bool interactive, string[] packageSources)
        {
            if (!File.Exists(file))
            {
                if (IsHttpUri(file))
                {
                    var downloader = new ScriptDownloader();
                    var code       = await downloader.Download(file);

                    return(await RunCode(code, debugMode, useRestoreCache, logFactory, optimizationLevel, args, Directory.GetCurrentDirectory(), packageSources));
                }

                throw new Exception($"Couldn't find file '{file}'");
            }

            var absoluteFilePath = file.GetRootedPath();
            var directory        = Path.GetDirectoryName(absoluteFilePath);

            var sourceText = absoluteFilePath.ToSourceText();
            var context    = new ScriptContext(sourceText, directory, args, absoluteFilePath, optimizationLevel, packageSources: packageSources);

            if (interactive)
            {
                var compiler = GetScriptCompiler(debugMode, useRestoreCache, logFactory);

                var runner = new InteractiveRunner(compiler, logFactory, ScriptConsole.Default, packageSources);
                await runner.RunLoopWithSeed(context);

                return(0);
            }

            return(await Run(debugMode, useRestoreCache, logFactory, context));
        }
Пример #3
0
        private static async Task <int> RunScript(string file, bool debugMode, LogFactory logFactory, OptimizationLevel optimizationLevel, IEnumerable <string> args, bool interactive, string[] packageSources)
        {
            if (!File.Exists(file))
            {
                if (IsHttpUri(file))
                {
                    var downloader = new ScriptDownloader();
                    var code       = await downloader.Download(file);

                    return(await RunCode(code, debugMode, logFactory, optimizationLevel, args, Directory.GetCurrentDirectory(), packageSources));
                }

                throw new Exception($"Couldn't find file '{file}'");
            }

            var absoluteFilePath = Path.IsPathRooted(file) ? file : Path.Combine(Directory.GetCurrentDirectory(), file);
            var directory        = Path.GetDirectoryName(absoluteFilePath);

            using (var filestream = new FileStream(absoluteFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                var sourceText = SourceText.From(filestream);
                var context    = new ScriptContext(sourceText, directory, args, absoluteFilePath, optimizationLevel, packageSources: packageSources);
                if (interactive)
                {
                    var compiler = GetScriptCompiler(debugMode, logFactory);

                    var runner = new InteractiveRunner(compiler, logFactory, ScriptConsole.Default, packageSources);
                    await runner.RunLoopWithSeed(context);

                    return(0);
                }

                return(await Run(debugMode, logFactory, context));
            }
        }
        public async Task <int> Execute(ExecuteInteractiveCommandOptions options)
        {
            var compiler = new ScriptCompiler(_logFactory, useRestoreCache: false);
            var runner   = new InteractiveRunner(compiler, _logFactory, _scriptConsole, options.PackageSources);

            if (options.ScriptFile == null)
            {
                await runner.RunLoop();
            }
            else
            {
                var context = new ScriptContext(options.ScriptFile.Path.ToSourceText(), Path.GetDirectoryName(options.ScriptFile.Path), options.Arguments, options.ScriptFile.Path, OptimizationLevel.Debug, packageSources: options.PackageSources);
                await runner.RunLoopWithSeed(context);
            }

            return(0);
        }