VisualSVN Server可以用WMI接口管理(Windows Management Instrumentation)。

VisualSVN Server安装的计算机中,位于%VISUALSVN_SERVER%\WMI下的MOF文件描述了该接口。可以用C#代码控制管理VisualSVN Server。

我机器VisualSVN安装在D盘,MOF文件存在位置:D:\Program Files\VisualSVN Server\WMI\VisualSVNServer.mof

下面一些代码供参考:

using System.Management;
using System.Management.Instrumentation;

并添加 System.Management,System.Management.Instrumentation这两个组件的引用。

1)创建Subversion 用户 'user1',密码为'secret'

ManagementClass userClass = newManagementClass("root\\VisualSVN","VisualSVN_User",null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
userClass.GetMethodParameters("Create");
// Add the input parameters.
inParams["Name"] = "user1";
inParams["Password"] = "secret";
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
userClass.InvokeMethod("Create", inParams, null);

2)创建新的repository 'Repo1'

ManagementClass repoClass = newManagementClass("root\\VisualSVN","VisualSVN_Repository",null);
// Obtain in-parameters for the method
ManagementBaseObject inParams =
repoClass.GetMethodParameters("Create");
// Add the input parameters.
inParams["Name"] = "Repo1";
// Execute the method and obtain the return values.
ManagementBaseObject outParams =
repoClass.InvokeMethod("Create", inParams, null);

  3)设置SID S-1-5-32-545 ('BUILTIN\Users') Windows用户组对'Test' repository的读/写权限. FYI: AccessLevel 值在MOF有描述: "0 - 无权限, 1 - 只读, 2 - 读/写".
ManagementClass userClass = newManagementClass("root\\VisualSVN","VisualSVN_WindowsAccount",null);
ManagementClass authzClass = newManagementClass("root\\VisualSVN","VisualSVN_SecurityDescriptor",null);
ManagementClass permClass = newManagementClass("root\\VisualSVN","VisualSVN_PermissionEntry",null);
ManagementObject userObject = userClass.CreateInstance();
userObject.SetPropertyValue("SID","S-1-5-32-545");
ManagementObject permObject = permClass.CreateInstance();
permObject.SetPropertyValue("Account", userObject);
permObject.SetPropertyValue("AccessLevel", 2);
ManagementObject repo = newManagementObject("VisualSVN_Repository.Name='Test'");
ManagementBaseObject inParams =
authzClass.GetMethodParameters("SetSecurity");
inParams["Object"] = repo;
inParams["Permissions"] = newobject[] { permObject };
ManagementBaseObject outParams =
authzClass.InvokeMethod("SetSecurity", inParams, null);

参考文章:

1.http://msdn.microsoft.com/en-us/library/bb404655

2.http://stackoverflow.com/questions/10017282/control-visualsvn-server-from-c-sharp

作者:a497785609 发表于2014-5-29 15:51:58 原文链接
阅读:10 评论:0 查看评论

