码迷,mamicode.com
首页 > Windows程序 > 详细

[译]C#控制管理VisualSVN Server

时间:2015-09-18 15:15:42      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:

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

 

http://www.cnblogs.com/zhangqs008/p/3763829.html

[译]C#控制管理VisualSVN Server

标签:

原文地址:http://www.cnblogs.com/chen110xi/p/4819095.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!