Beispiel #1
0
        /// <summary>
        /// 检查是否是任务计划操作
        /// </summary>
        /// <param name="projectAction"></param>
        /// <returns></returns>
        private bool CheckSchTaskOperate(DepProjectAction projectAction)
        {
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);

            return(!string.IsNullOrEmpty(projectItem.ExcludeFile) &&
                   projectItem.ExcludeFile.EndsWith(".exe"));
        }
Beispiel #2
0
        /// <summary>
        /// 回收IIS应用程序池
        /// </summary>
        /// <param name="projectAction"></param>
        /// <param name="iisVersion"></param>
        private void RecycleIISPool(DepProjectAction projectAction, IIsVersion iisVersion)
        {
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);
            string         strOutput;

            IISHelper.GetIIS(iisVersion, projectItem.WebSite).RecycleAppPool(out strOutput);
            SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, strOutput);
        }
Beispiel #3
0
        /// <summary>
        /// 开启计划任务
        /// </summary>
        /// <param name="projectAction"></param>
        private void StartSchTasks(DepProjectAction projectAction)
        {
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);
            string         strOutput   = SchTasksOperate.StartRun(projectItem.WebSite);

            Logger.SaveLog(strOutput);
            SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, strOutput);
        }
Beispiel #4
0
 private bool GetSchTasks(string[] ids)
 {
     if (ids.Length > 0)
     {
         var item = SvnProcesser.ProjectItem(int.Parse(ids[0]));
         if (item != null && !string.IsNullOrEmpty(item.ExcludeFile))
         {
             return(true);
         }
     }
     return(false);
 }
Beispiel #5
0
        private void QuickDeploy(DepProjectAction projectAction, IIsVersion iisVersion)
        {
            //停止IIS
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);

            if (CheckSchTaskOperate(projectAction))
            {
                DoSchTaskQuickDeploy(projectAction, projectItem);
            }
            else
            {
                DoIIsQuickDeploy(projectAction, iisVersion, projectItem);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 创建任务计划
        /// </summary>
        /// <param name="projectAction"></param>
        private void CreateSchTasks(DepProjectAction projectAction)
        {
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);
            string         targetPath  = string.Empty;

            targetPath = projectItem.DeployPath.Replace("/", @"\");
            if (targetPath.IndexOf(":") == -1)
            {
                targetPath = CommandExeHelper.CombineDir(DEPLOY_ROOT, targetPath);
            }
            targetPath = CommandExeHelper.CombineDir(targetPath, projectItem.ExcludeFile);
            string strOutput = SchTasksOperate.Create(projectItem.WebSite, targetPath);

            Logger.SaveLog(strOutput);
            SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, strOutput);
        }
Beispiel #7
0
        /// <summary>
        /// 清理SVN
        /// </summary>
        /// <param name="projectAction"></param>
        private void Cleanup(DepProjectAction projectAction)
        {
            DepProjectItem projectItem  = SvnProcesser.ProjectItem(projectAction.DepId);
            DepProject     depProject   = SvnProcesser.Project(projectItem.DepId);
            string         checkOutPath = Path.Combine(SVN_UPDATE_ROOT, depProject.Id.ToString());
            string         svnArguments = string.Format(
                "cleanup {0} --username {1} --password {2} --no-auth-cache --non-interactive --trust-server-cert",
                checkOutPath,
                SVN_USER,
                SVN_PASSWORD
                );

            Logger.SaveLog(string.Format("SvnDeploy执行svn.exe {0}", svnArguments));
            string strOutput = CommandExeHelper.Run("svn.exe", svnArguments);

            if (string.IsNullOrEmpty(strOutput))
            {
                strOutput = "cleanup end.";
            }
            SvnProcesser.UpdateDeployStatus(projectAction.Id, 1, strOutput);
        }
Beispiel #8
0
        /// <summary>
        /// 部署Python脚本
        /// </summary>
        /// <param name="projectAction"></param>
        private bool DeployPython(DepProjectAction projectAction)
        {
            string         msg         = "";
            bool           result      = true;
            string         pythonPath  = ConfigHelper.GetSetting("DEPLOY_Python_Path", "PyScript");
            DepProjectItem projectItem = SvnProcesser.ProjectItem(projectAction.DepId);
            DepProject     project     = SvnProcesser.Project(projectItem.DepId);
            //目标路径
            string targetPath = projectItem.DeployPath.Replace("/", @"\");

            if (targetPath.IndexOf(":") == -1)
            {
                targetPath = CommandExeHelper.CombineDir(DEPLOY_ROOT, targetPath);
                //Python目录
                targetPath = CommandExeHelper.CombineDir(targetPath, pythonPath);
            }
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            string checkSharePath = CommandExeHelper.CombineDir(SVN_UPDATE_ROOT, project.Id.ToString());

            checkSharePath = CommandExeHelper.CombineDir(checkSharePath, project.SharePath);
            //Python目录
            checkSharePath = CommandExeHelper.CombineDir(checkSharePath, pythonPath);

            string exclude = "";//string.IsNullOrEmpty(project.ExcludeFile) ? "" : string.Format("/xf {0}", project.ExcludeFile);
            //更新共享的目录,如Code目录
            string robarguments = string.Format("{0} {1} /MIR {2}", checkSharePath, targetPath, exclude);

            Logger.SaveLog(string.Format("SvnDeploy Python shared directory robocopy.exe {0}", robarguments));
            msg += CommandExeHelper.Run("robocopy.exe", robarguments);

            SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, msg);
            return(result);
        }
