8

Вопрос по svn, c# – Управлять сервером VisualSVN из C #

Я установил VisualSVN Server 2.5.4. Я могу создать пользователя и хранилище. У меня вопрос, как я могу создать / удалить пользователя / репозиторий из C #. Есть ли библиотека?

  • 12

    Error: User Rate Limit Exceeded

    Update 03/09/2015

    .

    You can create a new repository MySuperRepo by running this PowerShell command:

    New-SvnReposiory MySuperRepo

    You can create a project structure in the repository

    New-SvnRepositoryItem MySuperRepo -Path /branches, /tags, /trunk -Type Folder

    You can provide DOMAIN\Developers Active Directory group account with Read / Write access to the new repository

    Add-SvnAccessRule MyRepo -Path / -AccountName DOMAIN\Developers -Access ReadWrite

    You can calculate the size the repository takes on disk:

    Measure-SvnRepository MySuperRepo

    You can verify the repository for corruptions:

    Test-SvnRepository MySuperRepo

    And much, much more!

    .

    %VISUALSVN_SERVER%\WMI

    This C# code will create a Subversion user 'user1' with password 'secret'.

        ManagementClass userClass = new ManagementClass("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);
    

    This C# code will create a new repository 'Repo1'.

        ManagementClass repoClass = new ManagementClass("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);
    

    This C# code will provide SID S-1-5-32-545 ('BUILTIN\Users') with Read / Write access to repository 'Test'. FYI: The AccessLevel values are as described in the MOF: "0 - no access, 1 - read only, 2 - read/write".

    ManagementClass userClass = new ManagementClass("root\\VisualSVN", "VisualSVN_WindowsAccount", null);                            
    ManagementClass authzClass = new ManagementClass("root\\VisualSVN", "VisualSVN_SecurityDescriptor", null);
    ManagementClass permClass = new ManagementClass("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 = new ManagementObject("VisualSVN_Repository.Name='Test'");
    
    ManagementBaseObject inParams =
        authzClass.GetMethodParameters("SetSecurity");
    
    inParams["Object"] = repo;
    inParams["Permissions"] = new object[] { permObject };
    
    ManagementBaseObject outParams =
        authzClass.InvokeMethod("SetSecurity", inParams, null);
    

    Updated on 02/10/2013:

    create VisualSVN_Repository class object specifying repository name, create VisualSVN_PermissionEntry entry object specifying account username and access permissions,

    invoke SetSecurity method on VisualSVN_Repository passing valid repository path and PermissionEntry object.

        ManagementClass userClass = new ManagementClass("root\\VisualSVN", "VisualSVN_WindowsAccount", null);
        ManagementClass permClass = new ManagementClass("root\\VisualSVN", "VisualSVN_PermissionEntry", null);
        ManagementClass repoClass = new ManagementClass("root\\VisualSVN", "VisualSVN_Repository", 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 repoObject = repoClass.CreateInstance();
        repoObject.SetPropertyValue("Name", "MyProject");
    
        ManagementBaseObject inParams =
            repoClass.GetMethodParameters("SetSecurity");
    
        inParams["Path"] = "/trunk";
        inParams["Permissions"] = new object[] { permObject };
    
        ManagementBaseObject outParams =
            repoObject.InvokeMethod("SetSecurity", inParams, null);