By Daniel Du
When doing vault customization, we generally just make it one of the three types: explore plug-in, custom job or event hander, which means we probably just implement one of these three interfaces: IExplorerExtension, IJob, or IWebServiceExtension. But as you know, in .net it is possible to implement more than one interface, it applies to vault customization as well, sometimes, we have to do that, implementing multiple interface to do our job.
Let’s say we are trying to monitoring the life cycle state change event and then update the file properties on Vault Explorer, and of cause a class implementing IWebServiceExtension and then hooking the event in OnLoad is the direct solution. We can obtain IExplorerUtil within the UpdateFileLifecycleStateEvents.Post-event using LoadExplorerUtil. In general, it works fine, but when it is running in Vault Explorer, it will be problematic. When entities life cycle changed, the Explorer grid will be empty. We should use GetExplorerUtil, not LoadExplorerUtil if running inside Vault Explorer. We can call System.Diagnostics.Process.GetCurrentProcess().ProcessName to figure out what the running process is. But if we just implement the IWebServiceExtension interface, we cannot call GetExplorerUtil, as it need a an Instance of Autodesk.Connectivity.Explorer.Extensibility.IApplication as a parameter, what should we do?
In this case, we need to implement IExplorerExtension as well, here is a code sample:
[assembly: ApiVersion("6.0")]
[assembly: ExtensionId("ff477652-5bdf-438d-975a-d8e61580d39c")]
namespace MultiInterfaceSample
{
//if you rename this class name, please make sure change accordingly in vaultplugin.vcet.config
public class Class1 : IWebServiceExtension, IExplorerExtension
{
private IApplication m_explorerApplication = null;
#region IExplorerExtenion implemenation
public IEnumerable<CommandSite> CommandSites()
{
return null;
}
…
public void OnStartup(IApplication application)
{
m_explorerApplication = application;
DocumentServiceExtensions.UpdateFileLifecycleStateEvents.Post +=
new EventHandler<UpdateFileLifeCycleStateCommandEventArgs>(UpdateFileLifecycleStateEvents_Post);
}
#endregion
#region IWebServiceExtension implementation
public void OnLoad()
{
// regeister web service command events here if running outside Vault Explorer.
// If running inside Vault Explorer, OnStartup is where these events are registered.
if (System.Diagnostics.Process.GetCurrentProcess().ProcessName != "Connectivity.VaultPro")
{
DocumentServiceExtensions.UpdateFileLifecycleStateEvents.Post +=
new EventHandler<UpdateFileLifeCycleStateCommandEventArgs>(UpdateFileLifecycleStateEvents_Post);
}
}
void UpdateFileLifecycleStateEvents_Post(object sender, UpdateFileLifeCycleStateCommandEventArgs e)
{
IExplorerUtil explorerUtil = null;
string procName = System.Diagnostics.Process.GetCurrentProcess().ProcessName;
if (procName == "Connectivity.VaultPro")
{
explorerUtil = ExplorerLoader.GetExplorerUtil(m_explorerApplication);
}
else
{
long userId = 1;
explorerUtil = ExplorerLoader.LoadExplorerUtil("server", "vaultName", userId, "ticket");
}
//implement your logic
}
#endregion
}
}
And here is the vcet.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectivity.ExtensionSettings3>
<extension
interface="Autodesk.Connectivity.WebServices.IWebServiceExtension,
Autodesk.Connectivity.WebServices, Version=18.0.0.0, Culture=neutral, PublicKeyToken=aa20f34aedd220e1"
type="MultiInterfaceSample.Class1, MultiInterfaceSample">
</extension>
<extension
interface="Autodesk.Connectivity.Explorer.Extensibility.IExplorerExtension,
Autodesk.Connectivity.Explorer.Extensibility, Version=18.0.0.0, Culture=neutral, PublicKeyToken=aa20f34aedd220e1"
type="MultiInterfaceSample.Class1, MultiInterfaceSample">
</extension>
</connectivity.ExtensionSettings3>
</configuration>
In fact, the JobProcessorApiSamples sample application that is packaged with the SDK is another example. Hope this helps.