Exemplo n.º 1
0
        //构造函数
        public MainService()
        {
            //参数初始化
            ServerIP =ConfigHelper.ReadParameter("ServerIP");
            MainFolder = ConfigHelper.ReadParameter("MainFolder");
            string connstr = "server=" + ServerIP+ ";database=MonoGrid;user=root;pwd=123456;";
            conn = new MySqlConnection(connstr);
            mg = new MonoGrid(conn);

            try
            {
                molDiv = int.Parse(mg.Parameter.First(p => p.PnAme == "molDiv").PvAlue);
            }
            catch
            {
                ConsoleHelper.Warn("数据库配置出错,未能获取系统参数!");
                throw new Exception("数据库配置出错,未能获取系统参数!");
            }

            //初始化Node
            localNode = NodeHelper.InitNode(mg);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 初始化Node
        /// </summary>
        /// <param name="mg">数据库DataContext</param>
        /// <returns>初始化后的本地Node</returns>
        public static Node InitNode(MonoGrid mg)
        {
            string Ip = NodeHelper.GetIP();
            if (Ip == "error")
            {
                ConsoleHelper.Warn("获取IP失败,请检查网络情况!");
            }
            Node tempNode = null;
            try
            {
                tempNode = mg.Node.First(n => n.Ip == Ip);
                //tempNode.CpuUse = (int)(NodeHelper.GetCpuUsage() * 100f);
                //tempNode.UpdateTime = DateTime.Now;
                tempNode.Status = 0;
            }
            catch
            {
                tempNode = new Node();
                tempNode.Ip = Ip;
                tempNode.DockFolder = ConfigHelper.ReadParameter("DockFolder");
                tempNode.CpuIntro = NodeHelper.GetCPUInfo();
                tempNode.UpdateTime = DateTime.Now;

                mg.Node.InsertOnSubmit(tempNode);
            }
            finally
            {
                if (!FileHelper.CheckDock(tempNode.DockFolder))
                {
                    ConsoleHelper.Warn("本地Dock程序异常!");
                    throw new Exception("本地Dock程序异常!");
                }
                mg.SubmitChanges();
            }
            tempNode = mg.Node.First(n => n.Ip == Ip);
            return tempNode;
        }