Ejemplo n.º 1
0
        public async Task <IList <Item> > GetTopFoldersAsync(string hubId, string projectId)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            IList <Item> nodes = new List <Item>();

            ProjectsApi projectsApi = new ProjectsApi();

            projectsApi.Configuration.AccessToken = userAccessToken;
            var folders = await projectsApi.GetProjectTopFoldersAsync(hubId, projectId);

            foreach (KeyValuePair <string, dynamic> folderInfo in new DynamicDictionaryItems(folders.data))
            {
                Item projectNode = new Item(folderInfo.Value.links.self.href, folderInfo.Value.attributes.displayName, "folders");
                nodes.Add(projectNode);
            }

            return(nodes);
        }
Ejemplo n.º 2
0
        public async Task <UserResponse> GetUserProfile()
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            UserProfileApi userProfileApi = new UserProfileApi();

            userProfileApi.Configuration.AccessToken = userAccessToken;
            try
            {
                dynamic user = await userProfileApi.GetUserProfileAsync();

                UserResponse response = new UserResponse();
                response.firstName = user.firstName;
                response.lastName  = user.lastName;

                return(response);
            }
            catch (Exception e)
            {
                return(null);
            }
        }
Ejemplo n.º 3
0
        public async Task <bool> GetIsSessionValid()
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(false);
            }

            return(await OAuthDB.IsSessionIdValid(sessionId, localId));
        }
Ejemplo n.º 4
0
        public async Task <HttpResponseMessage> Get()
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            if (_httpClient == null)
            {
                _httpClient = new HttpClient(
                    // this should avoid HttpClient seaching for proxy settings
                    new HttpClientHandler()
                {
                    UseProxy = false,
                    Proxy    = null
                }, true);
                _httpClient.BaseAddress = new Uri(FORGE_BASE_URL);
                ServicePointManager.DefaultConnectionLimit = int.MaxValue;
            }

            string url         = Request.RequestUri.AbsolutePath.Replace(PROXY_ROUTE, string.Empty);
            string resourceUrl = url + Request.RequestUri.Query;

            try
            {
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, resourceUrl);

                // add our Access Token
                request.Headers.Add("Authorization", "Bearer " + userAccessToken);

                HttpResponseMessage response = await _httpClient.SendAsync(request,
                                                                           // this ResponseHeadersRead force the SendAsync to return
                                                                           // as soon as the header is ready, faster
                                                                           HttpCompletionOption.ResponseHeadersRead);

                return(response);
            }
            catch
            {
                return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError));
            }
        }
Ejemplo n.º 5
0
        public async Task <IList <Item> > GetHubs()
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            HubsApi hubsApi = new HubsApi();

            hubsApi.Configuration.AccessToken = userAccessToken;

            IList <Item> nodes = new List <Item>();
            var          hubs  = await hubsApi.GetHubsAsync();

            foreach (KeyValuePair <string, dynamic> hubInfo in new DynamicDictionaryItems(hubs.data))
            {
                string hubType = "hubs";
                switch ((string)hubInfo.Value.attributes.extension.type)
                {
                case "hubs:autodesk.core:Hub":
                    hubType = "hubs";
                    break;

                case "hubs:autodesk.a360:PersonalHub":
                    hubType = "personalhub";
                    break;

                case "hubs:autodesk.bim360:Account":
                    hubType = "bim360hubs";
                    break;
                }
                Item item = new Item(hubInfo.Value.links.self.href, hubInfo.Value.attributes.name, hubType);
                nodes.Add(item);
            }

            return(nodes);
        }
Ejemplo n.º 6
0
        protected async void Page_Load(object sender, EventArgs e)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return;
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return;
            }

            string urn        = Page.Request.QueryString["urn"];
            string proxyRoute = string.Format("{0}/api/forge/viewerproxy/", Request.Url.GetLeftPart(UriPartial.Authority));

            string script = string.Format("<script>showModel('{0}', '{1}');</script>", urn, proxyRoute);

            ClientScript.RegisterStartupScript(GetType(), "ShowModel", script);
        }
Ejemplo n.º 7
0
        public async Task <IList <Item> > GetProjectsAsync(string hubId)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            IList <Item> nodes = new List <Item>();

            ProjectsApi projectsApi = new ProjectsApi();

            projectsApi.Configuration.AccessToken = userAccessToken;
            var projects = await projectsApi.GetHubProjectsAsync(hubId);

            foreach (KeyValuePair <string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data))
            {
                string projectType = "projects";
                switch ((string)projectInfo.Value.attributes.extension.type)
                {
                case "projects:autodesk.core:Project":
                    projectType = "a360projects";
                    break;

                case "projects:autodesk.bim360:Project":
                    projectType = "bim360projects";
                    break;
                }
                Item projectNode = new Item(projectInfo.Value.links.self.href, projectInfo.Value.attributes.name, projectType);
                nodes.Add(projectNode);
            }

            return(nodes);
        }
Ejemplo n.º 8
0
        public async Task <IList <Item> > GetItemVersionsAsync(string projectId, string itemId)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            IList <Item> versionsList = new List <Item>();

            ItemsApi itemsApi = new ItemsApi();

            itemsApi.Configuration.AccessToken = userAccessToken;
            var versions = await itemsApi.GetItemVersionsAsync(projectId, itemId);

            foreach (KeyValuePair <string, dynamic> version in new DynamicDictionaryItems(versions.data))
            {
                DateTime versionDate = version.Value.attributes.lastModifiedTime;

                string urn = string.Empty;
                try { urn = (string)version.Value.relationships.derivatives.data.id; }
                catch { urn = "not_available"; } // some BIM 360 versions don't have viewable

                Item itemNode = new Item("/versions/" + urn, versionDate.ToString("dd/MM/yy HH:mm:ss"), "versions");

                versionsList.Add(itemNode);
            }

            return(versionsList);
        }
Ejemplo n.º 9
0
        public async Task <IList <Item> > GetFolderContentsAsync(string projectId, string folderId)
        {
            string sessionId, localId;

            if (!HeaderUtils.GetSessionLocalIDs(out sessionId, out localId))
            {
                return(null);
            }
            if (!await OAuthDB.IsSessionIdValid(sessionId, localId))
            {
                return(null);
            }
            string userAccessToken = await OAuthDB.GetAccessToken(sessionId, localId);

            IList <Item> folderItems = new List <Item>();

            FoldersApi folderApi = new FoldersApi();

            folderApi.Configuration.AccessToken = userAccessToken;
            var folderContents = await folderApi.GetFolderContentsAsync(projectId, folderId);

            foreach (KeyValuePair <string, dynamic> folderContentItem in new DynamicDictionaryItems(folderContents.data))
            {
                string displayName = folderContentItem.Value.attributes.displayName;
                if (string.IsNullOrWhiteSpace(displayName))
                {
                    continue;
                }

                Item itemNode = new Item(folderContentItem.Value.links.self.href, displayName, (string)folderContentItem.Value.type);

                folderItems.Add(itemNode);
            }

            return(folderItems);
        }