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 查看评论