zoukankan      html  css  js  c++  java
  • c#实现远程操作svn

    /// <summary>
            /// 本地svn服务器地址
            /// </summary>
            private static string localSVN = ConfigurationManager.AppSettings["localSVN"].ToString();
            /// <summary>
            /// 线上svn服务器地址
            /// </summary>
            private static string onlineSVN = ConfigurationManager.AppSettings["onlineSVN"].ToString();
            /// <summary>
            /// 本地地址
            /// </summary>
            private static string localPath = ConfigurationManager.AppSettings["localPath"].ToString();
    
            /// <summary>
            /// 添加
            /// </summary>
            /// <param name="fullpath">添加的文件所在路径</param>
            /// <returns></returns>
            public static bool AddSvn(string fullpath) {
                using (SvnClient client = new SvnClient()) {
                    string path = fullpath;
                    SvnAddArgs args = new SvnAddArgs();
                    args.Depth = SvnDepth.Empty;
                    return client.Add(path, args);
                }
            }
    
            /// <summary>
            /// 更新
            /// </summary>
            /// <param name="fileName">文件夹名称</param>
            /// <returns></returns>
            public static string UpdateSvn(string fileName, string user, string pwd, string type) {
                string result = string.Empty;
                using (SvnClient client = new SvnClient()) {
                    GetPermission(client, user, pwd);
                    SvnInfoEventArgs serverInfo;
                    SvnInfoEventArgs clientInfo;
                    SvnUriTarget repos = new SvnUriTarget("http://" + (type == "local" ? localSVN : onlineSVN) + fileName);
                    SvnPathTarget local = new SvnPathTarget(localPath + "\" + fileName);
    
                    client.GetInfo(repos, out serverInfo);
    
                    client.Update(localPath + "\" + fileName);
    
                    client.GetInfo(local, out clientInfo);
                    if (serverInfo.Revision > 0 && clientInfo.Revision > 0) {
                        result = serverInfo.Revision.ToString() + "-" + clientInfo.Revision.ToString();
                    }
                    return result;
                }
            }
    
            /// <summary>
            /// 提交
            /// </summary>
            /// <param name="fileName"></param>
            /// <returns></returns>
            public static string CommitSvn(string fileName, string user, string pwd, string type) {
                string result = string.Empty;
                using (SvnClient client = new SvnClient()) {
                    GetPermission(client, user, pwd);
                    SvnCommitArgs commitargs = new SvnCommitArgs();
                    commitargs.LogMessage = "OA提交";
                    SvnInfoEventArgs serverInfo;
                    SvnInfoEventArgs clientInfo;
                    SvnUriTarget repos = new SvnUriTarget("http://" + (type == "local" ? localSVN : onlineSVN) + fileName);
                    SvnPathTarget local = new SvnPathTarget(localPath + "\" + fileName);
    
                    var b = client.Commit(localPath + "\" + fileName, commitargs);
                    client.GetInfo(repos, out serverInfo);
                    client.GetInfo(local, out clientInfo);
                    return serverInfo.Revision.ToString();
                }
            }
    
            /// <summary>
            /// 回滚
            /// </summary>
            /// <param name="fileName">文件夹名称</param>
            /// <param name="ver">指定版本号</param>
            /// <returns></returns>
            public static string RollBackSvn(string fileName, int ver, string user, string pwd) {
                string result = string.Empty;
                using (SvnClient client = new SvnClient()) {
                    GetPermission(client, user, pwd);
    
                    SvnInfoEventArgs clientInfo;
                    SvnPathTarget local = new SvnPathTarget(localPath + "\" + fileName);
    
                    client.Update(localPath + "\" + fileName, new SvnUpdateArgs() { Revision = new SvnRevision(ver) });
                    client.GetInfo(local, out clientInfo);
    
                    return clientInfo.Revision.ToString();
                }
            }
    
            /// <summary>
            /// 获取权限
            /// </summary>
            /// <param name="client"></param>
            private static void GetPermission(SvnClient client, string username, string password) {
                client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);
                client.Authentication.UserNamePasswordHandlers +=
                    new EventHandler<SvnUserNamePasswordEventArgs>(
                        delegate(object s, SvnUserNamePasswordEventArgs e) {
                            e.UserName = username;
                            e.Password = password;
                        });
                client.Authentication.SslServerTrustHandlers +=
                    new EventHandler<SvnSslServerTrustEventArgs>(
                        delegate(object s, SvnSslServerTrustEventArgs e) {
                            e.Save = true;
                        });
            }
  • 相关阅读:
    [LeetCode] Exclusive Time of Functions 函数的独家时间
    [LeetCode] Design Log Storage System 设计日志存储系统
    [LeetCode] Find the Derangement of An Array 找数组的错排
    [LeetCode] 632. Smallest Range Covering Elements from K Lists 覆盖K个列表元素的最小区间
    [LeetCode] 633. Sum of Square Numbers 平方数之和
    [LeetCode] Design Excel Sum Formula 设计Excel表格求和公式
    [LeetCode] Delete Operation for Two Strings 两个字符串的删除操作
    [LeetCode] Kill Process 结束进程
    [LeetCode] Course Schedule III 课程清单之三
    [LeetCode] K Inverse Pairs Array K个翻转对数组
  • 原文地址:https://www.cnblogs.com/len0031/p/5944678.html
Copyright © 2011-2022 走看看