[译]C#控制管理VisualSVN Server的更多相关文章

  1. C#控制管理VisualSVN Server 分类: C# 2014-05-29 15:51 796人阅读 评论(0) 收藏

    VisualSVN Server可以用WMI接口管理(Windows Management Instrumentation). VisualSVN Server安装的计算机中,位于%VISUALSVN ...

  2. C#控制管理VisualSVN Server

    VisualSVN Server可以用WMI接口管理(Windows Management Instrumentation). VisualSVN Server安装的计算机中,位于%VISUALSVN ...

  3. 项目管理实践教程二、源代码控制【Source Control Using VisualSVN Server and TortoiseSVN】

    在第一篇文章 项目管理实践教程一.工欲善其事,必先利其器[Basic Tools]发布后,根据大家的回复,我需要向大家说明几个问题: 1.为什么要用VisualSVN Server,而不用Subver ...

  4. 源代码管理(Windows + VisualSVN Server + TortoiseSVN + VS2010)

    之前项目中使用过SVN管理源代码,但是都是链接别人搭建的服务器,现在感觉每周保留一个版本蛮麻烦的,就搭建一个,方便以后管理代码. 1.安装VisualSVN Server( VisualSVN Ser ...

  5. 如何创建 SVN 服务器,并搭建自己的 SVN 仓库 如何将代码工程添加到VisualSVN Server里面管理

    如何创建 SVN 服务器,并搭建自己的 SVN 仓库,附链接: https://jingyan.baidu.com/article/6b97984dca0d9c1ca3b0bf40.html 如何将代 ...

  6. VisualSVN Server的配置和使用方法(转)

    1.为什么要用VisualSVN Server,而不用Subversion? 回答: 因为如果直接使用Subversion,那么在Windows 系统上,要想让它随系统启动,就要封装SVN Serve ...

  7. (转)TortoiseSVN与VisualSVN Server搭建SVN版本控制系统

    本片主要介绍如何搭建SVN版本控制系统,主要使用工具: 1 客户端:TortoiseSVN (小乌龟) 2 服务端:VisualSVN Server 搭建出图形化管理,以及右键菜单版本控制管理的SVN ...

  8. TortoiseSVN与VisualSVN Server搭建SVN版本控制系统

    本片主要介绍如何搭建SVN版本控制系统,主要使用工具: 1 客户端:TortoiseSVN (小乌龟) 2 服务端:VisualSVN Server 搭建出图形化管理,以及右键菜单版本控制管理的SVN ...

  9. VisualSVN Server的配置和使用方法 图文

    转载 http://www.jb51.net/article/17365.htm VisualSVN Server是免费的,而VisualSVN是收费的.VisualSVN是SVN的客户端,和Visu ...

随机推荐

  1. 深入理解 Javascript 面向对象编程

    一:理解构造函数原型(prototype)机制 prototype是javascript实现与管理继承的一种机制,也是面向对象的设计思想.构造函数的原型存储着引用对象的一个指针,该指针指向与一个原型对 ...

  2. iOS6新特征:UICollectionView高级使用示例之CircleLayout

    DEMO   下面再看看Demo运行的效果图,通过这样的一个Demo,我们可以看出,使用UICollectionView可以很方便的制作出照片浏览等应用.并且需要开发者写的代码也不多.   程序刚刚启 ...

  3. linux命令别名的使用

    语 法:alias[别名]=[指令名称] 1,查看该用户下的别名: alias 2,有的系统里没有ll这个命令,原因就是没有定义ll='ls -l --color=tty'这个别名 如果想永久生效,就 ...

  4. C/C++内存分配区

    一.起源 C++内存分成5个区,分别是堆.栈.自由存储区.全局/静态存储区和常量存储区. 但这个自由存储区这么一听还是模模糊糊的,和堆好像是一样的,还有同学说起这个问题.   二.个人理解 关于自由存 ...

  5. detours安装和使用

    http://blog.csdn.net/evi10r/article/details/6659354 http://blog.csdn.net/donglinshengan/article/deta ...

  6. Borg Maze(MST & bfs)

    Borg Maze Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9220   Accepted: 3087 Descrip ...

  7. HDU 1025 Constructing Roads In JGShining's Kingdom(求最长上升子序列nlogn算法)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1025 解题报告:先把输入按照r从小到大的顺序排个序,然后就转化成了求p的最长上升子序列问题了,当然按p ...

  8. ruby Errors & Exceptions

    When you first started coding, errors were probably the last thing you wanted to see. After all, it’ ...

  9. How to Configure Nginx for Optimized Performance

    Features Pricing Add-ons Resources | Log in Sign up   Guides & Tutorials Web Server Guides Nginx ...

  10. 【转】MySQL中增加sequence管理功能(模拟创建sequence)

    1.oracel可以直接支持sequence,但是mysql不支持sequence,因此我们要通过模拟sequence的方法在mysql中创建sequence.模拟sequence的方法:项目场景:项 ...