コード例 #1
0
 private void BTStart_Click(object sender, EventArgs e)
 {
     Task.Factory.StartNew(() =>
     {
         CMDProcessTool.Execute(@"java -jar " + TBJar.Text,
                                new Action <string>((s) =>
         {
             UIRs(s);
         }));
     });
 }
コード例 #2
0
        /// <summary>
        /// 根据工程设置启动服务
        /// </summary>
        /// <returns></returns>
        private void Start()
        {
            StatusUI(WorkStatus.正在启动);
            StartTime = DateTime.Now;

            //端口号是0,玩个蛋
            if (Project.Port == 0)
            {
                ToastForm.Display("启动失败", $"没有为 {Project.Name} 工程配置正儿八经的端口号", 'e', 5000);
                StatusUI(WorkStatus.启动失败);
                return;
            }
            if (!(ListTool.HasElements(Project.Versions) && Project.CurrentVersion != 0 && Project.LastVersion != 0))
            {
                //不存在版本或错误的版本(版本为0),不启动工程
                ToastForm.Display("启动失败", $"没有发现 {Project.Name} 工程的相关文件", 'e', 5000);
                StatusUI(WorkStatus.启动失败);
                return;
            }

            //存在版本,准备启动
            Task.Factory.StartNew(() =>
            {
                string cmd = $"java -jar {Project.Parameter} \"{JarFileTool.GetFilePath(Project)}\"";
                CMDProcessTool.Execute(cmd,
                                       new Action <string>((s) =>
                {
                    if (ConsoleCodeTool.IsLunchSuccess(s))
                    {
                        R.Log.i(s);
                        StatusUI(WorkStatus.启动成功);
                        Invoke(new Action(() =>
                        {
                            ToastForm.Display("启动成功", $"启动 {Project.Name} 工程成功", 'i', 5000);
                        }));
                    }

                    string log = ConsoleCodeTool.GetLogInfo(s);
                    if (!string.IsNullOrWhiteSpace(log))
                    {
                        R.Log.v(log);
                    }

                    //输出到窗口
                    if (ConsoleForm != null && !ConsoleForm.IsDisposed && ConsoleForm.Visible == true)
                    {
                        ConsoleForm.AddToQueue(s);
                    }
                }));

                if (Status == WorkStatus.启动成功 || Status == WorkStatus.端口占用 || Status == WorkStatus.正在关闭)
                {
                    StatusUI(WorkStatus.正在关闭);
                    Stop();
                }
                else
                {
                    StatusUI(WorkStatus.启动失败);
                }
            });
        }