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() + "\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);

    }

  • 相关阅读:
    EasyDSS高性能RTMP、HLS(m3u8)、HTTP-FLV、RTSP流媒体服务器前端源码重构(一)-从零开始搭建 webpack + vue + AdminLTE 多页面脚手架
    采用EasyDSS视频点播服务器搭建企业私有化的音视频多媒体、短视频、视频服务网站与管理后台
    基于EasyNVR摄像机无插件直播方案二次开发实现自己的摄像机IPC-NVR无插件化直播解决方案
    基于EasyNVR摄像机无插件直播流媒体服务器实现类似于单点登录功能的免登录直播功能
    实现RTSP摄像机进行网页直播和微信直播的技术方案:EasyNVR版本免费更新方法
    实现RTSP摄像机硬盘录像机NVR网站网页微信H5直播方案EasyNVR部署问题之:ERR_CONTENT_LENGTH_MISMATCH
    如何自己构建一套EasyNVR这样的无插件流媒体服务器实现摄像机硬盘录像机的网页可视化直播
    浏览器低延时播放监控摄像头RTSP海康大华硬盘录像机NVR视频(EasyNVR播放FLV视频流)
    基于EasyNVR摄像机流媒体服务器实现RTSP或Onvif监控摄像头Web无插件化直播监控
    基于EasyDarwin开源流媒体服务器框架实现EasyNVR H5无插件直播流媒体服务器方案
  • 原文地址:https://www.cnblogs.com/goody9807/p/2749938.html
Copyright © 2011-2022 走看看