Exemple #1
0
        public void ShowCompileResult(CompilerResults result)
        {
            if (result.Errors.HasErrors)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Build Error:");
                Console.WriteLine("Error Numeber:{0}", result.Errors.Count);
                foreach (CompilerError item in result.Errors)
                {
                    Console.WriteLine("Line:{0}\tError:{1}", item.Line, item.ErrorText);
                }
                Console.ResetColor();
            }
            Console.WriteLine("Build Success!");
            try
            {
#if CompileIntoMemory
                                Type type  =  result.CompiledAssembly.GetType("Program");
                                Phoenix.GetMethod("Main").Invoke(null, new string[] {});
#else
                System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo
                {
                    FileName               = result.PathToAssembly,
                    UseShellExecute        = false,
                    CreateNoWindow         = true,
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true
                };
                System.Diagnostics.Process process;
                process = new System.Diagnostics.Process();
                process.OutputDataReceived += (s, e) => {
                    if (e.Data != null)
                    {
                        Console.WriteLine(e.Data);
                    }
                };
                process.ErrorDataReceived += (s, e) => {
                    if (e.Data != null)
                    {
                        Console.WriteLine(e.Data);
                    }
                };
                process.StartInfo           = info;
                process.EnableRaisingEvents = true;
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();
#endif
            }
            catch (System.Reflection.TargetInvocationException ex)
            {
                Console.WriteLine("Exception:" + ex.InnerException.Message);
            }
        }