示例#1
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!Page.IsPostBack)
     {
         lblSubTitle.Text = SvnProcesser.Project(DeployId).Name;
     }
 }
示例#2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            DepProject depSln = null;
            string     strId  = Request.QueryString["id"];

            if ((!string.IsNullOrEmpty(strId)) && int.TryParse(strId, out nId))
            {
                depSln = SvnProcesser.Project(nId);

                if (null == depSln)
                {
                    bIsNew = true;
                    Response.Redirect("SlnEdit.aspx");
                    return;
                }
            }
            else
            {
                bIsNew = true;
            }

            if (bIsNew)
            {
                pTitle.InnerText = "项目部署创建";
            }
            else
            {
                pTitle.InnerText = depSln.Name;
            }

            if ("GET".Equals(Request.HttpMethod) && !Page.IsPostBack)
            {
                if (!bIsNew)
                {
                    tbSlnName.Text      = depSln.Name;
                    tbSlnIP.Text        = depSln.Ip;
                    tbSvnPath.Text      = depSln.SvnPath;
                    txtSharePath.Text   = depSln.SharePath;
                    txtExcludeFile.Text = depSln.ExcludeFile;
                    txtGameId.Text      = depSln.GameId.ToString();
                }
            }
        }
示例#3
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);
        }
示例#4
0
        /// <summary>
        /// 快速部署计划任务
        /// </summary>
        private void DoSchTaskQuickDeploy(DepProjectAction projectAction, DepProjectItem projectItem)
        {
            //更新缓存
            DepProject project  = SvnProcesser.Project(projectItem.DepId);
            int        gameId   = project.GameId;
            int        serverId = projectItem.ServerId;
            string     host     = project.ExcludeFile;//配置成Socket地址

            using (GameSocketClient client = new GameSocketClient())
            {
                string msg = string.Empty;
                client.ReceiveHandle += new SocketCallback((error, errorInfo, buffer) =>
                {
                    try
                    {
                        msg += string.Format("cache cmd:{0}-{1}\r\n", error, errorInfo);
                        //停止计划任务
                        msg += SchTasksOperate.StopRun(projectItem.WebSite);
                        string deploymsg = string.Empty;
                        if (Deploy(projectAction, ref deploymsg))
                        {
                            msg          += deploymsg;
                            int sleepTime = SVN_QDEPLOY_WAIT + new Random().Next(1, 10);
                            Thread.Sleep(sleepTime * 1000);
                            //开启计划任务
                            msg += SchTasksOperate.StartRun(projectItem.WebSite);
                        }
                        SvnProcesser.UpdateDeployStatus(projectAction.Id, SUCCESS, msg);
                    }
                    catch (Exception ex)
                    {
                        new BaseLog().SaveLog("DoSchTaskQuickDeploy", ex);
                        SvnProcesser.UpdateDeployStatus(projectAction.Id, ERROR, ex.ToString());
                    }
                });
                client.Connect(host);
                string command = "GM:cache";
                client.SendToServer(gameId, serverId, 1000, command);
            }
        }
示例#5
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);
        }
示例#6
0
        protected override void DoOperated(string op)
        {
            string[] ids = GetParam("Id").Split(',');

            int projectId = Convert.ToInt32(GetParam("deployId"));
            int verId     = 0;

            int.TryParse(GetParam("verId"), out verId);
            DepProject project    = SvnProcesser.Project(projectId);
            bool       hasSchTask = false;
            int        type       = 0;
            int        gameId     = 0;
            int        serverId   = 0;

            switch (op)
            {
            case "startiis":
                hasSchTask = GetSchTasks(ids);
                type       = hasSchTask ? 13 : 1;
                DoProcess(type, ids, project, verId);
                break;

            case "stopiis":
                hasSchTask = GetSchTasks(ids);
                type       = hasSchTask ? 14 : 2;
                DoProcess(type, ids, project, verId);
                break;

            case "clearupsvn":
                DoProcess(5, ids, project, verId);
                break;

            case "updatesvn":
                bool ischeck;
                bool.TryParse(GetParam("Ischeck"), out ischeck);
                if (ischeck)
                {
                    DoProcess(6, ids, project, verId);
                }
                else
                {
                    DoProcess(3, ids, project, verId);
                }
                break;

            case "deploy":
                DoProcess(4, ids, project, verId);
                break;

            case "deployPython":
                DoProcess(8, ids, project, verId);
                break;

            case "quickdeploy":
                DoProcess(7, ids, project, verId);
                break;

            case "runpy":
                gameId   = Convert.ToInt32(GetParam("gameId"));
                serverId = Convert.ToInt32(GetParam("serverId"));
                DoProcessPython(ids, gameId, serverId);
                hasDoAction = true;
                break;

            case "msmq":
                gameId   = Convert.ToInt32(GetParam("gameId"));
                serverId = Convert.ToInt32(GetParam("serverId"));
                SelectMSMQLog(projectId, gameId, serverId);
                hasDoAction = true;
                break;

            case "createSchtask":
                DoProcess(11, ids, project, verId);
                break;

            case "deleteSchtask":
                DoProcess(12, ids, project, verId);
                break;

            case "restart":
                DoProcess(15, ids, project, verId);
                break;

            case "socketcmd":
                DoProcessCommand(ids, project, GetParam("cmd"));
                break;

            default:
                break;
            }
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var depSln = SvnProcesser.Project(DeployId);

            pTitle.Text = depSln.Name;
        }