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.
Now 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: