SVN Client API的.net 接口 SharpSvn介紹 Checkout操作实例

Subversion是一個文件版本管理工具, 廣泛的被大家採用來作為源代碼版本管理.

已有的工具不管是其自帶的命令行工具還是Windows UI的tortoiseSVN等還是很方便實用的, 但是如果想跟已有的系統整合的話,除了用其內建的Hook Script功能外,必然要使用SVN的API,這個API是用C寫的, 所以對於其他開發語言來說如java, C#等使用起來不方便.

於是就有了SVN Client的java實現,或者是用其他語言對C接口的DLL包裝了一層的代碼(參考SWIG),這樣我們就可以方便的使用其他語言來與SVN repository 進行溝通了

SharpSvn就是 .net平台的一個SVN API的實現, 其被廣泛採用到AnkhSVN 等工具中, 可以被用來擴展為自定義的訪問SVN的Client, 或者用來跟其他系統如Bug/CR追踪等進行整合.

下面是一位網友整理的一個簡單的指南,類似hello world, 告訴我們如何開始使用Sharp SVN

The SharpSvn library basically gives you a .NET interface to all the operations that you would normally perform through a tool like TortoiseSVN.

I found myself needing this exact library while writing a tool that changes files that have been checked out from SVN.

The problem with manipulating files that are under SVN is that you need to be careful about renaming files (and sometimes even deleting). If you don’t do it through the SVN api then you will end up with duplicates files/folders in SVN since SVN thinks that it’s a new file.

To solve this I finally got a chance to crack open the SharpSVN library which is used by my favourite AnkhSVN.

1. Download the latest library from http://sharpsvn.open.collab.net/. You have to pick between either 1.5 or 1.6. I went with 1.6 and didn’t run into any issues. I think this is based on the version of the SVN server that your connecting to.

2. In your Visual Studio project add a reference to the following assemblies.  - SharpSvn.dll  - SharpSvn.UI.dll (Only needed if you need the UI to prompt for login)

3. If like me your building on a 64 bit OS and you want your app to run on a 32 bit OS, make sure the project that references the SharpSvn.dll is set to Build for the x86 Platform. (Build –> Configuration Manager – Solution Platform)

4. Write your code using the SvnClient object. Here are some samples from the SharpSvn Wiki and some that I wrote.

ShowLog操作

using (SvnClient client = new SvnClient())

