Setting up the SDK
The following steps illustrate how you can initialize the SDK after the installation of the Data Exchange .NET SDK is completed. In addition to the provided steps, you can also initialize the SDK to your specific requirements by incorporating additional steps, configurations, or modifications to the default setup.
Initializing the SDK using the default setup
Use the default setup provided by the Data Exchange .NET SDK out of the box to initialize the SDK. The following code sample illustrates the default method of initializing the SDK.
Register an App (if not done already) and note down the values of ClientId, ClientSecret, and CallBack and pass them to the client object. This grants access to the Data Exchange functionality, offering methods for retrieving and updating both data and metadata associated with Data Exchanges.
string AuthClientID = "Your App Client id";
string AuthClientSecret = "Your App Client Secret";
string AuthCallBack = "Your App CallBack URL";
SDKOptionsDefaultSetup SdkOptionsDefaultSetup = new SDKOptionsDefaultSetup()
{
ClientId = AuthClientID,
ClientSecret = AuthClientSecret,
CallBack = AuthCallBack,
ConnectorName = "Revit-Connector",
ConnectorVersion = "1.0.0",
HostApplicationName = "Revit",
HostApplicationVersion = "2023.0.1"
};
The Applications that use the authentication provider of SDK must initialize the client in an async manner as this will open the browser for authentication and should be enclosed in a try-catch block as shown in the following code sample.
// Asynchronous
try
{
IClient Client = await Task.Run(() => new Client(SdkOptionsDefaultSetup));
}
catch (Exception ex)
{
}
// Synchronous
IClient Client = new Client(SdkOptionsDefaultSetup);
Creating a Logger object
Create an ILogger Interface object and use it across the application to log the messages in the log file. The ILogger Interface object enables the logging of events, messages, and errors during execution, offering valuable insight for application debugging, monitoring, and maintenance.
var AppWorkspaceDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
string AppBasePath = Path.Combine(AppWorkspaceDirectory, "YourApplicationName");
var LogDirectoryPath = Path.Combine(AppBasePath, "logs");
ILogger Logger = new Log(LogDirectoryPath);
Creating Auth object
Register an App (if not done already) and note down the values of ClientId, ClientSecret, and CallBack. Pass these values to the IAuth object, and this step will authenticate the connector SDK. The Logger object is optional and can be added only if needed.
string AuthClientID = "Your App Client id";
string AuthClientSecret = "Your App Client Secret";
string AuthCallBack = "Your App CallBack URL"
var AuthOption = new AuthOptions
{
ClientId = AuthClientID,
ClientSecret = AuthClientSecret,
CallBack = AuthCallBack,
Logger = Logger
};
IAuth Auth = new Auth(AuthOption);
Creating Storage object :
Create an object of the IStorage Interface, this Interface provides functionality for storing data in a cache-like manner.
IStorage Storage = new Storage(AppBasePath);
Creating HostingProvider object
Create an object of IHostingProvider Interface. The IHostingProvider provides functionalities for accessing Hubs, Projects, Folders, and many more within the Autodesk Construction Cloud (ACC) using the API and the ACC facilitates the connection to ACC APIs.
IHostingProvider HostingProvider = new ACC(Logger, () => Auth.GetAuthToken());
Creating Geometry configuration object
Create an object of the GeometryConfiguration Object, the Geometry configuration instance is used to configure GUSDK configurations such as STEPProtocol, STEPTolerance, etc.
GeometryConfiguration GeometryConfiguration = new GeometryConfiguration()
{
STEPProtocol = STEPProtocol.ConfigurationControlledDesign,
STEPTolerance = 0.001
} ;
Creating SDKOptions object
Pass the values of the objects from the preceding steps to the SDKOptions object. It provides an option to DataExchange SDK such as Authentication, Storage, Hosting, logger, and so on.
var sdkOptions = new SDKOptions
{
AuthProvider = Auth,
Storage = Storage,
SourceProvider = new SourceProvider.SourceProvider(),
ContractProvider = new ContractProvider.ContractProvider(),
HostingProvider = HostingProvider,
Logger = Logger,
ConnectorName = "Revit-Connector",
ConnectorVersion = "1.0.0",
HostApplicationName = "Revit",
HostApplicationVersion = "2023.0.1"
};
Creating Client object
Pass the SdkOptions object to the IClient interface, this grants access to the Data Exchange functionality, offering methods for retrieving and updating both data and metadata associated with Data Exchanges.
The Applications that use the authentication provider of SDK must initialize the client in an async manner as this will open the browser for authentication and should be enclosed in a try-catch block as shown in the following code sample.
// Asynchronous
try
{
IClient Client = await Task.Run(() => new Client(SdkOptions));
}
catch (Exception ex)
{
}
// Synchronous
IClient Client = new Client(SdkOptions);