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);
            }
        }
示例#2
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);
        }
        public async Task <bool> GetIsSessionValid()
        {
            string sessionId, localId;

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

            return(await OAuthDB.IsSessionIdValid(sessionId, localId));
        }
示例#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));
            }
        }
示例#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);
        }
示例#6
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);
        }
示例#7
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);
        }
示例#8
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);
        }