{                 //client.Authentication.Clear();                 client.Authentication.UserNamePasswordHandlers += new EventHandler<SharpSvn.Security.SvnUserNamePasswordEventArgs>(                 delegate(Object s, SharpSvn.Security.SvnUserNamePasswordEventArgs ee)                 {                     ee.UserName = "你的帳號"; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ee.Password = "你的密碼";                 });
                client.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(                 delegate(Object ssender, SharpSvn.Security.SvnSslServerTrustEventArgs se)                 {                     // Look at the rest of the arguments of E whether you wish to accept
                    // If accept:                     se.AcceptedFailures = se.Failures;                     se.Save = true; // Save acceptance to authentication store                 });
                this.txtLog.Text += DateTime.Now.ToLongTimeString() + "\r\n";                 SvnLogArgs logArgs = new SvnLogArgs();                 logArgs.Range = new SvnRevisionRange(long.Parse(this.txtRevisionFrom.Text), long.Parse(this.txtRevisionTo.Text));                 logArgs.RetrieveAllProperties = true;
                EventHandler<SvnLogEventArgs> logHandler = new EventHandler<SvnLogEventArgs>(delegate(object lo, SvnLogEventArgs le)                 {                     foreach (SvnChangeItem changeItem in le.ChangedPaths)                     {                         this.txtLog.Text += string.Format(                                                     "{0} {1} {2} {3} {4}\r{5} {6}",                                                     changeItem.Action,                                                     changeItem.Path,                                                     changeItem.CopyFromRevision,                                                     changeItem.CopyFromPath,                                                     le.Author,                                                     le.LogMessage,                                                     le.Revision);
                    }                 });
                client.Log(new Uri(<a href="https://url">https://url</a>), logArgs, logHandler);                 this.txtLog.Text += DateTime.Now.ToLongTimeString() + "\r\n";             }

using (SvnClient client = new SvnClient())

{                 //client.Authentication.Clear();                 client.Authentication.UserNamePasswordHandlers += new EventHandler<SharpSvn.Security.SvnUserNamePasswordEventArgs>(                 delegate(Object s, SharpSvn.Security.SvnUserNamePasswordEventArgs ee)                 {                     ee.UserName = "你的帳號";                     ee.Password = "你的密碼";                 });
                client.Authentication.SslServerTrustHandlers+= new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(                 delegate(Object ssender, SharpSvn.Security.SvnSslServerTrustEventArgs se)                 {                   // Look at the rest of the arguments of E whether you wish to accept
                  // If accept:                   se.AcceptedFailures = se.Failures;                   se.Save = true; // Save acceptance to authentication store                 });
                client.CheckOut(                   new Uri("https://yourSVN-Server:8443/svn/prd/UTL/trunk/ExcelPool"), //SVN repository url                   @"c:\wc");                                                                                                          //local direcotory             }

Add new files to the working copy

using(SvnClient client = new SvnClient()) {   SvnAddArgs args = new SvnAddArgs();   // TODO: Set optional settings on args   client.Add(@"C:\file\in\workingcopy", args);

}

http://www.cnblogs.com/goody9807/archive/2012/11/01/2749938.html

时间: 2024-10-31 13:50:08

SVN Client API的.net 接口 SharpSvn介紹 Checkout操作实例的相关文章

HBase Client API使用入门(二)---查询及过滤器

相关知识 创建表插入数据删除等见:http://www.cnblogs.com/wishyouhappy/p/3735077.html HBase API简介见:http://www.cnblogs.com/wishyouhappy/p/3753347.html 按行.列簇等查询 package wish.hbase; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org

Memcached Java Client API详解

针对Memcached官方网站提供的java_memcached-release_2.0.1版本进行阅读分析,Memcached Java客户端lib库主要提供的调用类是SockIOPool和MemCachedClient?,关键类及方法整理说明如下. SockIOPool 这个类用来创建管理客户端和服务器通讯连接池,客户端主要的工作包括数据通讯.服务器定位.hash码生成等都是由这个类完成的. public static SockIOPool getInstance() 获得连接池的单态方法.

unable to load default svn client 和 Eclipse SVN 插件与TortoiseSVN对应关系

(一)unable to load default svn client 在Win7下的Eclipse,安装了subclipse 1.10.x,已经选中了subclipse和subversion Client Adapter.但是,在新建SVN 资源库时,出现unable to load default svn client错误,把Subversion JavaHL Native Library Adpter安装上即可.如下图所示: (二)Eclipse SVN 插件与TortoiseSVN对应

Android系统进程间通信(IPC)机制Binder中的Client获得Server远程接口过程源代码分析

文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/6633311 在上一篇文章中,我 们分析了Android系统进程间通信机制Binder中的Server在启动过程使用Service Manager的addService接口把自己添加到Service Manager守护过程中接受管理.在这一篇文章中,我们将深入到Binder驱动程序源代码去分析Client是如何通过Service Manager的

ecshop /api/client/api.php、/api/client/includes/lib_api.php SQL Injection Vul

catalog 1. 漏洞描述 2. 漏洞触发条件 3. 漏洞影响范围 4. 漏洞代码分析 5. 防御方法 6. 攻防思考 1. 漏洞描述 ECShop存在一个盲注漏洞,问题存在于/api/client/api.php文件中,提交特制的恶意POST请求可进行SQL注入攻击,可获得敏感信息或操作数据库 http://sebug.net/vuldb/ssvid-21007 2. 漏洞触发条件 1. /api/client/api.php存在未过滤漏洞 2. 服务器magic_quote_gpc =

ElasticSearch---------------------&gt;Elasticsearch Clients---------------------&gt;Java REST Client API

Elasticsearch-->Java REST Client API 概述: elasticsearch提供了REST WEB API,所以开发者可以在自己的restful web中调用elasticsearch 关于Java REST Client API的详细叙述,参见官方documentation:Java REST Client API 可以直接使用curl来调用elasticsearch: 基本语法格式:RESTful API with JSON over HTTP 使用示例: 例

jupyter Client API

Jupyter Client Api : Jupyter Kernel :http://jupyter-client.readthedocs.io/en/latest/kernels.html Jupyter Client API: http://jupyter-client.readthedocs.io/en/latest/api/kernelspec.html

Android中使用系统提供API数据访问接口操作数据库

数据的增加 1.创建一个SQLite数据的帮助类 SQLiteDatabase db = helper.getWritableDatabase(); 2.创建一个类似map集合的类ContentValues,用来存储键值对 ContentValues values = new ContentValues(); 3.把需要增加的数据存放进去 values.put("name", name); values.put("number", number); 4.执行系统提供

Proxy settings in TortoiseSVN and command line svn client

The server file is created when you install TortoiseSVN, Eclipse or command-line Subversion. Use the appropriate path from the installation folder to configure proxy settings: CLI Unix/Linux : /home/username/.subversion/servers CLI Windows (2k, XP):