コード例 #1
0
ファイル: Win2Tiz.cs プロジェクト: katatunix/win2tiz
        private bool buildCommandFile(string[] args)
        {
            DateTime totalTimeBegin = DateTime.Now;

            string file    = null;
            int    jobs    = s_kDefaultJobs;
            bool   verbose = false;

            for (int i = 1; i < args.Length; i++)
            {
                if (args[i] == "-file")
                {
                    if (i + 1 >= args.Length)
                    {
                        break;
                    }
                    file = args[i + 1];
                    i++;
                }
                else if (args[i] == "-jobs")
                {
                    if (i + 1 >= args.Length)
                    {
                        break;
                    }
                    jobs = StringUtils.convertString2Int(args[i + 1]);
                    i++;
                }
                else if (args[i] == "-verbose")
                {
                    verbose = true;
                }
            }
            if (jobs <= 0 || jobs > s_kDefaultJobs)
            {
                jobs = s_kDefaultJobs;
            }

            if (file == null)
            {
                CConsole.writeError("error: The value for the option '-file' must be specified.\n");
                printUsage();
                return(false);
            }

            file = Path.GetFullPath(file);

            if (!File.Exists(file))
            {
                CConsole.writeError("error: Could not found the file " + file + ".\n");
                return(false);
            }

            lock (m_lock)
            {
                m_builder = new Builder();
            }

            string workingDir = Path.GetDirectoryName(file);

            using (StreamReader reader = new StreamReader(file))
            {
                string cmd;
                while ((cmd = reader.ReadLine()) != null)
                {
                    cmd = cmd.Trim();
                    if (cmd.Length == 0 || cmd.StartsWith("//"))
                    {
                        continue;
                    }

                    string project = "Project";

                    if (cmd[0] == '*')
                    {
                        int index = cmd.IndexOf(' ');
                        if (index == -1)
                        {
                            CConsole.writeError("error: Invalid compile command " + cmd + ".\n");
                            return(false);
                        }
                        project = cmd.Substring(1, index - 1);
                        cmd     = cmd.Substring(index + 1).Trim();
                        if (cmd.Length == 0)
                        {
                            continue;
                        }
                    }

                    // Parse the cmd
                    ICmdParser parser = CmdParserFactory.createCmdParser(cmd);
                    string     alias  = parser.getAlias();

                    if (alias == null)
                    {
                        CConsole.writeError("error: Invalid command " + cmd + "\n");
                        return(false);
                    }

                    TCommand tCommand = new TCommand(cmd, cmd, workingDir, alias, ECommandType.eCompile, project);
                    m_builder.addCommand(tCommand);
                }
            }

            bool result = m_builder.build(verbose, jobs);

            m_builder = null;

            CConsole.writeTime("Total time: " + (DateTime.Now - totalTimeBegin).ToString() + "\n\n");

            return(result);
        }
コード例 #2
0
ファイル: ServerHandler.cs プロジェクト: katatunix/win2tiz
        private void handleMessageCompile(Message msg)
        {
            MessageCompileRequest msgCompile = null;

            try
            {
                msgCompile = new MessageCompileRequest(msg);
            }
            catch (Exception)
            {
                // Ignore
                return;
            }

            string cmd = msgCompile.getCmd();

            ICmdParser parser = CmdParserFactory.createCmdParser(cmd);

            string outputFileName;

            cmd = parser.makeServerCmd(m_sessionFolderPath, out outputFileName, m_debugPrefixMap);
            string alias = parser.getAlias();

            Message respondMessage = null;
            bool    ok             = false;

            if (alias != null && outputFileName != null)
            {
                // Compile
                CConsole.writeInfoLine(string.Format("{0} Recv a compile request: {1}", cur(), alias));

                string outputFilePath = m_sessionFolderPath + outputFileName;

                string workingDir = parser.getLocalSpecificWorkingDir();
                if (workingDir == null)
                {
                    workingDir = m_sessionFolderPath;
                }

                TProcessResult pr = m_processCompile.execute(cmd, workingDir, outputFilePath);

                if (!pr.wasExec || pr.exitCode != 0)
                {
                    CConsole.writeInfoLine(
                        string.Format("{0} Compile error: wasExec=[{1}], exitCode=[{2}], cmd=[{3}], outputText=[{4}]",
                                      cur(), pr.wasExec, pr.exitCode, cmd, pr.outputText)
                        );
                    respondMessage = MessageCompileResponse.createMessage(pr.wasExec, pr.exitCode, pr.outputText, null, 0);
                }
                else
                {
                    ok = true;
                    // Read the output file from disk
                    byte[] buffer   = IOUtils.readFile_Bytes(outputFilePath);
                    int    fileSize = buffer == null ? 0 : buffer.Length;
                    respondMessage = MessageCompileResponse.createMessage(
                        pr.wasExec, pr.exitCode, pr.outputText, buffer, fileSize);
                }
            }
            else
            {
                CConsole.writeInfoLine(string.Format("{0} Receive a compile request but it is a invalid command", cur()));
                respondMessage = MessageCompileResponse.createMessage(false, 0, "error: Invalid compile command!", null, 0);
            }

            CConsole.writeInfoLine(string.Format("{0} Send compile result: {1}, success = {2}",
                                                 cur(), alias != null ? alias : "[no file]", ok));

            m_messageStream.writeMessage(respondMessage);
        }