public static async Task Main() { const string path = @"E:\Project\Materal\Application\Materal.APP\Deploy.Server\Application\template\Start.cmd"; var cmdManager = new CmdManager(); cmdManager.OutputDataReceived += CmdManager_OutputDataReceived; cmdManager.ErrorDataReceived += CmdManager_ErrorDataReceived; //await cmdManager.RunCmdCommandsAsync("E:", @"cd Project\Materal\Application\Materal.APP\Deploy.Server\Application\template", "npm run deploy"); await cmdManager.RunCmdCommandsAsync("E:", @"cd Project\Materal\Application\Materal.APP\Deploy.Server\Application\template", "echo Hello World"); await cmdManager.RunCmdCommandsAsync("echo Hello World"); Console.ReadKey(); }
/// <summary> /// 更新APP文件 /// </summary> /// <param name="model"></param> /// <returns></returns> private async Task UpdateAppFileAsync(UpdateAppFileModel model) { var appManager = ApplicationService.GetService <IAppService>(); string tempPath = Path.Combine(model.WorkingDirectory, $"Temp/{StringManager.GetRandomStrByGuid()}"); DirectoryInfo tempDirectoryInfo = null; if (!Directory.Exists(tempPath)) { tempDirectoryInfo = Directory.CreateDirectory(tempPath); } tempDirectoryInfo ??= new DirectoryInfo(tempPath); var cmdManager = new CmdManager(); string winRarCmd = Path.Combine(ApplicationConfig.WinRarPath, "UnRAR.exe"); await cmdManager.RunCmdCommandsAsync($"\"{winRarCmd}\" x -o+ -y {model.FilePath} {tempPath}"); DirectoryInfo[] directoryInfos = tempDirectoryInfo.GetDirectories(); string[] paths = directoryInfos.Select(m => m.Name).ToArray(); appManager.StopAppByPaths(paths); foreach (DirectoryInfo directoryInfo in directoryInfos) { try { string dirPath = Path.Combine(model.WorkingDirectory, directoryInfo.Name); CopyDirectory(directoryInfo, dirPath); } finally { directoryInfo.Delete(true); } } tempDirectoryInfo.Delete(true); }
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); }
/// <summary> /// 更新APP文件 /// </summary> /// <param name="path"></param> /// <param name="channel"></param> /// <returns></returns> private async Task UpdateAppFileAsync(string path, IChannel channel) { var appManager = ApplicationData.GetService <IAppManager>(); string tempPath = $"{workingDirectory}Temp/{StringManager.GetRandomStrByGuid()}"; DirectoryInfo tempDirectoryInfo = null; if (!Directory.Exists(tempPath)) { tempDirectoryInfo = Directory.CreateDirectory(tempPath); } if (tempDirectoryInfo == null) { tempDirectoryInfo = new DirectoryInfo(tempPath); } var cmdManager = new CmdManager(); await cmdManager.RunCmdCommandsAsync($"unrar x -o+ -y {path} {tempPath}"); DirectoryInfo[] directoryInfos = tempDirectoryInfo.GetDirectories(); string[] paths = directoryInfos.Select(m => m.Name).ToArray(); appManager.StopAppByPaths(paths); foreach (DirectoryInfo directoryInfo in directoryInfos) { try { string dirPath = $"{workingDirectory}{directoryInfo.Name}"; CopyDirectory(directoryInfo, dirPath); } catch (Exception ex) { var @event = new ServerErrorEvent { Status = 500, Message = ex.Message }; await channel.SendJsonEventAsync(@event); } finally { directoryInfo.Delete(true); } } tempDirectoryInfo.Delete(true); }
/// <summary> /// 更新APP文件 /// </summary> /// <param name="path"></param> /// <param name="channel"></param> /// <returns></returns> private async Task UpdateWebFileAsync(string path, IChannel channel) { var fileService = ApplicationData.GetService <IWebFileService>(); string tempPath = $"{AppDomain.CurrentDomain.BaseDirectory}Temp/{StringManager.GetRandomStrByGuid()}"; DirectoryInfo tempDirectoryInfo = null; if (!Directory.Exists(tempPath)) { tempDirectoryInfo = Directory.CreateDirectory(tempPath); } if (tempDirectoryInfo == null) { tempDirectoryInfo = new DirectoryInfo(tempPath); } var cmdManager = new CmdManager(); await cmdManager.RunCmdCommandsAsync($"unrar x -o+ -y {path} {tempPath}"); DirectoryInfo[] directoryInfos = tempDirectoryInfo.GetDirectories(); foreach (DirectoryInfo directoryInfo in directoryInfos) { try { string targetPath = $"{workingDirectory}{directoryInfo.Name}"; CopyDirectory(directoryInfo, targetPath); fileService.InitServices(); } catch (Exception ex) { var @event = new ServerErrorEvent { Status = 500, Message = ex.Message }; await channel.SendJsonEventAsync(@event); } finally { directoryInfo.Delete(true); } } tempDirectoryInfo.Delete(true); }