Getting Existing Vault Connection Through API

Getting Existing Vault Connection Through API

Tiffany_Hayden_
Collaborator Collaborator
602 Views
6 Replies
Message 1 of 7

Getting Existing Vault Connection Through API

Tiffany_Hayden_
Collaborator
Collaborator

I'm creating a Vault Addin and I need to get the existing connection through vault. The user has already connected to vault and logged in. And there is already an existing connection when I need to do my logic. Is there a way to do this? Any help would be appreciated. Thanks! 

 

Autodesk.DataManagement.Client.Framework.Vault.Currency.Connections.Connection connection ;

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Accepted solutions (1)
603 Views
6 Replies
Replies (6)
Message 2 of 7

Markus.Koechl
Autodesk
Autodesk

For an Inventor Addin, I'd recommend following this approach: add a reference to the Inventor-Vault library Connectivity.Application.VaultBase. Then create a readonly property that represents an existing connection: iLogic-Vault/iLogic-Vault-QuickstartLibrary/iLogic-Vault QuickstartLibrary.cs at 2023.3 · koechlm/iL....
Validate the connection before you rely on it: iLogic-Vault/iLogic-Vault-QuickstartLibrary/iLogic-Vault QuickstartLibrary.cs at 2023.3 · koechlm/iL...
A Vault extension provides the existing connection best with the logon event argument application: 

 

/// <summary>
/// This function is called after the user logs in to the Vault Server.
/// Part of the IExtension interface.
/// </summary>
/// <param name="application">Provides information about the running application.</param>
public void OnLogOn(IApplication application)
{
    conn = application.Connection;
    mFldrPropDefs = conn?.WebServiceManager.PropertyService.GetPropertyDefinitionsByEntityClassId("FLDR");
}

 



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 3 of 7

Tiffany_Hayden_
Collaborator
Collaborator

@Markus.Koechl - Oh I'm doing a Vault Addin within Vault. Do I need to do anything differently? 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 4 of 7

Markus.Koechl
Autodesk
Autodesk

A Vault "Addin" is an extension. So, the second approach should provide what you need: Your extension class needs to reference the IExporerExtension interface, which includes the LogOn event handler mentioned above.

namespace CloudLinkPanel
{

    /// <summary>
    /// This class implements the IExtension interface, which means it tells Vault Explorer what 
    /// commands and custom tabs are provided by this extension.
    /// </summary>
    public class CloudLinkPanelExtension : IExplorerExtension
    { .......


Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 5 of 7

Tiffany_Hayden_
Collaborator
Collaborator

I have implemented the IExplorerExtension and all is fine. But I need to do some queries to display information and use the "Connection" to do so and was curious how that worked with an extension? @Markus.Koechl 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes
Message 6 of 7

Markus.Koechl
Autodesk
Autodesk
Accepted solution

To have the connection always available, you could implement an internal static connection object and consume whenever the extension class or another class in this namespace needs. A sample: 

 public class VaultExplorerExtension : IExplorerExtension
 {
     // Capture the current theme on startup
     internal static string mCurrentTheme = "light";

     internal static Connection? conn { get; set; }

     internal static IApplication? mApplication { get; set; }

.....

 void IExplorerExtension.OnLogOn(IApplication application)
 {
     conn = application.Connection;
 }

......

consuming the connection to retrieve entities and their details:
// Look for the File object depending on the selected source
Item? mItem = null;
if (selection2.TypeId == SelectionTypeId.File)
{
    // our ISelection.Id is a File.MasterId
    var selectedFile = conn?.WebServiceManager.DocumentService.GetLatestFileByMasterId(selection2.Id);
    if (selectedFile != null)
    {
        var items = conn?.WebServiceManager.ItemService.GetItemsByFileId(selectedFile.Id);
        mItem = items?.FirstOrDefault();
    }
}

 @Tiffany_Hayden_ : Does this resolve your open question?



Markus Koechl

Solutions Engineer PDM, Autodesk Central Europe
0 Likes
Message 7 of 7

Tiffany_Hayden_
Collaborator
Collaborator

Yes it does! Thanks so much. It was a mystery to me how to use the internal connection. I appreciate your help. @Markus.Koechl 

Tiffany Hayden
Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.

EESignature

0 Likes