This sample demonstrates a desktop application that shows BIM 360 Team, BIM 360 Docs and Fusion Team hubs, which respective Projects, Folders, Items and Versions. For each version it is possible to view it using Viewer.
Uses Data Management to list hubs, projects and files. Uses Viewer to show models on a Chromium-based browser, CefSharp.WinForms. A Mongo database is used to store session (OAuth) information.
See this quick video.
When the user opens the desktop application, it redirects to Autodesk Account sign in page using the Forge Client ID stored on the Cloud module. After authenticating, the access_token and refresh_token are stored on a MongoDB database, creating a session ID. This ID is encrypted and sent to the Desktop client.
On the next request, the Desktop client provides the Session ID, the Cloud module uses that to get the respective access_token and connects to Autodesk. Once the data is acquired, it is adjusted and sent to the Desktop client.
The Desktop client will not have access to the access_token.
This sample uses CefSharp.WinForms, based on Chromium Embedded Framework, the open source version of Google Chrome. It's is also available for WPF applications. The build-in .NET WebView is based on Internet Explorer (version 11) and it's have several limitations.
The Cloud module acts as a proxy between the Desktop client and Autodesk data. Only authorized information is returned, including the viewables for Viewer, controlled via Proxy.
To identify the Desktop client, this sample uses a MachineID identifier. For this first version, it is using the MAC address, but this may be improvements.
- Forge Account: Learn how to create a Forge Account, activate subscription and create an app at this tutorial.
- Visual Studio: At least the Community edition
- .NET basic knowledge with C#
- MongoDB: noSQL database, learn more. Or use a online version via Mongo Altas (this is used on this sample)
For using this sample, you need an Autodesk developer credentials. Visit the Forge Developer Portal, sign up for an account, then create an app. For this new app, use http://localhost:3000/api/forge/callback/oauth
as Callback URL. Finally take note of the Client ID and Client Secret.
This sample contains 2 projects: cloud
and desktop
.
MongoDB
MongoDB is a no-SQL database based on "documents", which stores JSON-like data. For testing purpouses, you can either use local or live. For cloud environment, try MongoDB Atlas (offers a free tier). With MongoDB Atlas you can set up an account for free and create clustered instances, intructions:
- Create a account on MongoDB Atlas.
- Under "Collections", create a new database (e.g. named
desktopsample
) with a collection (e.g. namedusers
). - Under "Command Line Tools", whitelist the IP address to access the database, see this tutorial. If the sample is running on Heroku, you'll need to open to all (IP
0.0.0.0/0
). Create a new user to access the database.
At this point the connection string should be in the form of mongodb+srv://<username>:<password>@clusterX-a1b2c4.mongodb.net/desktopsample?retryWrites=true
. Learn more here
There are several tools to view your database, Robo 3T (formerly Robomongo) is a free lightweight GUI that can be used. When it opens, follow instructions here to connect to MongoDB Atlas.
WebConfig
Open the web.config
and edit the Forge Client ID, Secret and Callback URL. The OAUTH_DATABASE should point to your MongoDB instance.
<appSettings>
<add key="FORGE_CLIENT_ID" value="" />
<add key="FORGE_CLIENT_SECRET" value="" />
<add key="FORGE_CALLBACK_URL" value="" />
<add key="OAUTH_DATABASE" value="" />
</appSettings>
Open the app.config
file and specify the webserver address under appSettings:
<appSettings>
<add key="serverAddress" value="http://localhost:3000" />
</appSettings>
For local testing, the desktop module should work "as is".
To debug, make sure to launch both projects. On the Solution Explorer, right-click on the solution and go to properties, under Startup Project select both.
IMPORTANT: this sample implements minimum error check for simplicity, not ready for production environment.
The cloud
project should be deployed live, any .NET compatible host should work, including (but not limited to):
- Appharbor: check this steps to configure your Forge Client ID & Secret.
- AWS Elastic Beanstalk: check this tutorial.
Consider upgrading the mLab account to production.
Then the desktop
module should be updated with the cloud module address (under appSettings file).
Documentation:
Blogs on Expanding .NET desktop apps into the cloud
Other APIs:
- MongoDB for C# driver
- Mongo Altas Database-as-a-Service for MongoDB
-
The CEF Sharp library should work on
AnyCPU
, but this sample uses onlyx64
version. This issue entry explains how to adjust it, if needed. -
To keep keys locally, the sample defines a
web.keys.config
file that is added to .gitignore. On local development environment, this file stores the keys. When commit to Github, this file is not included. -
The AWS Elastic Beanstalk deployment cannot override
web.config
variables on deployment, so this sample includes a transform on theweb.Release.config
to remove them. With that it should work.
<appSettings>
<add key="FORGE_CLIENT_ID" xdt:Transform="Remove" xdt:Locator="Match(key)" />
<add key="FORGE_CLIENT_SECRET" xdt:Transform="Remove" xdt:Locator="Match(key)" />
<add key="FORGE_CALLBACK_URL" xdt:Transform="Remove" xdt:Locator="Match(key)" />
<add key="OAUTH_DATABASE" xdt:Transform="Remove" xdt:Locator="Match(key)" />
</appSettings>
-
Cannot see my BIM 360 projects: Make sure to provision the Forge App Client ID within the BIM 360 Account, learn more here. This requires the Account Admin permission.
-
cloud module cannot load its dependencies: first clean up the solution, then delete the
.vs
(hidden) andpackages
folder. Make sure thecloud
project is set toAnyCPU
and thedesktop
project is either 32 or 64 bit. Rebuild.
This sample is licensed under the terms of the MIT License. Please see the LICENSE file for full details.
Augusto Goncalves @augustomaia, Forge Partner Development