/// <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 > && clientInfo.Revision > ) {
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;
});
}

c#实现远程操作svn的更多相关文章

  1. 命令行操作svn和git和git

    前几天在写代码的时候电脑突然坏掉,老大交代的任务没完成,非常痛恨自己用svn或者git保存代码,相信很多程序员遇到过,硬盘坏掉,存在硬盘中的代码丢失,无法找回的问题,svn和git可谓程序员界的福音, ...

  2. Git远程操作详解

    Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...

  3. Git远程操作

    Git远程操作 // */ // ]]>   Git远程操作 Table of Contents 1 Git远程命令概览 2 Git远程仓库与本地仓库的关系图 3 git clone 4 git ...

  4. [转] SSH原理与运用(2):远程操作与端口转发

    英文:阮一峰 链接:http://www.ruanyifeng.com/blog/2011/12/ssh_port_forwarding.html 接着前一次的文章,继续介绍SSH的用法. (Imag ...

  5. 转: Git远程操作详解 (阮一峰)

    说明: 通过这个说明终于把远程操作给搞明白了. http://www.ruanyifeng.com/blog/2014/06/git_remote.html

  6. [转]Git远程操作详解

    原文:http://www.ruanyifeng.com/blog/2014/06/git_remote.html Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多 ...

  7. 【转】PowerShell入门(六):远程操作

    转至:http://www.cnblogs.com/ceachy/archive/2013/02/20/PowerShell_Remoting.html PowerShell远程操作是远程管理的基础, ...

  8. Git 远程操作详解

    Git是目前最流行的版本管理系统,学会Git几乎成了开发者的必备技能. Git有很多优势,其中之一就是远程操作非常简便.本文详细介绍5个Git命令,它们的概念和用法,理解了这些内容,你就会完全掌握Gi ...

  9. SSH原理与运用(二):远程操作与端口转发

    SSH原理与运用(二):远程操作与端口转发 作者:阮一峰 (Image credit: Tony Narlock) 七.远程操作 SSH不仅可以用于远程主机登录,还可以直接在远程主机上执行操作. 上一 ...

随机推荐

  1. DataTable转化为Model

    /// <summary> /// 将DataTable转成Model /// </summary> /// <param name="dt"> ...

  2. 【转】eclipse luna 无法安装veloeclipse问题

    转载地址:https://code.google.com/p/veloeclipse/issues/detail?id=47 I tried to install veloeclipse 2.0.8 ...

  3. css 水平垂直居中

    主要是垂直居中有点麻烦,以下代码可以实现,先记下来: <style type="text/css"> div{ border:1px solid #ccc; heigh ...

  4. wsdl学习

    本文来自 :迹忆 原文地址:http://www.onmpw.com/tm/xwzj/network_47.html 在刚开始学习Webservice的时候,发现里面涉及到的知识点还真不少,每一点单拿 ...

  5. window 下 xampp 上 安装memcached

    1.下载memcache 的window 稳定版,解压到xampp 目下;比如D:\xampp\memcached 2. 打开cmd 命令界面 输入 D:\xampp\memcached\ memca ...

  6. 点击表格tr同时点击checkbox

    项目里偶然要用到这个功能,写到了就记一下吧.

  7. OpenModelica仿真

    复杂产品通常涉及机械.控制.电子.液压.气动和软件等多学科领域,其设计过程需要进行仿真,以满足对成本.质量.性能等的要求.目前各个学科和领域都已经有了比较成熟的仿真软件,但大部分仿真软件仅适用于本学科 ...

  8. HTML5滑动(swipe)事件

    移动H5开发中经常用到滑动效果(页面上移.下移.向左滑动.向右滑动等),浏览器并没有内置swipe事件,可以通过touch事件(touchstart.touchmove和touchend)模拟swip ...

  9. Openstack+Kubernetes+Docker微服务实践之路--弹性扩容

    服务上线就要顶的住压力.扛的住考验,不然挨说的还是我们这帮做事的兄弟,还记得上图这个场景吗 老办法是服务集群部署,但总归有个上限,之前跟阿里合作的时候他们有个弹性计算可以通过设置CPU的阀值来动态扩展 ...

  10. nginx 日志变量含义

    log_format logstash "remote_addr | $time_local | $request | $status | $body_bytes_sent | " ...