private void ManagerForm_Load(object sender, EventArgs e) { // 读配置 FileInfo exeInfo = new FileInfo(Application.ExecutablePath); Directory.SetCurrentDirectory(exeInfo.Directory.FullName); string configFile = Path.Combine(exeInfo.Directory.FullName, "config.xml"); if (File.Exists(configFile)) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(configFile); XmlNode docNode = xmlDoc.DocumentElement; // Unity程序路径 XmlElement unityEle = docNode.SelectSingleNode("Unity") as XmlElement; UnityPath = unityEle.Attributes["ExePath"].Value; // 端口 XmlElement socketEle = docNode.SelectSingleNode("Socket") as XmlElement; listenPort = int.Parse(socketEle.Attributes["Port"].Value); // 工人 XmlElement workersEle = docNode.SelectSingleNode("workers") as XmlElement; XmlNodeList workerNodes = workersEle.SelectNodes("worker"); foreach (XmlElement xmlEle in workerNodes) { String name = xmlEle.Attributes["Name"].Value; String projPath = xmlEle.Attributes["ProjectPath"].Value; String defCmd = xmlEle.Attributes["DefaultCmd"].Value; Slave slave = new Slave { Name = name, ProjectPath = projPath, DefaultCmd = defCmd }; slave.Initialize(); Slaves.Add(slave); } // 后处理 XmlElement postBuildCmdsEle = docNode.SelectSingleNode("PostBuildCmds") as XmlElement; foreach (XmlElement xmlEle in postBuildCmdsEle) { string cmd = xmlEle.Attributes["Cmd"].Value; PostBuildCmds.Add(cmd); } WriteLine(""); WriteLine(">>>>>>>> 初始化完毕"); // 命令参考 } // 允许客户端接入 Waiter = new Waiter(8090); }
public void DoOrder(string cmd) { WriteLine("开始分析指令:"); WriteLine(cmd); // 缩减连续空格 Regex regex = new Regex(" +"); string fixCmd = regex.Replace(cmd, " "); string[] args = fixCmd.Split(' '); // 预定义参数 string arg_slave = ""; string arg_command = ""; string arg_platform = ""; string arg_packages = ""; // 读取参数对 for (int i = 0; i < args.Length; i++) { string arg = args[i]; switch (arg) { case "-slave": arg_slave = args[i + 1]; i++; break; case "-command": arg_command = args[i + 1]; i++; break; case "-platform": arg_platform = args[i + 1]; i++; break; case "-packages": arg_packages = args[i + 1]; i++; break; } } // 组合Unity命令 StringBuilder unityCMDBuilder = new StringBuilder(); bool commandOK = true; string commandErrInfo = ""; // 默认基础参数 unityCMDBuilder.Append(" -quit -batchmode -nographics "); // 设定Slave Slave curSlave = Slaves.Find(s => s.Name == arg_slave); if (curSlave != null) { unityCMDBuilder.Append(" -projectPath " + curSlave.ProjectPath + " "); if (curSlave.IsRunning) { WriteLine("奴隶" + curSlave.Name + "非常繁忙,请过会儿再鞭挞他 "); return; } // ======== // 发布命令 // ======== if (arg_command == "build") { if (arg_platform == "android") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformBuildAndroid "); // TODO 检查此项 WriteLine("APK Identifier必须先设置好,此错误不会有任何提示"); } else if (arg_platform == "ios") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformBuildIOS "); } else if (arg_platform == "web") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformBuildWeb "); } else if (arg_platform == "all") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformBuildAll "); } else { string info = "奴隶" + arg_slave + ": 我不认识这个目标平台" + arg_platform; commandErrInfo += info + "\n"; WriteLine(info); commandOK = false; } } // ======== // 打包命令 // ======== else if (arg_command == "package") { if (arg_platform == "android") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformPackageAndroid "); } else if (arg_platform == "ios") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformPackageIOS "); } else if (arg_platform == "web") { unityCMDBuilder.Append(" -executeMethod BackgroundWorker.PerformPackageWeb "); } } else { WriteLine("奴隶" + arg_slave + ":我只会打包(package)和发布(build)"); commandOK = false; } } else { string info = "指定的奴隶不存在! " + arg_slave; commandErrInfo += info + "\n"; Console.WriteLine(info); commandOK = false; } // 执行 if (commandOK) { WriteLine(""); WriteLine(">>>>>>> 已成功向奴隶下达指令"); WriteLine("UnityCmd: " + unityCMDBuilder.ToString()); curSlave.StartActionThread(unityCMDBuilder.ToString()); } else { WriteLine("命令存在问题,无法开始"); WriteLine(commandErrInfo); } }