コード例 #1
0
ファイル: Program.cs プロジェクト: yuzs/donetci
        /// <summary>
        /// svn代码获取
        /// </summary>
        /// <param name="svnuri">svn地址</param>
        static void SVNUpdate(string svnuri, out string logmessage, out long reversion)
        {
            logmessage = "";
            reversion  = 0;
            long clientVersion = -1;

            using (SvnClient client = new SvnClient())
            {
                try
                {
                    var localpath = WorkPath + @"\" + ProjCode + @"\" + BranchName;
                    var username  = ConfigHelper.GetValue("SVNUser");
                    var pwd       = ConfigHelper.GetValue("SVNpwd");
                    client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd);
                    //notiny = "正在检查本地版本...";
                    //ShowInfo();
                    //SvnInfoEventArgs clientInfo;
                    //bool okc = SC.GetInfo(local, out clientInfo);
                    //if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令
                    //{
                    //    result = (serverInfo.Revision > clientInfo.Revision);
                    //}

                    //如果项目不存在则checkout,否则进行update
                    if (!Directory.Exists(localpath))
                    {
                        client.CheckOut(new Uri(svnuri), localpath);
                        Console.WriteLine("svn checkout success");
                    }
                    else
                    {
                        SvnInfoEventArgs serverInfo;
                        SvnInfoEventArgs clientInfo;
                        SvnUriTarget     repos = new SvnUriTarget(svnuri);
                        SvnPathTarget    local = new SvnPathTarget(localpath);
                        SvnUpdateArgs    args  = new SvnUpdateArgs();
                        args.Depth = SvnDepth.Infinity;
                        var  svnService = new SvnService();
                        long version    = 0;

                        var msg = "";
                        args.Notify += delegate(object sender, SvnNotifyEventArgs e)
                        {
                            //if (svnService.GetNotifyAction(e.Action) == "添加")
                            //{
                            //    msg += "\r\n添加" + e.FullPath;
                            //}
                            //if (svnService.GetNotifyAction(e.Action) == "更新删除")
                            //{
                            //    msg += "\r\n删除:" + e.FullPath;
                            //}
                            //if (svnService.GetNotifyAction(e.Action) == "更新修改")
                            //{
                            //    msg += "\r\n修改" + e.FullPath;
                            //}
                            msg    += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath;
                            version = e.Revision;
                            Console.WriteLine(msg);
                        };


                        client.GetInfo(repos, out serverInfo);
                        client.GetInfo(local, out clientInfo);
                        clientVersion = clientInfo.Revision;



                        //if (clientVersion < version)//客户端version必须小于服务端才更新
                        //{


                        //client.Resolve(localpath, SvnAccept.Base);//解决冲突
                        ////解决冲突
                        //Collection<SvnStatusEventArgs> statuses;
                        //client.GetStatus(localpath, out statuses);

                        //foreach (var item in statuses)
                        //{
                        //    if (item.Conflicted)
                        //    {
                        //        client.Resolve(item.FullPath, SvnAccept.Working);
                        //        Console.WriteLine("处理冲突文件:" + item.FullPath);
                        //        logmessage += "处理冲突文件:" + item.FullPath;
                        //    }
                        //}


                        client.CleanUp(localpath);

                        SvnRevertArgs revertArgs = new SvnRevertArgs()
                        {
                            Depth = SvnDepth.Infinity
                        };                                                                           //撤销本地所做的修改
                        client.Revert(localpath, revertArgs);
                        client.Update(localpath, args);

                        //获取消息
                        Collection <SvnLogEventArgs> logitems;
                        //if (version > 0 && clientVersion < version)
                        logmessage += "变更文件:" + msg;

                        if (version > 0 && clientVersion < version)
                        {
                            reversion = version;
                            client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems);
                            //client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems);
                            foreach (var logentry in logitems)
                            {
                                string author  = logentry.Author;
                                string message = logentry.LogMessage;
                                //DateTime checkindate = logentry.Time;
                                logmessage += string.Format("\r\n提交人:{0} ,日志: {1}", author, message);
                            }
                        }
                        //}
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    logmessage = ex.ToString();
                }
            }
        }
コード例 #2
0
ファイル: SVNTest.cs プロジェクト: yuzs/donetci
        /// <summary>
        /// svn代码获取
        /// </summary>
        /// <param name="svnuri">svn地址</param>
        static void SVNUpdate(string svnuri, out string logmessage, out long reversion)
        {
            logmessage = "";
            reversion  = 0;
            using (SvnClient client = new SvnClient())
            {
                var localpath = "d:\\sharpsvn";
                localpath = @"E:\project\ccms\CCMS_V7_HBYD_R";
                var username = "";
                var pwd      = "";
                client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd);
                //如果项目不存在则checkout,否则进行update
                if (!Directory.Exists(localpath))
                {
                    client.CheckOut(new Uri(svnuri), localpath);
                    // Console.WriteLine("svn checkout success");
                }
                else
                {
                    SvnInfoEventArgs serverInfo;
                    SvnInfoEventArgs clientInfo;
                    SvnUriTarget     repos = new SvnUriTarget(svnuri);
                    SvnPathTarget    local = new SvnPathTarget(localpath);
                    SvnUpdateArgs    args  = new SvnUpdateArgs();
                    args.Depth = SvnDepth.Infinity;
                    var  svnService    = new SvnService();
                    long version       = 0;
                    long clientVersion = -1;
                    var  msg           = "";
                    args.Notify += delegate(object sender, SvnNotifyEventArgs e)
                    {
                        //if (svnService.GetNotifyAction(e.Action) == "添加")
                        //{
                        //    msg += "\r\n添加" + e.FullPath;
                        //}
                        //if (svnService.GetNotifyAction(e.Action) == "更新删除")
                        //{
                        //    msg += "\r\n删除:" + e.FullPath;
                        //}
                        //if (svnService.GetNotifyAction(e.Action) == "更新修改")
                        //{
                        //    msg += "\r\n修改" + e.FullPath;
                        //}
                        msg    += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath;
                        version = e.Revision;
                    };


                    client.GetInfo(repos, out serverInfo);
                    client.GetInfo(local, out clientInfo);
                    clientVersion = clientInfo.Revision;

                    //if (clientVersion < version)//客户端version必须小于服务端才更新
                    //{
                    client.CleanUp(localpath);

                    SvnRevertArgs args2 = new SvnRevertArgs()
                    {
                        Depth = SvnDepth.Infinity
                    };


                    client.Revert(localpath, args2);
                    client.Update(localpath, args);

                    //获取消息
                    Collection <SvnLogEventArgs> logitems;
                    //if (version > 0 && clientVersion < version)
                    if (msg.Length > 5)
                    {
                        reversion   = version;
                        logmessage += "\r\n变更文件:" + msg;
                        client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems);
                        // client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems);
                        foreach (var logentry in logitems)
                        {
                            string author  = logentry.Author;
                            string message = logentry.LogMessage;
                            //DateTime checkindate = logentry.Time;
                            logmessage += "\r\n";
                            logmessage += string.Format("提交人:{0} ,日志: {1}", author, message) + "\r\n";
                        }
                    }
                    //}


                    // Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision));
                    //Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision));
                    // Console.WriteLine("代码获取成功");
                }
            }//
        }