예제 #1
0
        public override Assembly Compile(string path, string outPath)
        {
            Assembly asm = null;

            try
            {
                if (this.ExistsAndUpToDate(path, outPath))
                {
                    return(Assembly.LoadFrom(outPath));
                }

                var compiler = new Boo.Lang.Compiler.BooCompiler();
                compiler.Parameters.AddAssembly(typeof(Log).Assembly);
                compiler.Parameters.AddAssembly(typeof(ScriptManager).Assembly);
                compiler.Parameters.Input.Add(new FileInput(path));
                compiler.Parameters.OutputAssembly = outPath;
                compiler.Parameters.Pipeline       = new CompileToFile();

                var context = compiler.Run();
                if (context.GeneratedAssembly == null)
                {
                    var errors = context.Errors;
                    var newExs = new CompilerErrorsException();

                    foreach (var err in errors)
                    {
                        var newEx = new CompilerError(path, err.LexicalInfo.Line, err.LexicalInfo.Column, err.Message, false);
                        newExs.Errors.Add(newEx);
                    }

                    throw newExs;
                }

                asm = context.GeneratedAssembly;

                //this.SaveAssembly(asm, outPath);
            }
            catch (CompilerErrorsException)
            {
                throw;
            }
            catch (UnauthorizedAccessException)
            {
                // Thrown if file can't be copied. Happens if script was
                // initially loaded from cache.
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return(asm);
        }
예제 #2
0
파일: BooCompiler.cs 프로젝트: pie3467/aura
        public override Assembly Compile(string path, string outPath)
        {
            Assembly asm = null;
            try
            {
                if (this.ExistsAndUpToDate(path, outPath))
                    return Assembly.LoadFrom(outPath);

                var compiler = new Boo.Lang.Compiler.BooCompiler();
                compiler.Parameters.AddAssembly(typeof(Log).Assembly);
                compiler.Parameters.AddAssembly(typeof(ScriptManager).Assembly);
                compiler.Parameters.Input.Add(new FileInput(path));
                compiler.Parameters.OutputAssembly = outPath;
                compiler.Parameters.Pipeline = new CompileToFile();

                var context = compiler.Run();
                if (context.GeneratedAssembly == null)
                {
                    var errors = context.Errors;
                    var newExs = new CompilerErrorsException();

                    foreach (var err in errors)
                    {
                        var newEx = new CompilerError(path, err.LexicalInfo.Line, err.LexicalInfo.Column, err.Message, false);
                        newExs.Errors.Add(newEx);
                    }

                    throw newExs;
                }

                asm = context.GeneratedAssembly;

                //this.SaveAssembly(asm, outPath);
            }
            catch (CompilerErrorsException)
            {
                throw;
            }
            catch (UnauthorizedAccessException)
            {
                // Thrown if file can't be copied. Happens if script was
                // initially loaded from cache.
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return asm;
        }
예제 #3
0
        public override Assembly Compile(string path, string outPath)
        {
            Assembly asm = null;

            try
            {
                if (this.ExistsAndUpToDate(path, outPath))
                {
                    return(Assembly.LoadFrom(outPath));
                }

                asm = CSScript.LoadCode(this.PreCompile(File.ReadAllText(path)));

                this.SaveAssembly(asm, outPath);
            }
            catch (csscript.CompilerException ex)
            {
                var errors = ex.Data["Errors"] as System.CodeDom.Compiler.CompilerErrorCollection;
                var newExs = new CompilerErrorsException();

                foreach (System.CodeDom.Compiler.CompilerError err in errors)
                {
                    // Line-1 to compensate lines added by the pre-compiler.
                    var newEx = new CompilerError(path, err.Line - 1, err.Column, err.ErrorText, err.IsWarning);
                    newExs.Errors.Add(newEx);
                }

                throw newExs;
            }
            catch (UnauthorizedAccessException)
            {
                // Thrown if file can't be copied. Happens if script was
                // initially loaded from cache.
                // TODO: Also thrown if CS-Script can't create the file,
                //   ie under Linux, if /tmp/CSSCRIPT isn't writeable.
                //   Handle that somehow?
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return(asm);
        }
예제 #4
0
        public override Assembly Compile(string path, string outPath)
        {
            Assembly asm = null;
            try
            {
                if (this.ExistsAndUpToDate(path, outPath))
                    return Assembly.LoadFrom(outPath);

                asm = CSScript.LoadCode(this.PreCompile(File.ReadAllText(path)));

                this.SaveAssembly(asm, outPath);
            }
            catch (csscript.CompilerException ex)
            {
                var errors = ex.Data["Errors"] as System.CodeDom.Compiler.CompilerErrorCollection;
                var newExs = new CompilerErrorsException();

                foreach (System.CodeDom.Compiler.CompilerError err in errors)
                {
                    // Line-1 to compensate lines added by the pre-compiler.
                    var newEx = new CompilerError(path, err.Line - 1, err.Column, err.ErrorText, err.IsWarning);
                    newExs.Errors.Add(newEx);
                }

                throw newExs;
            }
            catch (UnauthorizedAccessException)
            {
                // Thrown if file can't be copied. Happens if script was
                // initially loaded from cache.
                // TODO: Also thrown if CS-Script can't create the file,
                //   ie under Linux, if /tmp/CSSCRIPT isn't writeable.
                //   Handle that somehow?
            }
            catch (Exception ex)
            {
                Log.Exception(ex);
            }

            return asm;
        }