Ejemplo n.º 1
0
        public override void Deploy(string stnm, string tcode, string ip)
        {
            bool flag = false;

            try
            {
                //进程是否存在
                if (Helper_Process.CheckProcessExists(name) || GetDir_FromDeploy(name, false) != null)
                {
                    //升级
                    report.Add(comment + "升级...");
                    //关闭程序
                    if (!Helper_Process.KillProcess(name))
                    {
                        report.Error(name + "程序关闭失败");
                    }
                    else
                    {
                        report.Add(name + "程序已关闭");
                        //开始升级
                        flag = Update(stnm, tcode, ip);
                    }
                }
                else
                {
                    //安装
                    report.Add(comment + "安装...");
                    flag = Install(stnm, tcode, ip);//安装
                }

                //部署后自动开启
                if (AutoStart)
                {
                    FileInfo fi_start = GetFile_FromDeploy(name);
                    if (fi_start != null && File.Exists(fi_start.FullName))
                    {
                        Process.Start(fi_start.FullName);
                        report.Add(name + "已开启");
                    }
                    else
                    {
                        report.Add(fi_start.FullName + "未找到");
                    }
                }
            }
            catch (Exception e)
            {
                report.Error("部署" + comment + "异常", e);
            }
            finally
            {
                report.Add("部署-" + comment, flag ? "成功" : "失败");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 删除老旧服务
        /// 特殊处理老旧的服务
        /// </summary>
        public static bool Delete_Old_Software()
        {
            string[] old_name = Config.GetAppConfig("del_process").Split(',');

            foreach (var old in old_name)
            {
                if (Helper_Process.CheckProcessExists(old))//检测进程
                {
                    report.Add("检测到老旧版本【" + old + "】");
                    FileInfo      fi   = new FileInfo(Process.GetProcessesByName(old)[0].MainModule.FileName);//通过进程获取文件位置
                    DirectoryInfo dir  = new DirectoryInfo(fi.DirectoryName);
                    FileInfo      stop = new FileInfo(dir.FullName + "\\Stop.bat");
                    if (File.Exists(stop.FullName))
                    {
                        try
                        {
                            Process p = Process.Start(stop.FullName);
                            p.WaitForExit(15000);
                        }
                        catch (Exception ex)
                        {
                            report.Error("卸载服务异常" + old, ex); return(false);
                        }
                    }
                    else
                    {
                        report.Error("未找到老服务Stop.bat文件");
                    }
                    Thread.Sleep(5000);

                    //检查进程:进程名称与exe名称一致
                    if (Helper_Process.CheckProcessExists(old))
                    {
                        if (Helper_Process.KillProcess(old))
                        {
                            report.Add("进程已经被强制结束");
                        }
                        else
                        {
                            report.Error("进程强制结束失败"); return(false);
                        }
                    }
                    dir.Delete(true);
                    report.Add("【" + old + "】已卸载", "成功");
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 部署
        /// </summary>
        /// <param name="stnm"></param>
        /// <param name="tcode"></param>
        /// <param name="ip"></param>
        public override void Deploy(string stnm, string tcode, string ip)
        {
            bool flag = false;

            try
            {
                //特殊处理:清理老版不规范的服务
                Delete_Old_Software();

                //判断服务是否存在
                if (Helper_Service.Service_IsExisted(name))
                {
                    #region 升级
                    report.Add(comment + "升级...");
                    if (!Helper_Service.Server_Close(name)) //先关闭服务
                    {
                        report.Error(name + "服务关闭失败");
                    }
                    else
                    {
                        Thread.Sleep(5000);
                        report.Add(name + "服务已关闭");

                        report.Add("检查残留进程...");
                        if (Helper_Process.CheckProcessExists(name))
                        {
                            if (Helper_Process.KillProcess(name))
                            {
                                report.Add("进程已经被强制结束");
                            }
                            else
                            {
                                report.Error("进程强制结束失败");
                            }
                        }
                        flag = Update(stnm, tcode, ip);
                    }
                    #endregion
                }
                else
                {
                    //安装
                    report.Add(comment + "安装...");
                    flag = Install(stnm, tcode, ip);//安装
                }

                //部署后自动开启
                if (AutoStart)
                {
                    DirectoryInfo dir = GetDir_FromDeploy(name);
                    if (dir != null)
                    {
                        FileInfo fi_start = new FileInfo(dir.FullName + "\\Start.bat");
                        if (File.Exists(fi_start.FullName))
                        {
                            Process.Start(fi_start.FullName);
                            report.Add(name + "已开启");
                        }
                        else
                        {
                            report.Add(fi_start.FullName + "未找到");
                        }
                    }
                }
            }
            catch (Exception e)
            {
                report.Error("部署" + comment + "异常", e);
            }
            finally
            {
                report.Add("部署-" + comment, flag ? "成功" : "失败");
            }
        }