Esempio n. 1
0
        /// <summary>
        /// 安装软件
        /// 流程:解压 修改配置文件
        /// 适用:数据库\服务\应用程序\网络站点
        /// </summary>
        /// <param name="stnm"></param>
        /// <param name="tcode"></param>
        /// <param name="ip"></param>
        /// <returns></returns>
        protected bool Install(string stnm, string tcode, string ip)
        {
            try
            {
                //解压
                report.Add("解压缩...");
                FileInfo fi_zip = GetZipFile_FromSource(name);
                if (fi_zip == null)
                {
                    return(false);
                }
                Helper_Zip.UnZip(fi_zip.FullName, dir_deploy.FullName, "", true);

                //获取具体软件部署目录
                DirectoryInfo dir_soft = GetDir_FromDeploy(name);

                //修改配置文件
                if (list_mx.Count > 0)
                {
                    report.Add("修改配置文件...");
                    foreach (modify_xml mx in list_mx)
                    {
                        try
                        {
                            if (string.IsNullOrWhiteSpace(mx.innerText))
                            {
                                Helper_XML.ModifyAttr_ByID(dir_soft.FullName + "\\" + mx.path,
                                                           mx.id,
                                                           mx.attr,
                                                           mx.value.Replace("@TelexCode", tcode).Replace("@IP", ip),
                                                           mx.encode);
                                report.Add("【" + mx.path + "】id:" + mx.id + "的属性" + mx.attr + "置为" + mx.value.Replace("@TelexCode", tcode).Replace("@IP", ip), "成功");
                            }
                            else
                            {
                                Helper_XML.ModifyText_ByID(dir_soft.FullName + "\\" + mx.path,
                                                           mx.id,
                                                           mx.innerText.Replace("@TelexCode", tcode).Replace("@IP", ip),
                                                           mx.encode);
                                report.Add("【" + mx.path + "】id:" + mx.id + "的InnerText置为" + mx.innerText.Replace("@TelexCode", tcode).Replace("@IP", ip), "成功");
                            }
                        }
                        catch (Exception ex)
                        {
                            report.Error(mx.path, ex);
                            continue;
                        }
                    }
                }

                //获取新版本号
                FileInfo exe_new = GetFile_FromDeploy(name);
                if (exe_new != null)
                {
                    report.Add("新版本:" + Common_Handle.GetExeVersion(exe_new.FullName));
                }

                return(true);
            }
            catch (Exception e)
            {
                report.Error(comment + "安装[解压+修改配置文件]异常", e);
                return(false);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// 升级
        /// </summary>
        /// <returns></returns>
        private bool Update()
        {
            try
            {
                //检查服务是否正常
                if (Helper_Service.Server_IsOpen(name))
                {
                    report.Add("检测到数据库服务正常,准备执行脚本");
                }
                else
                {
                    report.Add("检测到数据库服务未启动,尝试启动");
                    if (Helper_Service.Server_Open(name))
                    {
                        report.Add("启动成功");
                    }
                    else
                    {
                        report.Error("启动失败"); return(false);
                    }
                }
                //备份
                if (!Backup(name))
                {
                    return(false);
                }

                //找到压缩包
                FileInfo zip = GetZipFile_FromSource(name_sql);
                if (zip == null)
                {
                    return(false);
                }

                //解压缩 至 源目录
                report.Add("解压缩...");
                if (Helper_Zip.UnZip(zip.FullName, dir_source.FullName, "", true))
                {
                    report.Add("脚本解压成功");
                }
                else
                {
                    report.Error("脚本解压失败"); return(false);
                }

                //执行脚本
                DirectoryInfo SQLDir = new DirectoryInfo(zip.FullName.TrimEnd(".zip".ToCharArray()));
                if (Directory.Exists(SQLDir.FullName))
                {
                    //获去当前数据库版本号
                    string dbv = GetDBVersion(con);
                    if (!string.IsNullOrWhiteSpace(dbv))
                    {
                        report.Add("数据库当前版本:" + dbv);
                        foreach (FileInfo s in SQLDir.GetFiles("*.sql"))
                        {
                            try
                            {
                                string BatVersion = Path.GetFileNameWithoutExtension(s.FullName).ToUpper().Replace("UPDATE_", "").Split("_".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)[0];
                                if (long.Parse(BatVersion) > long.Parse(dbv))
                                {
                                    string ErrorInfo = ExecSQLFile(s.FullName, con);
                                    if (ErrorInfo != "")
                                    {
                                        report.Error(s.Name + "【" + ErrorInfo + "】");
                                    }
                                    else
                                    {
                                        report.Add(s.Name, "成功");
                                    }
                                }
                            }
                            catch (Exception ex) { report.Error("【执行异常】" + s.Name, ex); continue; }
                        }
                    }
                    else
                    {
                        report.Error("无法获取当前数据库版本");
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                report.Error("数据库升级异常", e);
                return(false);
            }
        }