By Daniel Du
You probablay have noticed that Vault 2014 releases a new client – Thin Client with completely new UI. It is really a light one, you do not need to install anything on client side, a broswer is good enough. Thin Client performs read-access tasks in a vault, such as searching the vault and viewing file history using a web browser. If you have not noticed this, try it now, goto http://servername/AutodeskTC in your broswer, where servername is either the IP address or the name of the computer hosting Autodesk Data Management Server.
In this post, I will introduce how to integerate Vault Explorere and Vault ThinClient. I will create a Vault Explorer plugin, which enable users to right click a file or folder in Explorer and view it in Vault ThinClient. This is a just a demonstration, you may have better idea to use this permnent link, for example, save it into your database or ERP systems. In Autodesk Vault 2014 API, KnowledgeVaultService provides functions to get/set the persistent ID of entites. GetPersistentIds and ResolvePersistentIds in the KnowledgeVaultService are the functions to use for converting between file IDs and the persistent IDs. Keep in mind that there are two types of persistent IDs for files. If EntPersistOpt is History, the Persistent ID is for a specific file version. If EntPersistOpt is Latest, the Persistent ID is for the latest version of the file. The caller has to know which type to use. There is no way to tell the type by looking at the Persistent ID itself. Another tricky part is that, the PersistentId retrieved from Vault API is not the exact id of ThinClient URL, here is the core snippet of generating url of files and folders in ThinClient:
string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
VDF.Vault.Currency.Entities.EntityClassIds.Files,
new long[] { file.Id },
Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);
string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/
Details?id=m{3}=&itemtype=File",
serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);
string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
VDF.Vault.Currency.Entities.EntityClassIds.Folder,
new long[] { folder.Id },
Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);
string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/
Entities?folder=m{3}=&start=0",
serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);
Please note that there is “m” in front of the persistent ID, which may confuse you, but it is how it works :) Following is the comple code for this plugin:
using Autodesk.Connectivity.Explorer.Extensibility;
using Autodesk.Connectivity.Extensibility.Framework;
using Autodesk.Connectivity.WebServices;
using Autodesk.Connectivity.WebServicesTools;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Windows.Forms;
using VDF = Autodesk.DataManagement.Client.Framework;
[assembly: ApiVersion("6.0")]
[assembly: ExtensionId("76491449-B3FB-4570-81C4-17FE48BF50CB")]
namespace ThinClientUrlExtension
{
public class ThinClientUrlGenerator : IExplorerExtension
{
VDF.Vault.Currency.Connections.Connection currentConnection;
public IEnumerable<CommandSite> CommandSites()
{
CommandItem ThinClientUrlCmd = new CommandItem(
"Autodesk.ADN.PermaLink", "View in Thin Client...")
{
NavigationTypes = new SelectionTypeId[] {
SelectionTypeId.File,
SelectionTypeId.FileVersion,
SelectionTypeId.Folder },
MultiSelectEnabled = false
};
ThinClientUrlCmd.Execute += ThinClientUrlCmd_Execute;
CommandSite permaLinkFileContextSite = new CommandSite(
"Autodesk.ADN.PermaLinkFileContext", "PermaLinkFileContext")
{
DeployAsPulldownMenu = false,
Location = CommandSiteLocation.FileContextMenu
};
permaLinkFileContextSite.AddCommand(ThinClientUrlCmd);
CommandSite permaLinkFolderContextSite = new CommandSite(
"Autodesk.ADN.PermaLinkFolderContext", "PermaLinkFolderContext")
{
DeployAsPulldownMenu = false,
Location = CommandSiteLocation.FolderContextMenu
};
permaLinkFolderContextSite.AddCommand(ThinClientUrlCmd);
List<CommandSite> sites = new List<CommandSite>();
sites.Add(permaLinkFileContextSite);
sites.Add(permaLinkFolderContextSite);
return sites;
}
void ThinClientUrlCmd_Execute(object sender, CommandItemEventArgs e)
{
WebServiceManager webMgr = currentConnection.WebServiceManager;
ISelection selectedItem = e.Context.CurrentSelectionSet.FirstOrDefault<ISelection>();
if (selectedItem != null)
{
Uri serverUri = new Uri(webMgr.InformationService.Url);
string url;
if (selectedItem.TypeId == SelectionTypeId.File)
{
File file = webMgr.DocumentService.GetLatestFileByMasterId(selectedItem.Id);
if (file == null)
{
return;
}
string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
VDF.Vault.Currency.Entities.EntityClassIds.Files,
new long[] { file.Id },
Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);
string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Details?id=m{3}=&itemtype=File",
serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);
//Open with default broswer
Process.Start(url);
//copy url to clipboard
Clipboard.SetText(url);
}
if (selectedItem.TypeId == SelectionTypeId.Folder)
{
Folder folder = webMgr.DocumentService.GetFolderById(selectedItem.Id);
if (folder == null)
{
return;
}
string[] ids = webMgr.KnowledgeVaultService.GetPersistentIds(
VDF.Vault.Currency.Entities.EntityClassIds.Folder,
new long[] { folder.Id },
Autodesk.Connectivity.WebServices.EntPersistOpt.Latest);
string id = ids[0];
id = id.TrimEnd('=');
url = string.Format("{0}://{1}/AutodeskTC/{1}/{2}#/Entity/Entities?folder=m{3}=&start=0",
serverUri.Scheme, serverUri.Host, currentConnection.Vault, id);
//Open with default broswer
Process.Start(url);
//copy url to clipboard
Clipboard.SetText(url);
}
}
}
public void OnLogOn(IApplication application)
{
currentConnection = application.Connection;
}
public IEnumerable<CustomEntityHandler> CustomEntityHandlers()
{
throw new NotImplementedException();
}
public IEnumerable<DetailPaneTab> DetailTabs()
{
throw new NotImplementedException();
}
public IEnumerable<string> HiddenCommands()
{
throw new NotImplementedException();
}
public void OnLogOff(IApplication application)
{
}
public void OnShutdown(IApplication application)
{
}
public void OnStartup(IApplication application)
{
}
}
}
Let’s take a look at how it works:
Hope it helps!