/// <summary> /// 将参数文件保存到本地 /// </summary> private void SaveParamToLocal(GofTask CurrentTask) { foreach (var kv in CurrentTask.Params) { var localParamPath = Path.Combine(Setting.GnsserConfig.CurrentProject.ParamDirectory, kv.Key); File.WriteAllText(localParamPath, kv.Value); } }
/// <summary> /// 编辑一个项目 /// </summary> /// <param name="node"></param> /// <param name="index">顺序序号,从 0 开始</param> public void Edit(GofTask node, int index) { XmlDocument newdoc = new XmlDocument(); newdoc.LoadXml(node.ToXml()); XmlElement e = newdoc.DocumentElement; doc.DocumentElement.ChildNodes[index].InnerXml = e.InnerXml; }
/// <summary> /// 解析XML /// </summary> /// <param name="north"></param> /// <returns></returns> public List <GofTask> GetAllTasks() { List <GofTask> list = new List <GofTask>(); foreach (XmlNode item in doc.DocumentElement.ChildNodes) { var task = GofTask.ParseXml(item.OuterXml); list.Add(task); } return(list); }
/// <summary> /// 是否相等 /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { GofTask t = obj as GofTask; if (t == null) { return(false); } return(Name.Equals(t.Name) && Id.Equals(t.Id)); }
/// <summary> /// 添加任务到文件。 /// </summary> /// <param name="node"></param> public void Add(GofTask node) { node.Id = this.doc.DocumentElement.ChildNodes.Count; XmlDocument newdoc = new XmlDocument(); newdoc.LoadXml(node.ToXml()); XmlElement e = newdoc.DocumentElement; var newNode = doc.ImportNode(e, true); doc.DocumentElement.AppendChild(newNode); }
private void 导入OToolStripButton_Click(object sender, EventArgs e) { var absPath = Geo.Utils.FormUtil.ShowFormGetFilePath("操作文件|*.gof"); if (absPath == null) { return; } OperationFlow operFlow = OperationFlow.ReadFromFile(absPath); var task = new GofTask(operFlow); this.mgr.Add(task); this.mgr.Save(); // tasks.Add(task); this.bindingSource_task.Add(task); }
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); //} }
private void 除任务ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.bindingSource2.Current == null) { return; } GofComputeNode curent1 = this.bindingSource1.Current as GofComputeNode; List <DataGridViewRow> rows = Geo.Utils.DataGridViewUtil.GetSelectedRows(this.dataGridView2); foreach (var item in rows) { GofTask curent = item.DataBoundItem as GofTask; curent1.Tasks.Remove(curent); } mgr.Edit(curent1, this.bindingSource1.IndexOf(curent1)); mgr.Save(); BindSub(); }
/// <summary> /// 解析XML字符串 /// </summary> /// <param name="xml"></param> /// <returns></returns> public static GofTask ParseXml(string xml) { XmlDocument doc = new XmlDocument(); doc.LoadXml(xml); XmlElement e = doc.DocumentElement; GofTask task = new GofTask(); task.Id = int.Parse(e.SelectSingleNode("./Id").InnerText); task.Name = e.SelectSingleNode("./Name").InnerText; task.OperationInfos = new List <OperationInfo>(); XmlNodeList list = e.SelectNodes("./OperationInfos/OperationInfo"); foreach (XmlNode item in list) { OperationInfo OperationInfo = new Geo.OperationInfo { Name = item.SelectSingleNode("./Name").InnerText, OperationName = item.SelectSingleNode("./OperationName").InnerText, DependsString = item.SelectSingleNode("./DependsString").InnerText, ParamFilePath = item.SelectSingleNode("./ParamFilePath").InnerText, }; task.OperationInfos.Add(OperationInfo); } XmlNodeList paramlist = e.SelectNodes("./Params/Param"); foreach (XmlNode item in paramlist) { var name = item.SelectSingleNode("./Name").InnerText; var content = item.SelectSingleNode("./Content").InnerText; task.Params.Add(name, content); } return(task); }
/// <summary> /// 保存 GOF 及其参数文件到本地 /// </summary> /// <param name="CurrentTask"></param> /// <returns></returns> private string SaveGofToLocal(GofTask CurrentTask) { //在此解析执行! //保存 Gof 文件,保存参数文件。执行! var name = CurrentTask.Name; if (!name.ToLower().Contains(".gof")) { name += ".gof"; } var localGofPath = Path.Combine(Setting.GnsserConfig.CurrentProject.ScriptDirectory, name); StringBuilder sb = new StringBuilder(); foreach (var oper in CurrentTask.OperationInfos) { sb.AppendLine(oper.ToString()); } File.WriteAllText(localGofPath, sb.ToString()); //保存参数文件 SaveParamToLocal(CurrentTask); return(localGofPath); }