Connector API
The ConnectorAPI class provides a set of methods and events to manage and interact with data exchanges within the Autodesk DataExchange UI. It acts as a bridge between the UI and the underlying data exchange functionalities, encapsulating various operations such as creating, updating, deleting, loading, and unloading data exchanges.
Key Components
Following are the keys components of the ConnectorAPI.
- Constructor
Initializes the ConnectorAPI with an Application instance.
var application = new Application(...); var connectorAPI = new ConnectorAPI(application);
- Events
Following are the events available in the ConnectorAPI:
- ConnectorClosed: Triggered when the connector is closed.
- ExchangesLoaded: Triggered when exchanges are loaded in the connector.
// Subscribe to events connectorAPI.ConnectorClosed += (sender, e) => { /* Handle connector closed */ }; connectorAPI.ExchangesLoaded += (sender, e) => { /* Handle exchanges loaded */ };
SuppressUIArgs Class
The SuppressUIArgs class defines a base class and its derived class, DeleteExchangeSuppressUIArgs, is used to manage arguments for suppressing certain UI prompts in an application.
- Base Class: SuppressUIArgs
SuppressUIArgs is an abstract class that serves as a base for other classes needing to provide arguments to suppress UI prompts. As an abstract class, it cannot be instantiated directly. Instead, it is intended to be inherited by other classes that will provide specific implementations.
//// <summary> /// It serves as a common base for classes that provide arguments for suppressing certain UI prompts. /// </summary> public abstract class SuppressUIArgs { }
- Derived Class: DeleteExchangeSuppressUIArgs
The DeleteExchangeSuppressUIArgs class inherits from SuppressUIArgs and provides specific arguments to suppress UI prompts during a “Delete Exchange” operation.
In the following code block, ShowConfirmationMessage is a boolean property that indicates whether a confirmation message box should be shown when performing the delete operation. The constructor initializes ShowConfirmationMessage to true, meaning that by default, the confirmation message will be shown unless explicitly set otherwise.
/// <summary> /// This class contains arguments that can be specified to suppress UI prompts when Delete Exchange is called /// </summary> public class DeleteExchangeSuppressUIArgs : SuppressUIArgs { /// <summary> /// Property to indicate whether a confirmation message box should be displayed when deleting. /// </summary> public bool ShowConfirmationMessage { get; set; } public DeleteExchangeSuppressUIArgs() { this.ShowConfirmationMessage = true; } } var deleteExchangeSuppressUIArgs = new DeleteExchangeSuppressUIArgs { ShowConfirmationMessage = false }; connectorAPI.AddSuppressUIArgs( deleteExchangeSuppressUIArgs);
Show MoreThese classes are likely used in scenarios where certain UI interactions, such as confirmation dialogs, need to be suppressed based on user preferences or specific conditions. For example, when performing batch operations or automated tasks, it might be necessary to suppress these prompts to ensure smooth execution without manual intervention.
Example
In a method designed to perform a delete operation, you will typically encounter the following steps:
public void DeleteExchange(ExchangeItem exchangeItem) { var args = connectorAPI.GetSuppressUIArgs<DeleteExchangeSuppressUIArgs>(); if (args.ShowConfirmationMessage) { // Show confirmation dialog } else { // Proceed with deletion without confirmation } }
Show MoreThis allows the method to conditionally show or suppress the confirmation dialog based on the provided arguments.
In summary, SuppressUIArgs and its derived classes provide a flexible way to control UI behavior in different parts of an application, enhancing user experience and automation capabilities.
UI API Methods
The following are various important methods offered by the Connector UI API:
- CreateExchange: Creates a new data exchange.
// Create a new exchange var exchangeItem = await connectorAPI.CreateExchange("New exchange name", "folderId", "projectId", "hubId");
- UpdateExchange: Updates an existing data exchange.
var exchangeItem = await connectorAPI.UpdateExchange("Exchange name/id");
- DeleteExchange: Deletes a specified data exchange.
connectorAPI.DeleteExchange("Exchange name/id");
- LoadExchange: Loads a specified data exchange.
var dataExchangeIdentifier = new DataExchangeIdentifier { CollectionId = "CollectionId", ExchangeId = "ExchangeId", HubId = "HubId" }; var exchangeItem = await connectorAPI.LoadExchange(dataExchangeIdentifier);
Show More - LoadLatestExchange: Loads the latest details of a specified data exchange.
connectorAPI.LoadLatestExchange("Exchange name/id");
- UnloadExchange: Unloads a specified data exchange.
connectorAPI.UnloadExchange("Exchange name/id");
- SelectElements: Selects elements belonging to specified data exchanges.
var exchangeNames = new List<string> { "ExchangeName1", "ExchangeName2", }; connectorAPI.SelectElements(exchangeNames);
- CopyExchangeLink: Copies the link of a specified data exchange.
connectorAPI.CopyExchangeLink("Exchange name/id");
- ViewExchange: Views a specified data exchange.
connectorAPI.ViewExchange("Exchange name/id");
- GetNotifications: Returns all notifications.
List<Notification> notifications = connectorAPI.GetNotifications();
- GetExchangeItem: Returns details of a specified data exchange.
connectorAPI.GetExchangeItem("ExchangeName");
- GetExchanges: Returns all data exchanges.
IEnumerable<ExchangeItem> exchanges = connectorAPI.GetExchanges();
- CloseConnector: Closes the connector window.
connectorAPI.CloseConnector();
Use ConnectorAPI Class in your Application
Following is an example how you can use the ConnectorAPI class in your application.
var application = new Application(...);
var connectorAPI = new ConnectorAPI(application);
// Subscribe to events
connectorAPI.ConnectorClosed += (sender, e) => { /* Handle connector closed */ };
connectorAPI.ExchangesLoaded += (sender, e) => { /* Handle exchanges loaded */ };
// Create a new exchange
var exchangeItem = await connectorAPI.CreateExchange("New Exchange", "folderId", "projectId", "hubId");
// Get all exchanges
var exchanges = connectorAPI.GetExchanges();
// Close the connector
connectorAPI.CloseConnector();