Example #1
0
        private void  择计算任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (tasks == null)
            {
                MessageBox.Show("请先设置任务名称!"); return;
            }
            GofComputeNode curent = this.bindingSource1.Current as GofComputeNode;

            if (curent == null)
            {
                MessageBox.Show("请先选中任务!"); return;
            }
            Geo.Winform.Controls.ListItemSelecterForm form =
                new Geo.Winform.Controls.ListItemSelecterForm(tasks.ToArray());

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                curent.Tasks.Clear();

                foreach (object o in form.SelectedItems)
                {
                    curent.Tasks.Add(o as GofTask);
                }

                mgr.Edit(curent, this.bindingSource1.IndexOf(curent));
                mgr.Save();
                BindSub();
            }
        }
Example #2
0
        private void 手动输入任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GofComputeNode curent = this.bindingSource1.Current as GofComputeNode;

            if (curent == null)
            {
                MessageBox.Show("请先选中任务!"); return;
            }

            string[] lines;
            if (Geo.Utils.FormUtil.ShowInputLineForm("输入行", out lines))
            {
                curent.Tasks.Clear();

                foreach (object o in lines)
                {
                    var task = tasks.Find(m => m.Name == o.ToString() || m.Id == int.Parse(o.ToString()));
                    curent.Tasks.Add(task);
                }

                mgr.Edit(curent, this.bindingSource1.IndexOf(curent));
                mgr.Save();
                BindSub();
            }
        }
Example #3
0
        /// <summary>
        /// 解析XML
        /// </summary>
        /// <param name="ComputeNodeFilePath"></param>
        /// <param name="TaskFilePath"></param>
        /// <returns></returns>
        public static List <GofComputeNode> LoadGofComputeNodes(string ComputeNodeFilePath, string TaskFilePath)
        {
            XmlDocument doc = new XmlDocument();

            doc.Load(ComputeNodeFilePath);

            var tasks = new GofTaskMgr(TaskFilePath).GetAllTasks();

            List <GofComputeNode> list = new List <GofComputeNode>();

            foreach (XmlNode item in doc.DocumentElement.ChildNodes)
            {
                GofComputeNode node = new GofComputeNode();
                node.Id      = int.Parse(item.SelectSingleNode("./Id").InnerText);
                node.Name    = item.SelectSingleNode("./Name").InnerText;
                node.Ip      = item.SelectSingleNode("./IP").InnerText;
                node.Port    = int.Parse(item.SelectSingleNode("./Port").InnerText);
                node.Enabled = Boolean.Parse(item.SelectSingleNode("./Enabled").InnerText);

                List <int> taskId = BerComputeNode.ParseTaskIdsString(item.SelectSingleNode("./TaskId").InnerText);
                try
                {
                    node.Tasks = tasks.FindAll(m => taskId.Contains(m.Id));
                }
                catch (Exception ex) { MessageBox.Show(ex.Message); }

                list.Add(node);
            }
            return(list);
        }
Example #4
0
        private void TriggerCurrentEnable()
        {
            GofComputeNode curent = this.bindingSource1.Current as GofComputeNode;

            curent.Enabled = !curent.Enabled;
            mgr.Edit(curent, this.bindingSource1.IndexOf(curent));
            mgr.Save();
            BindMain();
        }
Example #5
0
        private void BindSub()
        {
            GofComputeNode curent = this.bindingSource1.Current as GofComputeNode;

            if (curent != null)
            {
                this.bindingSource2.DataSource = null;
                this.bindingSource2.DataSource = curent.Tasks;
            }
        }
        /// <summary>
        /// 异步执行节点任务
        /// </summary>
        /// <param name="north"></param>
        private void InvokeComputeNodeTask(GofComputeNode n)
        {
            RunGofNodeDelegate runNode = RunOne;

            runNode.BeginInvoke(n, ar =>
            {// 380, 120
                string response = runNode.EndInvoke(ar);
                ShowInfo(n.ToString() + "返回信息:" + response);
            }, runNode);
        }
Example #7
0
        private void 修改计算节点ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GofComputeNode      curent = this.bindingSource1.Current as GofComputeNode;
            ComputeNodeEditForm form   = new ComputeNodeEditForm(curent);

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mgr.Edit(curent, this.bindingSource1.IndexOf(curent));
                mgr.Save();
                BindMain();
            }
        }
        /// <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>
        /// 运行客户端,调用。
        /// </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);
        }
Example #10
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            ShowInfo("开始工作....");
            watch.Restart();

            //统计有多少个任务
            _taskCount = 0;
            foreach (var item in ComputeNodes)
            {
                if (item.Enabled)
                {
                    _taskCount += item.TaskCount;
                }
            }

            //清零工作记录列表
            foreach (var node in ComputeNodes)
            {
                if (node.Enabled)
                {
                    if (!ComputeNodeTaskDic.ContainsKey(node))
                    {
                        ComputeNodeTaskDic.Add(node, 0);
                    }
                    else
                    {
                        ComputeNodeTaskDic[node] = 0;
                    }
                }
            }


            //首次分配任务
            for (int i = 0; i < ComputeNodes.Count; i++)
            {
                GofComputeNode n = ComputeNodes[i];
                if (n.Enabled)
                {
                    string msg = n.ToString() + "开始执行......";
                    ShowInfo(msg);

                    InvokeComputeNodeTask(n);
                }
            }
        }
Example #11
0
        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();
        }