/// <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. 【转】Android选项卡置底的方法

    转载地址:http://www.oschina.net/code/snippet_163910_6092 发现很多Android应用的选项卡 都是显示在页面底部的,网上有资料:通过反射获取TabWid ...

  2. MySQL为什么需要一个主键

    主键 表中每一行都应该有可以唯一标识自己的一列(或一组列). 一个顾客可以使用顾客编号列,而订单可以使用订单ID,雇员可以使用雇员ID 或 雇员社会保险号. 主键(primary key) 一列(或一 ...

  3. 给自己的XTC820摆拍一下。

    上个月入手了捷安特的XTC820,始终没有时间为爱车拍几张照,今天凑着在办公室的机会,就随手拍了几张,展示一下XTC820.先给大家看图片,然后再分享一下当初我买它的原因以及车的规格. 下面就来简单说 ...

  4. OpenWrt > ADSL单线多拨,负载均衡(仅供参考)

    前题 硬件:路由器,刷入OpenWrt 一些背景知识和动手能力 目标效果图 步骤 使用SSH 登陆路由器.I.e. ssh root@192.168.2.1 运行/usr/bin/duobo.日志类似 ...

  5. 在Linux/Windows系统上编辑/etc/hosts文件

    Linux ubuntu16 open the terminal, input the command: sudo -i gedit /etc/hosts file click enter key, ...

  6. iOS中事件传递过程

    iOS中,UIApplication管理着一个事件的队列,当系统获取用户的点击或滑动等事件后,就会将这些事件按顺序插入UIApplication管理的这个队里中,UIApplication再从这个队列 ...

  7. Momentics创建Photon图形程序

    Photon microGui是qnx原生的UI图形工具.Qnx下开发Photon 一般是使用phAB来创建,使用默认的Momentics IDE也可以创建Photon图形程序. 首先需要创建一个c/ ...

  8. VirtualBox piix4_smbus Error

    VirtualBox piix4_smbus Error   VirtualBox 3.2.10 gives me the following error message when booting U ...

  9. 一个简单确非常实用的javascript函数

    在写js的时候,往往会碰到字符串拼接的问题,如果简单,直接使用+号连接字符串就可以了, 但是如果复杂,+用起来就非常不爽,在.net中有,Sting.Format函数,用起来还是很爽的,于是就想着js ...

  10. 退役&&搬家

    牡丹江与鞍山两站作为最后的结束站.一银一铜就此结束了~ 此博客用来怀念ACM就此保留并不添加任何其它与其无关内容. ------------------------------------------ ...