예제 #1
0
        public static void OpenDaemon()
        {
            DirectoryInfo dir = GetDir_FromDeploy("TOEC_Daemon", false);

            if (dir != null)
            {
                FileInfo fi = new FileInfo(dir.FullName + "\\Start.bat");
                if (File.Exists(fi.FullName))
                {
                    if (!Helper_Service.Server_IsOpen("TOEC_Daemon"))
                    {
                        Process p = Process.Start(fi.FullName);
                        p.WaitForExit(15000);
                        report.Add("守护进程已经开启", "成功");
                    }
                    else
                    {
                        report.Add("守护进程已经开启", "成功");
                    }
                }
                else
                {
                    report.Error("未找到守护进程服务的Start.bat");
                }
            }
            else
            {
                report.Add("未安装守护进程");
            }
        }
예제 #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);
            }
        }