Exemplo n.º 1
0
        public string CompilePage(string pageFilePath, string GetVars = "", string PostVars = "")
        {
            try
            {
                string temp = System.IO.Path.GetTempFileName() + "." + AppHelper.LastPeice(pageFilePath, ".");

                if (this.DecodeDataBeforeEnvironment)
                {
                    GetVars = WebServer.DecodeUrlChars(GetVars);
                }

                if (GetVars.StartsWith("?"))
                {
                    GetVars = GetVars.Substring(1);
                }

                string prepend = XCompiler.PrependCode(this.LangName, (PostVars != "") ? "POST" : "GET");

                if (PostVars != "")
                {
                    prepend = prepend.Replace("GET", "POST");
                }

                AppHelper.writeToFile(temp, prepend + " \r\n\r\n" + AppHelper.ReadFileText(pageFilePath));
                pageFilePath = temp;

                Process proc = new Process();
                proc.StartInfo.FileName               = CompilerPath;
                proc.StartInfo.Arguments              = this.ProcessArgs.Replace("$page$", pageFilePath) + " " + GetVars + " " + PostVars;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.RedirectStandardOutput = true;
                proc.StartInfo.RedirectStandardError  = true;
                proc.Start();

                string res = proc.StandardOutput.ReadToEnd();
                if (string.IsNullOrEmpty(res))
                {
                    res = proc.StandardError.ReadToEnd();
                    res = "<h2 style=\"color:red;\">Error!</h2><hr/> <h4>Error Details :</h4> <pre>" + res + "</pre>";
                    proc.StandardError.Close();
                }
                if (res.StartsWith("\n Parse error: syntax error"))
                {
                    res = "<h2 style=\"color:red;\">Error!</h2><hr/> <h4>Error Details :</h4> <pre>" + res + "</pre>";
                }

                proc.StandardOutput.Close();
                proc.Close();

                AppHelper.deleteFile(temp);
                return(res);
            }
            catch (Exception s) { return(s.Message); }
        }