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

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

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

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

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

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

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

                foreach (object o in lines)
                {
                    Task 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();
            }
        }
Esempio n. 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);
        }
Esempio n. 4
0
        private void TriggerCurrentEnable()
        {
            BerComputeNode curent = this.bindingSource1.Current as BerComputeNode;

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

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

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

            if (form.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                mgr.Edit(curent, this.bindingSource1.IndexOf(curent));
                mgr.Save();
                BindMain();
            }
        }
Esempio n. 8
0
        /// <summary>
        /// 监听客户端执行结果。并下载到本地。
        /// </summary>
        public void ListenClient()
        {
            while (true)
            {
                if (Stop)
                {
                    break;
                }
                try
                {
                    client = lister.AcceptTcpClient();
                }
                catch (Exception ex)
                {
                    ShowInfo(ex.Message);
                    break;
                }

                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<ComputeNode>(m => m.Enabled);
                    if (completedThreadCount + failedThreadCount == _taskCount)
                    {
                        AfterCompleted();
                    }
                    else//继续执行。
                    {
                        BerComputeNode node = ComputeNodes.Find(m => tMsg.From.Contains(m.Ip));
                        if (node != null)
                        {
                            InvokeComputeNodeTask(node);
                        }
                    }
                }
            }
        }
Esempio n. 9
0
        /// <summary>
        /// 运行客户端,调用。
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private string RunOne(BerComputeNode node)
        {
            string str = "";

            try
            {
                //列表,记录任务
                int taskIndex = ComputeNodeTaskDic[node];

                if (node.TaskCount <= taskIndex)
                {
                    return(node + " 所有任务已经执行完!");
                }

                Task 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);
        }
Esempio n. 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++)
            {
                BerComputeNode n = ComputeNodes[i];
                if (n.Enabled)
                {
                    string msg = n.ToString() + "开始执行......";
                    ShowInfo(msg);

                    InvokeComputeNodeTask(n);
                }
            }
        }
Esempio n. 11
0
        private void  除任务ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.bindingSource2.Current == null)
            {
                return;
            }

            BerComputeNode         curent1 = this.bindingSource1.Current as BerComputeNode;
            List <DataGridViewRow> rows    = Geo.Utils.DataGridViewUtil.GetSelectedRows(this.dataGridView2);

            foreach (var item in rows)
            {
                Task curent = item.DataBoundItem as Task;
                curent1.Tasks.Remove(curent);
            }

            mgr.Edit(curent1, this.bindingSource1.IndexOf(curent1));

            mgr.Save();

            BindSub();
        }