ProcessFile() public method

public ProcessFile ( string path ) : FilePreProcessorResult
path string
return FilePreProcessorResult
Example #1
0
        public void Execute(string script)
        {
            var foregroundColor = Console.ForegroundColor;

            try
            {
                if (PreProcessorUtil.IsLoadLine(script))
                {
                    var filepath = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, script);
                    script = FilePreProcessor.ProcessFile(filepath);
                }
                else if (PreProcessorUtil.IsRLine(script))
                {
                    var assemblyPath = PreProcessorUtil.GetPath(PreProcessorUtil.RString, script);
                    References = References.Union(new[] { assemblyPath });
                    return;
                }

                Console.ForegroundColor = ConsoleColor.Cyan;
                var result = ScriptEngine.Execute(script, References, DefaultNamespaces, ScriptPackSession);
                if (result != null)
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine(result.ToJsv()

                                      );
                }
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\r\n" + ex + "\r\n");
            }
            Console.ForegroundColor = foregroundColor;
        }
Example #2
0
        public virtual ScriptResult Execute(string script, params string[] scriptArgs)
        {
            var path   = Path.IsPathRooted(script) ? script : Path.Combine(FileSystem.CurrentDirectory, script);
            var result = FilePreProcessor.ProcessFile(path);

            ScriptEngine.FileName = Path.GetFileName(path);
            return(EngineExecute(Path.GetDirectoryName(path), scriptArgs, result));
        }
Example #3
0
        public virtual ScriptResult Execute(string script, string[] scriptArgs)
        {
            var path       = Path.IsPathRooted(script) ? script : Path.Combine(FileSystem.CurrentDirectory, script);
            var result     = FilePreProcessor.ProcessFile(path);
            var references = References.Union(result.References);
            var namespaces = Namespaces.Union(result.UsingStatements);

            Logger.Debug("Starting execution in engine");
            return(ScriptEngine.Execute(result.Code, scriptArgs, references, namespaces, ScriptPackSession));
        }
Example #4
0
        public virtual ScriptResult Execute(string script, params string[] scriptArgs)
        {
            var path   = Path.IsPathRooted(script) ? script : Path.Combine(FileSystem.CurrentDirectory, script);
            var result = FilePreProcessor.ProcessFile(path);

            References = References.Union(result.References);
            var namespaces = Namespaces.Union(result.Namespaces);

            ScriptEngine.FileName = Path.GetFileName(path);

            Logger.Debug("Starting execution in engine");

            InjectScriptLibraries(Path.GetDirectoryName(path), result, ScriptPackSession.State);
            return(ScriptEngine.Execute(result.Code, scriptArgs, References, namespaces, ScriptPackSession));
        }
Example #5
0
        protected internal virtual FilePreProcessorResult LoadScriptLibraries(string workingDirectory)
        {
            if (string.IsNullOrWhiteSpace(ScriptLibraryComposer.ScriptLibrariesFile))
            {
                return(null);
            }

            var scriptLibrariesPath = Path.Combine(workingDirectory, FileSystem.PackagesFolder,
                                                   ScriptLibraryComposer.ScriptLibrariesFile);

            if (FileSystem.FileExists(scriptLibrariesPath))
            {
                _log.DebugFormat("Found Script Library at {0}", scriptLibrariesPath);
                return(FilePreProcessor.ProcessFile(scriptLibrariesPath));
            }

            return(null);
        }
Example #6
0
File: Repl.cs Project: waf/scriptcs
        public override ScriptResult Execute(string script, params string[] scriptArgs)
        {
            try
            {
                if (PreProcessorUtil.IsLoadLine(script))
                {
                    var filepath = PreProcessorUtil.GetPath(PreProcessorUtil.LoadString, script);
                    if (FileSystem.FileExists(filepath))
                    {
                        var processorResult = FilePreProcessor.ProcessFile(filepath);
                        script = processorResult.Code;
                    }
                    else
                    {
                        throw new FileNotFoundException(string.Format("Could not find script '{0}'", filepath), filepath);
                    }
                }
                else if (PreProcessorUtil.IsRLine(script))
                {
                    var assemblyName = PreProcessorUtil.GetPath(PreProcessorUtil.RString, script);
                    var assemblyPath = FileSystem.GetFullPath(Path.Combine(Constants.BinFolder, assemblyName));
                    AddReferences(FileSystem.FileExists(assemblyPath) ? assemblyPath : assemblyName);

                    return new ScriptResult();
                }

                Console.ForegroundColor = ConsoleColor.Cyan;

                Buffer += script;

                var result = ScriptEngine.Execute(Buffer, _scriptArgs, References, DefaultNamespaces, ScriptPackSession);
                if (result != null)
                {
                    if (result.CompileExceptionInfo != null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result.CompileExceptionInfo.SourceException.ToString());
                    }

                    if (result.ExecuteExceptionInfo != null)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine(result.ExecuteExceptionInfo.SourceException.ToString());
                    }

                    if (result.IsPendingClosingChar)
                    {
                        return result;
                    }

                    if (result.ReturnValue != null)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine(result.ReturnValue.ToJsv());
                    }

                    Buffer = null;
                }

                return result;
            }
            catch (FileNotFoundException fileEx)
            {
                RemoveReferences(fileEx.FileName);
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\r\n" + fileEx + "\r\n");
                return new ScriptResult { CompileExceptionInfo = ExceptionDispatchInfo.Capture(fileEx) };
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\r\n" + ex + "\r\n");
                return new ScriptResult { ExecuteExceptionInfo = ExceptionDispatchInfo.Capture(ex) };
            }
            finally
            {
                Console.ResetColor();
            }
        }