/// <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. 【转】解决eclipse新导入工程无法run as server

    转载地址:http://blog.csdn.net/huang86411/article/details/12118309 问题描述: 从SVN或者别处搞过来的web项目,利用eclipse工具,新建 ...

  2. Hibernate的关联映射

    单向N-1关联 <many-to-one> 单向N-1关系,比如多个人对应同一个住址,只需要从人实体端找到对应的住址实体,无须关系某个地址的全部住户.程序在N的一端增加一个属性,该属性引用 ...

  3. 【前端】从输入URL到页面加载完成的过程中都发生了什么事情

    把URL分割成几个部分:协议(http, https).网络地址(xxx.xxx.xxx.xxx).资源路径(/xxx/xxx.xx).端口号(默认80). 如果地址不是一个IP地址,通过DNS(域名 ...

  4. sp 数据导入导出

    https://msdn.microsoft.com/zh-cn/library/ee231568.aspxsharepoint 微软文档 sharepoint 导入导出分两种: 1.一个网站全部导入 ...

  5. JDBC相关的类介绍

    JDBC 背景:1996年,Sun公司推出了Java数据库连接(Java Database Connectivity JDBC)工具包的第一个版本.该工具包使得程序员可以使用结构化语言SQL连接到一个 ...

  6. 读《编写可维护的JavaScript》第五章总结

    第五章 UI层的松耦合 5.1 什么是松耦合 在Web开发中,用户界面是由三个彼此隔离又相互作用的层定义的: HTML是用来定义页面的数据和语义 CSS用来给页面添加样式 JavaScript用来给页 ...

  7. YUM仓库服务

    YUM仓库服务 大纲 1部署yum软件仓库 1.1 准备网络安装源(服务器端) 1.2 配置软件仓库位置(客户机端)   1部署yum软件仓库 借助于YUM软件仓库,可以完成安装.卸载.自动升级rpm ...

  8. LINQ之路 7:子查询、创建策略和数据转换

    在前面的系列中,我们已经讨论了LINQ简单查询的大部分特性,了解了LINQ的支持计术和语法形式.至此,我们应该可以创建出大部分相对简单的LINQ查询.在本篇中,除了对前面的知识做个简单的总结,还会介绍 ...

  9. Ruff is in the house

    Ruff is in my home. 浦东的一家小厂出产的开发板,让我可以用万能的JS开发. 等下试试它的树莓派SDK. 新的时代,旧的东西在被慢慢改进.只要有一颗想动手捣鼓的心,自然会找到合适的工 ...

  10. Gbase数据库备份与还原

    备份命令:cd D:\GeneralData\GBase\Server\bin        回车 后 : d :        回车 后: dump.exe -usysdba(u+用户名) -pbj ...