Exemple #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="srcString"></param>
        /// <param name="Command"></param>
        /// <param name="cpType">= ComplieType.exe</param>
        /// <param name="isStartByWindow">=false</param>
        /// <returns></returns>
        public string Creat(string srcString, string Command, ComplieType cpType, bool isStartByWindow)
        {
            this.SrcString      = srcString;
            this.Command        = Command;
            this.cpType         = cpType;
            this.isWindow       = isStartByWindow;
            this.isHasErrorRows = false;
            this.RowErrorNumber = -1;
            isError             = false;
            CreatFile();//
            StringBuilder sbr = new StringBuilder();

            sbr.AppendLine(runStringCSC(MakeCommond()));//编译
            if (File.Exists(CommConfig.ExeFilePath) || File.Exists(CommConfig.DllFilePath))
            {
                sbr = new StringBuilder();
                sbr.AppendLine("-------编译成功--------------------------------");
                if (cpType == ComplieType.exe || cpType == ComplieType.winexe) //测试*.exe文件
                {
                    if (isWindow || cpType == ComplieType.winexe)              //判断是否使用CMD
                    {
                        System.Diagnostics.Process.Start(CommConfig.ExeFilePath);
                    }
                    else
                    {
                        sbr.AppendLine("\n" + runStringTemp(this.Command));
                    }
                }
            }
            else
            {
                isError = true;
                sbr.AppendLine("-------编译失败--------------------------------");

                try
                {
                    Regex reg = new Regex(@"\((\d+)\,\d+\)", RegexOptions.Multiline);
                    Match m   = reg.Match(sbr.ToString());

                    if (m.Success)
                    {
                        isHasErrorRows = true;
                        RowErrorNumber = int.Parse(m.Groups[1].Value);
                    }
                }
                catch (Exception e)
                {
                    isHasErrorRows = false;
                    RowErrorNumber = -1;
                }
            }

            return(sbr.ToString());
        }
Exemple #2
0
        //处理Csc命令
        public string RunCsc(string cscCommand)
        {
            cscCommand = cscCommand.ToLower();
            Regex reg = new Regex(@"\s+");

            string[] strArrys = reg.Split(cscCommand);

            ComplieBuilder cp       = new ComplieBuilder();
            string         srcStr   = Tmpform.txtEditor.Text;
            string         comm     = "";
            ComplieType    cpType   = ComplieType.exe;
            bool           isWindow = false;

            //
            foreach (var i in strArrys)
            {
                if (i == "?" || i == "help")
                {
                    return("CSC 编译帮助\n" +
                           "exe        生成普通exe程序\n" +
                           "winexe     生成窗体exe程序\n" +
                           "dll        生成类库程序\n" +
                           "wd         使用窗口启动(普通exe程序有效)\n" +
                           "arg:hello  设置参数为hello(普通exe程序有效,不能出现符号'∫',要输出空格:\\s)\n");
                }
                if (i == "show")
                {
                    Tmpform.AddCsc();
                    if (Tmpform.isShow)
                    {
                        Tmpform.StartMeun();
                    }
                    return("");
                }
                switch (i)
                {
                case "exe":
                    cpType = ComplieType.exe;
                    break;

                case "winexe":
                    cpType = ComplieType.winexe;
                    break;

                case "dll":
                    cpType = ComplieType.dll;
                    break;

                case "wd":
                    isWindow = true;
                    break;
                }
                if (i.StartsWith("arg:"))
                {
                    string tmp = i;
                    tmp   = tmp.Replace(@"\\", @"\");
                    tmp   = tmp.Replace(@"\s", " ");
                    comm += tmp.Replace("arg:", "∫");
                }
            }
            CompliReslut.OutPutStr      = cp.Creat(srcStr, comm, cpType, isWindow);
            CompliReslut.isError        = cp.isError;
            CompliReslut.isHasErrorRow  = cp.isHasErrorRows;
            CompliReslut.RowErrorNumber = cp.RowErrorNumber;
            ErrorMake();
            return(CompliReslut.OutPutStr);
        }