Beispiel #9
0
        private bool DoDeploy(DepProjectAction projectAction, ref string msg)
        {
            bool           result         = true;
            DepProjectItem projectItem    = SvnProcesser.ProjectItem(projectAction.DepId);
            DepProject     project        = SvnProcesser.Project(projectItem.DepId);
            string         checkSharePath = CommandExeHelper.CombineDir(SVN_UPDATE_ROOT, project.Id.ToString());
            string         targetPath     = string.Empty;

            targetPath = projectItem.DeployPath.Replace("/", @"\");
            if (targetPath.IndexOf(":") == -1)
            {
                targetPath = CommandExeHelper.CombineDir(DEPLOY_ROOT, targetPath);
            }
            if (!Directory.Exists(targetPath))
            {
                Directory.CreateDirectory(targetPath);
            }
            if (!string.IsNullOrEmpty(project.SharePath.Trim()))
            {
                checkSharePath = CommandExeHelper.CombineDir(checkSharePath, project.SharePath);

                string exclude = "";//string.IsNullOrEmpty(project.ExcludeFile) ? "" : string.Format("/xf {0}", project.ExcludeFile);
                //更新共享的目录,如Code目录
                string robarguments = string.Format("{0} {1} /MIR {2}", checkSharePath, targetPath, exclude);
                Logger.SaveLog(string.Format("SvnDeploy shared directory robocopy.exe {0}", robarguments));
                msg += CommandExeHelper.Run("robocopy.exe", robarguments);
            }

            //差异目录,如天界行1服目录下的Web.Config文件
            string checkOutPath = CommandExeHelper.CombineDir(SVN_UPDATE_ROOT, project.Id.ToString());

            checkOutPath = CommandExeHelper.CombineDir(checkOutPath, projectItem.Name);
            bool isExist = Directory.Exists(checkOutPath);

            if (isExist)
            {
                //合并Debug与Release目录文件
                string arguments = string.Empty;
                if (IsRelease)
                {
                    arguments = string.Format("{0} {1} /e/y", checkOutPath, targetPath);
                }
                else
                {
                    arguments = string.Format("{0} {1} /e/y", Path.Combine(checkOutPath, "Debug"), targetPath);
                }

                Logger.SaveLog(string.Format("SvnDeploy differences in directory xcopy.exe {0}", arguments));
                msg += CommandExeHelper.Run("xcopy.exe", arguments);
            }
            //支持以前目录结构
            else if (string.IsNullOrEmpty(project.SharePath.Trim()))
            {
                checkOutPath = CommandExeHelper.CombineDir(SVN_UPDATE_ROOT, project.Id.ToString());
                string arguments = string.Format("{0} {1} /e/y", checkOutPath, targetPath);
                Logger.SaveLog(string.Format("SvnDeploy old directory xcopy.exe {0}", arguments));
                msg += CommandExeHelper.Run("xcopy.exe", arguments);
            }
            else
            {
                result = false;
                msg   += string.Format("Directory error:{0} {1}", checkOutPath, targetPath);
            }
            return(result);
        }
Beispiel #10
0
        /// <summary>
        /// 更新SVN
        /// </summary>
        /// <param name="projectAction"></param>
        private void SvnUpdate(DepProjectAction projectAction, bool isCheckout)
        {
            DepProjectItem projectItem  = SvnProcesser.ProjectItem(projectAction.DepId);
            DepProject     depProject   = SvnProcesser.Project(projectItem.DepId);
            string         svnUrl       = depProject.SvnPath.ToLower().StartsWith("http") ? depProject.SvnPath : SVN_ROOT + "/" + depProject.SvnPath;
            string         checkOutPath = Path.Combine(SVN_UPDATE_ROOT, depProject.Id.ToString());
            string         svnArguments = string.Empty;
            Exception      error        = null;

            //判断是否检出
            if (isCheckout || !Directory.Exists(checkOutPath))
            {
                //if (Directory.Exists(checkOutPath))
                //{
                //    try
                //    {
                //        Directory.Delete(checkOutPath, true);
                //    }
                //    catch (Exception ex)
                //    {
                //        error = ex;
                //    }
                //}
                if (projectAction.Revision <= 0)
                {
                    svnArguments = string.Format(
                        "checkout {0} {1} --username {2} --password {3} --no-auth-cache --non-interactive --trust-server-cert --force",
                        svnUrl,
                        checkOutPath,
                        SVN_USER,
                        SVN_PASSWORD
                        );
                }
                else
                {
                    svnArguments = string.Format(
                        "checkout {0} {1} -r {2} --username {3} --password {4} --no-auth-cache --non-interactive --trust-server-cert --force",
                        svnUrl,
                        checkOutPath,
                        projectAction.Revision,
                        SVN_USER,
                        SVN_PASSWORD
                        );
                }
            }
            else
            {
                if (projectAction.Revision <= 0)
                {
                    svnArguments = string.Format(
                        "update {0} --username {1} --password {2} --no-auth-cache --non-interactive --trust-server-cert --force",
                        checkOutPath,
                        SVN_USER,
                        SVN_PASSWORD
                        );
                }
                else
                {
                    svnArguments = string.Format(
                        "update {0} -r {1} --username {2} --password {3} --no-auth-cache --non-interactive --trust-server-cert --force",
                        checkOutPath,
                        projectAction.Revision,
                        SVN_USER,
                        SVN_PASSWORD
                        );
                }
            }
            if (error != null)
            {
                Logger.SaveLog(string.Format("SvnDeploy执行svn.exe {0}\r\n清除目录出错:", svnArguments), error);
            }
            else
            {
                Logger.SaveLog(string.Format("SvnDeploy执行svn.exe {0}", svnArguments));
            }

            string strOutput = CommandExeHelper.Run("svn.exe", svnArguments);

            if (error != null)
            {
                strOutput = "清除目录出错:" + error.Message + "\r\n" + strOutput;
            }
            SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, strOutput);
        }