List user’s accessible vaults in Autodesk Vault Explorer Extension

By Daniel Du

One customer wants to know how the get the accessible vaults for a user group in a Vault Explorer Extension with API. As you know, we can get the list from Vault Explorer UI, Tools –> Administration –> Global Settings –> Groups… to open group management dialogue, double click one group and click “Vaults…” button to see the accessible vaults.

imageNow let’s do it with API, here is the code snippet to do the same with 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);
            }
        }
    }
}

And here is the result:

image


Comments

One response to “List user’s accessible vaults in Autodesk Vault Explorer Extension”

  1. I tried your code and its working fine but I have a requirement such I have to list all the vaults associated with the Administrator account(i.e all the vaults) in a check box. I tried
    GroupInfo grpInfo = mgr.AdminService.GetGroupInfoByGroupId(groups.Id);
    foreach (var vault in grpInfo.Vaults)
    {
    vtemp += vault.Id + “:” + vault.Name + “\n”;
    }
    But only the first vault is displayed. I am not sure what is the problem in my code. Can you help me

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading