/// <summary>
        /// 获得启动程序
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private Process GetRunProcess(ApplicationRuntimeModel model)
        {
            if (model.ApplicationStatus != ApplicationStatusEnum.Stop)
            {
                throw new DeployException("应用程序尚未停止");
            }
            model.ApplicationStatus = ApplicationStatusEnum.ReadyRun;
            string           startArgs        = GetStartArgs(model.ApplicationInfo);
            ProcessStartInfo processStartInfo = ProcessManager.GetProcessStartInfo("dotnet.exe", !string.IsNullOrWhiteSpace(startArgs) ? startArgs : "");
            var result = new Process {
                StartInfo = processStartInfo
            };

            void DataHandler(object sender, DataReceivedEventArgs e)
            {
                model.ConsoleMessage.Add(e.Data);
            }

            result.OutputDataReceived += DataHandler;
            result.ErrorDataReceived  += DataHandler;
            if (result.Start())
            {
                result.BeginOutputReadLine();
                result.BeginErrorReadLine();
            }
            else
            {
                model.ApplicationStatus = ApplicationStatusEnum.Error;
                throw new DeployException("启动失败");
            }
            model.ApplicationStatus = ApplicationStatusEnum.Runing;
            model.ClearConsoleMessageTimer.Start();
            return(result);
        }
 public override void KillProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.DotNetCore)
     {
         Process[] processes      = Process.GetProcessesByName("dotnet");
         var       currentProcess = Process.GetCurrentProcess();
         foreach (Process process in processes)
         {
             if (currentProcess.Id == process.Id)
             {
                 return;
             }
             if (process.Modules.Cast <ProcessModule>().Any(processModule => processModule.ModuleName == model.ApplicationInfo.MainModule))
             {
                 KillProcess(process);
             }
         }
         return;
     }
     if (_next == null)
     {
         throw new DeployException("未识别应用程序类型");
     }
     _next.KillProcess(model);
 }
 public override Process GetProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.DotNetCore)
     {
         return(GetRunProcess(model));
     }
     if (_next != null)
     {
         return(_next.GetProcess(model));
     }
     throw new DeployException("未识别应用程序类型");
 }
 public override void KillProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.StaticDocument)
     {
         return;
     }
     if (_next == null)
     {
         throw new DeployException("未识别应用程序类型");
     }
     _next.KillProcess(model);
 }
 public override void KillProcess(ApplicationRuntimeModel model, Process process)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.DotNetCore)
     {
         KillProcess(process);
         return;
     }
     if (_next == null)
     {
         throw new DeployException("未识别应用程序类型");
     }
     _next.KillProcess(model, process);
 }
Example #6
0
 public override Process GetProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.Exe)
     {
         Task <Process> task = GetRunProcessAsync(model);
         Task.WaitAll(task);
         return(task.Result);
     }
     if (_next != null)
     {
         return(_next.GetProcess(model));
     }
     throw new DeployException("未识别应用程序类型");
 }
 public override Process GetProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.StaticDocument)
     {
         model.ApplicationStatus = ApplicationStatusEnum.Runing;
         model.ConsoleMessage.Add($"网站[{model.ApplicationInfo.Name}]已启动:{ApplicationConfig.Url}/{model.ApplicationInfo.Path}/{model.ApplicationInfo.MainModule}");
         return(null);
     }
     if (_next != null)
     {
         return(_next.GetProcess(model));
     }
     throw new DeployException("未识别应用程序类型");
 }
 public override void KillProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.PM2)
     {
         var  cmdManager = new CmdManager();
         Task task       = cmdManager.RunCmdCommandsAsync($"pm2 delete {model.ApplicationInfo.MainModule}");
         Task.WaitAll(task);
         return;
     }
     if (_next == null)
     {
         throw new DeployException("未识别应用程序类型");
     }
     _next.KillProcess(model);
 }
Example #9
0
 public override void KillProcess(ApplicationRuntimeModel model)
 {
     if (model.ApplicationInfo.ApplicationType == ApplicationTypeEnum.Exe)
     {
         string    fileName  = Path.GetFileName(model.ApplicationInfo.MainModule);
         Process[] processes = Process.GetProcessesByName(fileName);
         foreach (Process process in processes)
         {
             KillProcess(process);
         }
         return;
     }
     if (_next == null)
     {
         throw new DeployException("未识别应用程序类型");
     }
     _next.KillProcess(model);
 }
Example #10
0
        /// <summary>
        /// 获得启动程序
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        private async Task <Process> GetRunProcessAsync(ApplicationRuntimeModel model)
        {
            if (model.ApplicationStatus != ApplicationStatusEnum.Stop)
            {
                throw new DeployException("应用程序尚未停止");
            }
            model.ApplicationStatus = ApplicationStatusEnum.ReadyRun;
            ProcessStartInfo processStartInfo = ProcessManager.GetProcessStartInfo("cmd.exe", string.Empty);
            var result = new Process {
                StartInfo = processStartInfo
            };

            void DataHandler(object sender, DataReceivedEventArgs e)
            {
                model.ConsoleMessage.Add(e.Data);
            }

            result.OutputDataReceived += DataHandler;
            result.ErrorDataReceived  += DataHandler;
            if (result.Start())
            {
                result.BeginOutputReadLine();
                result.BeginErrorReadLine();
                IEnumerable <string> commands = GetCommands(model.ApplicationInfo);
                foreach (string command in commands)
                {
                    await result.StandardInput.WriteLineAsync(command);
                }
            }
            else
            {
                model.ApplicationStatus = ApplicationStatusEnum.Error;
                throw new DeployException("启动失败");
            }
            model.ApplicationStatus = ApplicationStatusEnum.Runing;
            model.ClearConsoleMessageTimer.Start();
            return(result);
        }
Example #11
0
 /// <summary>
 /// 杀死程序
 /// </summary>
 /// <param name="model"></param>
 /// <param name="process"></param>
 public abstract void KillProcess(ApplicationRuntimeModel model, Process process);
Example #12
0
 /// <summary>
 /// 获取启动程序
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public abstract Process GetProcess(ApplicationRuntimeModel model);