如何在C#中向Visual SVN服务器添加权限条目[重复]

问题描述 投票:5回答:1

此问题已经在这里有了答案:

我看过this question,并使它可以创建存储库并使用WMI界面为用户添加权限。我现在遇到的问题是:如果我要更新我创建的存储库并将another用户添加到该存储库,它将清除当前使用情况(将其完全从存储库中删除),并仅添加一个人。

所以,我需要弄清楚如何做两件事:

  1. 将用户添加到现有存储库中
  2. 从现有存储库中删除用户

我认为一旦有了,我就能弄清其余的互动内容。我参考了wof文件,并找到了我认为需要实现的这些条目:

类VisualSVN_Repository

[provider("VisualSVNWMIProvider"), dynamic]
class VisualSVN_Repository
    {
    [Description ("Repository name"), key]
    string Name;

    ...
    [implemented] void GetSecurity([in] string Path,
                               [out] VisualSVN_PermissionEntry Permissions[]);
    [implemented] void SetSecurity([in] string Path,
                               [in] VisualSVN_PermissionEntry Permissions[],
                               [in] boolean ResetChildren = false);
}

我正在像这样实现集合安全性:

static public void UpdatePermissions(string sid, string repository, AccessLevel level, bool isAdmin = false)
{
    ManagementClass repoClass = new ManagementClass("root\\VisualSVN", "VisualSVN_Repository", null);
     ManagementObject repoObject = repoClass.CreateInstance();
    repoObject.SetPropertyValue("Name", repository);

    ManagementBaseObject inParams =
        repoClass.GetMethodParameters("SetSecurity");

    inParams["Path"] = "/";
    inParams["Permissions"] = new object[] { permObject };

    ManagementBaseObject outParams =
        repoObject.InvokeMethod("SetSecurity", inParams, null);
}

这有效,但正如我所说,仅适用于一个用户。似乎它清除了其中的所有内容,仅添加了一个用户对象。

我认为我需要与之交互的另一种方法是“ GetSecurity”,它看起来像返回了一个VisualSVN_PermissionEntry数组

VisualSVN_PermissionEntry

class VisualSVN_PermissionEntry
{
    VisualSVN_Account Account;
    uint32 AccessLevel;
};

因此,这具有一个AccessLevel属性和VisualSVN_Account对象

VisualSVN_Account(我正在使用Windows身份验证,所以我需要使用该身份验证)]

[provider("VisualSVNWMIProvider"), dynamic, abstract]
class VisualSVN_Account
{
};

class VisualSVN_WindowsAccount : VisualSVN_Account
{
    [key] string SID;
};

所以这是我迷路的地方。我假定我需要调用“ GetSecurity”,然后遍历那些结果并将它们添加到“ SetSecurity”的输入参数的对象数组中。我似乎无法正常工作。我玩过的一些伪代码,但遇到各种错误(大多数是对象引用错误):

ManagementBaseObject inSecParams=
        repoClass.GetMethodParameters("GetSecurity");

    inSecParams["Path"] = "/";

ManagementBaseObject existingPerms =
        repoObject.InvokeMethod("GetSecurity");

//now I need to loop through the array existingPerms and add them to an array of VisualSVN_PermissionEntry object.

--or--
//can I take this result and just add the users I need to add to it somehow.
c# svn wmi visualsvn-server
1个回答
5
投票

我前一阵子是从visualSVN的某人那里得到的,我应该将工作解决方案粘贴到其中!

© www.soinside.com 2019 - 2024. All rights reserved.