Exemplo n.º 1
0
        private Result DoIIS(string appId, string fileName, HttpPostedFileBase fileInfo)
        {
            string newVersionPath = appId.CopyIISAppToNewDir();
            string zipPath        = Path.Combine(newVersionPath, fileName);

            fileInfo.SaveAs(zipPath);

            // 复制一份压缩包到本网站目录,部署外网的时候就直接从网站目录里面拿取压缩包了。
            string zipBackDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipFiles");

            if (!Directory.Exists(zipBackDir))
            {
                Directory.CreateDirectory(zipBackDir);
            }
            string zipBackPath = Path.Combine(zipBackDir, fileName);

            fileInfo.SaveAs(zipBackPath);
            SettingLogic.SetAppZipFilePath($"IIS-{appId}", zipBackPath);

            ZipHelper.UnZip(zipPath, Directory.GetParent(zipPath).FullName);
            var changeRes = appId.ChangeIISAppVersion(newVersionPath);

            return(changeRes);
        }
Exemplo n.º 2
0
        private Result DoExe(string appId, string fileName, HttpPostedFileBase fileInfo)
        {
            Result res = new Result();

            try
            {
                var allProcesses = Process.GetProcesses();

                // 读取进程守护信息
                string   mgeProcessFileName    = SettingLogic.GetMgeProcessFullName();
                string   processMgeXmlFullName = Path.Combine(Directory.GetParent(mgeProcessFileName).FullName, "ProcessInfo.xml");
                XElement element       = XElement.Load(processMgeXmlFullName);
                var      appProcessXml = element.Elements().FirstOrDefault(n => n.Attribute("ID")?.Value == appId);
                if (appProcessXml == null)
                {
                    throw new Exception("该进程未纳入到守护进程中,无法自动部署");
                }

                var appProcess = allProcesses.FirstOrDefault(n => n.Id.ToString() == appProcessXml.Attribute("PID").Value);
                if (appProcess == null)
                {
                    throw new Exception("未找到该进程");
                }
                string appFullPath = appProcess.MainModule.FileName;
                string appPath     = Directory.GetParent(appFullPath).FullName;
                string newAppPath  = appPath.AddVersion();
                string zipPath     = Path.Combine(newAppPath, fileName);
                appPath.CopyDirectoryTo(newAppPath);
                fileInfo.SaveAs(zipPath);

                // 复制一份压缩包到本网站目录,部署外网的时候就直接从网站目录里面拿取压缩包了。
                string zipBackDir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ZipFiles");
                if (!Directory.Exists(zipBackDir))
                {
                    Directory.CreateDirectory(zipBackDir);
                }
                string zipBackPath = Path.Combine(zipBackDir, fileName);
                fileInfo.SaveAs(zipBackPath);
                SettingLogic.SetAppZipFilePath($"EXE-{appId}", zipBackPath);

                ZipHelper.UnZip(zipPath, Directory.GetParent(zipPath).FullName);

                // 关闭进程守护
                var mgeProcess = allProcesses.FirstOrDefault(n => String.Equals(n.ProcessName, "ProcessManageApplication", StringComparison.CurrentCultureIgnoreCase));
                mgeProcess?.Kill();

                // 更新版本号
                appProcessXml.Attribute("Path").Value = newAppPath;
                element.Save(processMgeXmlFullName);

                // 关闭源程序
                appProcess.Kill();

                // 启动进程守护
                Process.Start(mgeProcessFileName);

                res.IsSucceed = true;
            }
            catch (Exception e)
            {
                TxtLogService.WriteLog(e, "切换exe版本异常,信息:" + new { appId, fileName }.SerializeObject());
                res.Message = e.Message;
            }

            return(res);
        }