/// <summary> /// 任务执行完后 /// </summary> void runner_TaskFinished() { try { //发送结果数据到服务器 string path = runner.ResultRinexFtp; TcpClient newclient = new TcpClient(controlIp, controlPort); BinaryWriter newbr = new BinaryWriter(newclient.GetStream()); TelMsg tMsg = new TelMsg() { MsgType = Winform.MsgType.Path, XmlContent = path, From = Geo.Utils.NetUtil.GetIp(), To = controlIp }; newbr.Write(tMsg.ToXml()); newbr.Flush(); } catch (Exception ex) { ShowInfo("向服务器返回数据出错:" + ex.Message); } }
/// <summary> /// 任务执行完后,报告控制端,让其下载结果。 /// </summary> void ReportResultToServer(string ResultUrl) { try { //发送结果数据到服务器 // string ResultUrl = "";//runner.ResultRinexFtp; TcpClient newclient = new TcpClient(MasterIp, MasterPort); BinaryWriter newbr = new BinaryWriter(newclient.GetStream()); TelMsg tMsg = new TelMsg() { MsgType = Winform.MsgType.Path, XmlContent = ResultUrl, From = Geo.Utils.NetUtil.GetIp(), To = MasterIp }; newbr.Write(tMsg.ToXml()); newbr.Flush(); } catch (Exception ex) { log.Info("向服务器返回数据出错:" + ex.Message); } }
/// <summary> /// 监听客户端执行结果。并下载到本地。 /// </summary> public void ListenClient() { while (true) { if (Stop) { break; } try { client = lister.AcceptTcpClient(); } catch (Exception ex) { ShowInfo(ex.Message); break; } //有数据,则读取 if (client.Available > 0) { BinaryReader br = new BinaryReader(client.GetStream()); string msg = br.ReadString(); TelMsg tMsg = TelMsg.ParseXml(msg); ShowInfo("收到信息,来自 " + tMsg.From + "," + msg); if (tMsg.MsgType == MsgType.Path) { string localPath = Path.Combine(resultDir, Path.GetFileName(tMsg.XmlContent)); Geo.Utils.NetUtil.FtpDownload(tMsg.XmlContent, localPath); ShowInfo("已经下载到本地" + localPath + "耗时:" + Geo.Utils.DateTimeUtil.GetFloatString(watch.Elapsed)); completedThreadCount++; //int runCount = ComputeNodes.Count<GofComputeNode>(m => m.Enabled); if (completedThreadCount + failedThreadCount == _taskCount) { AfterCompleted(); } else//继续执行。 { GofComputeNode node = ComputeNodes.Find(m => tMsg.From.Contains(m.Ip)); if (node != null) { InvokeComputeNodeTask(node); } } } } } }
/// <summary> /// 解析XML /// </summary> /// <param name="xml"></param> /// <returns></returns> public static TelMsg ParseXml(string xml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlElement e = doc.DocumentElement; TelMsg c = new TelMsg(); c.MsgType = (MsgType)Enum.Parse(typeof(MsgType), e.SelectSingleNode("./MsgType").InnerText); c.XmlContent = e.SelectSingleNode("./XmlContent").InnerXml; c.From = e.SelectSingleNode("./From").InnerXml; c.To = e.SelectSingleNode("./To").InnerXml; return(c); }
/// <summary> /// 运行客户端,调用。 /// </summary> /// <param name="node"></param> /// <returns></returns> private string RunOne(GofComputeNode node) { string str = ""; try { //列表,记录任务 int taskIndex = ComputeNodeTaskDic[node]; if (node.TaskCount <= taskIndex) { return(node + " 所有任务已经执行完!"); } var task = node.Tasks[taskIndex]; TelMsg tMsg = new TelMsg() { MsgType = Winform.MsgType.Task, XmlContent = task.ToXml(), From = Geo.Utils.NetUtil.GetFirstIp(), To = node.Ip }; TcpClient client = new TcpClient(node.Ip, node.Port); NetworkStream stream = client.GetStream(); BinaryReader br = new BinaryReader(stream); BinaryWriter bw = new BinaryWriter(stream); bw.Write(tMsg.ToXml()); bw.Flush(); //BinaryWriter.Close(); str = br.ReadString(); //工作编号增加1 ComputeNodeTaskDic[node]++; } catch (Exception ex) { str = node + "出错, " + ex.Message; //失败的节点 failedThreadCount++; } return(str); }
public void ListenClient() { try { while (true) { if (Stop) { break; } try { client = lister.AcceptTcpClient(); } catch (Exception ex) { ShowInfo(ex.Message); break; } TelCommand cmd = new TelCommand(client); list.Add(cmd); string info = "来自" + cmd.LocalEndPoint + ",命令:" + cmd.CmdStr + "\r\n"; ShowInfo(info); ShowInfo("开始执行任务...."); currentTask = Task.ParseXml(TelMsg.ParseXml(cmd.CmdStr).XmlContent); runner = new TaskRunner(Gnsser.Interoperation.Bernese.BerBpe.BerGpsDataPath); runner.InfoProduced += runner_InfoProduced; runner.TaskFinished += runner_TaskFinished; runner.RunAsyn(currentTask); } } catch (Exception ex) { if (!this.IsDisposed) { ShowInfo("运行错误:" + ex.Message); } } }
public void ListenClient() { //try //{ while (true) { if (Stop) { break; } try { TcpClient = TcpListener.AcceptTcpClient(); } catch (Exception ex) { ShowInfo(ex.Message); break; } TelCommand cmd = new TelCommand(TcpClient); list.Add(cmd); string info = "来自" + cmd.LocalEndPoint + ",命令:" + cmd.CmdStr + "\r\n"; ShowInfo(info); ShowInfo("开始执行任务...."); //解析并保存到当前目录 CurrentTask = GofTask.ParseXml(TelMsg.ParseXml(cmd.CmdStr).XmlContent); var localGofPath = SaveGofToLocal(CurrentTask); //开始执行 var pathes = new string[] { localGofPath }; this.AppendPathToTextBox(pathes); this.AddTasksAndRun(pathes); } //} //catch (Exception ex) //{ // if (!this.IsDisposed) // ShowInfo("运行错误:" + ex.Message); //} }