通过API找出Autodesk Vault中某个用户组可以访问的Vault

首先在Vault Explorer中可以这样查看和更改某个用户组有权访问的vault

Tools –> Administration –> Global Settings –> Groups… 打开用户组管理对话框, 双击某个组,点“Vaults…” 按钮即可查看和编辑这个组所能访问的vault。

image

 

现在通过API来实现,没啥说的,直接上代码:

using Autodesk.Connectivity.Explorer.Extensibility;
using Autodesk.Connectivity.WebServices;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using VDF = Autodesk.DataManagement.Client.Framework;

namespace HelloWorldVaultExplorer
{
    public class ListUserGroupVaults : IExplorerExtension
    {
        public IEnumerable<CommandSite> CommandSites()
        {
            CommandItem listGrougVaultsCmdItem = new CommandItem("HelloWorldVaultExplorer.ListUserGroupVaultsCmd",
                                                "List Group Vaults - Daniel");

            listGrougVaultsCmdItem.Execute += listGrougVaultsItem_Execute;

            CommandSite toolsMenuSite = new CommandSite("ListUserGroupVaultsCmd.Toolbar",
                                                    "List Group Vaults Menu- Daniel");
            toolsMenuSite.Location = CommandSiteLocation.ToolsMenu;
            toolsMenuSite.AddCommand(listGrougVaultsCmdItem);

            List<CommandSite> sites = new List<CommandSite>();
            sites.Add(toolsMenuSite);

            return sites;



        }

        void listGrougVaultsItem_Execute(object sender, CommandItemEventArgs e)
        {

           

            try
            {
                //using VDF = Autodesk.DataManagement.Client.Framework
                VDF.Vault.Currency.Connections.Connection connection =
                                e.Context.Application.Connection;

                string msg = "";
                Group[] groups = connection.WebServiceManager.AdminService.GetAllGroups();
                foreach (var group in groups)
                {
                    GroupInfo grpInfo = connection.WebServiceManager.AdminService
                            .GetGroupInfoByGroupId(group.Id);
                    msg += grpInfo.Group.Name + "\n";

                    msg += "Group accessable vaults : \n";
                    if (grpInfo.Vaults == null)
                    {
                        msg += " this group has no accessable vaults. \n";
                        continue;
                    }

                    foreach (var vault in grpInfo.Vaults)
                    {
                        msg += vault.Id + ": " + vault.Name + "\n";
                    }

                }

                MessageBox.Show(msg);



            }
            catch (Exception ex)
            {

                // If something goes wrong, we don't want the exception to bubble up to Vault Explorer.
                MessageBox.Show("Error: " + ex.Message);
            }

        }



    }
}

结果:

image


Related Posts Plugin for WordPress, Blogger...