zoukankan      html  css  js  c++  java
  • 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() + " ";                 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} {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() + " ";             }
    复制代码

     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:fileinworkingcopy", args);

    }

    复制代码

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

  • 相关阅读:
    Python基础入门教程
    【前端学习笔记】2015-09-11~~~~ js中ajax请求返回案例
    【前端学习笔记】2015-09-10~~~~ css层叠样式表~~格式
    【前端学习笔记】2015-09-09~~~~nodejs中的require()和module.exports
    【前端学习笔记】2015-09-08~~~~ 关于切图的简单方法
    【前端学习笔记】2015-09-06 ~~~~ setAttribute()、slice()
    【前端学习笔记】2015-09-02 附~~~~~ajax简单请求和获得响应结果
    【前端学习笔记】2015-09-02~~~~ 关于filter()匹配的使用
    【前端学习笔记】2015-09-01 附二 关于jq选择器的简单运用
    【前端学习笔记】2015-09-01 附 split()方法、readyState
  • 原文地址:https://www.cnblogs.com/chen110xi/p/4819081.html
Copyright © 2011-2022 走看看