Exemplo n.º 1
0
        public ScriptCompilerError[] Compile(string[] source)
        {
            // Invoke the compiler
            CompilerResults results = compiler.CompileAssemblyFromSourceBatch(parameters, source);

            // Build errors
            ScriptCompilerError[] errors = new ScriptCompilerError[results.Errors.Count];

            // Clear parameters
            parameters.ReferencedAssemblies.Clear();

            // Create error copy
            int index = 0;

            foreach (CompilerError err in results.Errors)
            {
                // Generate the error
                errors[index] = new ScriptCompilerError
                {
                    errorCode = err.ErrorNumber,
                    errorText = err.ErrorText,
                    fileName  = err.FileName,
                    line      = err.Line,
                    column    = err.Column,
                    isWarning = err.IsWarning,
                };

                // Increment index
                index++;
            }

            // Check for success
            if (results.CompiledAssembly != null)
            {
                // Find the output name
                string name = results.CompiledAssembly.GetName().Name + ".dll";

                // Read the file
                assemblyData = File.ReadAllBytes(name);

                // Delete the temp file
                File.Delete(name);
            }

            // Get the errors
            return(errors);
        }
Exemplo n.º 2
0
        private ScriptCompilerError[] CompileShared(Func <CompilerParameters, string[], CompilerResults> compileMethod, CompilerParameters parameters, string[] sourceOrFiles)
        {
            // Setup compiler paremters
            McsCompiler.OutputDirectory = outputDirectory;
            McsCompiler.GenerateSymbols = generateSymbols;

            // Reset state so assembly and symbols dont get out of sync
            assemblyData = null;
            symbolsData  = null;

            // Invoke the compiler
            CompilerResults results = compileMethod(parameters, sourceOrFiles);

            // Build errors
            ScriptCompilerError[] errors = new ScriptCompilerError[results.Errors.Count];

            // Clear parameters
            parameters.ReferencedAssemblies.Clear();

            // Create error copy
            int index = 0;

            foreach (CompilerError err in results.Errors)
            {
                // Generate the error
                errors[index] = new ScriptCompilerError
                {
                    errorCode = err.ErrorNumber,
                    errorText = err.ErrorText,
                    fileName  = err.FileName,
                    line      = err.Line,
                    column    = err.Column,
                    isWarning = err.IsWarning,
                };

                // Increment index
                index++;
            }

            // Check for success
            if (results.CompiledAssembly != null)
            {
                // Find the output name
                string assemblyName = results.CompiledAssembly.GetName().Name + ".dll";

                // Read the file
                assemblyData = File.ReadAllBytes(assemblyName);

                // Delete the temp file
                File.Delete(assemblyName);


                if (generateSymbols == true)
                {
                    // Find the symbols
                    string symbolsName = assemblyName + ".mdb";

                    // Check for file
                    if (File.Exists(symbolsName) == true)
                    {
                        // Read thef file
                        symbolsData = File.ReadAllBytes(symbolsName);

                        // Delete the temp file
                        File.Delete(symbolsName);
                    }
                }
            }

            // Get the errors
            return(errors);
        }