private async void listProjects(MyTreeNode hubNode) { var projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = logInInfo.accessToken; string[] idParams = hubNode.id.Split('/'); string hubId = idParams[idParams.Length - 1]; setNodeState(hubNode, true); var projects = await projectsApi.GetHubProjectsAsync(hubId); foreach (KeyValuePair <string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data)) { MyTreeNode projectNode = new MyTreeNode( projectInfo.Value.links.self.href, projectInfo.Value.attributes.name, projectInfo.Value.attributes.extension.type, "", NodeType.Project ); addToTreeView(hubNode, projectNode); } setNodeState(hubNode, false); }
private async Task<IList<jsTreeNode>> GetProjectsAsync(string href) { IList<jsTreeNode> nodes = new List<jsTreeNode>(); // the API SDK ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = Credentials.TokenInternal; // extract the hubId from the href string[] idParams = href.Split('/'); string hubId = idParams[idParams.Length - 1]; var projects = await projectsApi.GetHubProjectsAsync(hubId); foreach (KeyValuePair<string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data)) { // check the type of the project to show an icon string nodeType = "projects"; switch ((string)projectInfo.Value.attributes.extension.type) { case "projects:autodesk.core:Project": nodeType = "a360projects"; break; case "projects:autodesk.bim360:Project": nodeType = "bim360projects"; break; } // create a treenode with the values jsTreeNode projectNode = new jsTreeNode(projectInfo.Value.links.self.href, projectInfo.Value.attributes.name, nodeType, true); nodes.Add(projectNode); } return nodes; }
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); }
public async Task <JArray> GetProjectsAsync() { Credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); if (Credentials == null) { return(null); } // array of projects JArray allProjects = new JArray(); // the API SDK HubsApi hubsApi = new HubsApi(); hubsApi.Configuration.AccessToken = Credentials.TokenInternal; ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = Credentials.TokenInternal; var hubs = await hubsApi.GetHubsAsync(); foreach (KeyValuePair <string, dynamic> hubInfo in new DynamicDictionaryItems(hubs.data)) { string hubType = (string)hubInfo.Value.attributes.extension.type; if (hubType != "hubs:autodesk.bim360:Account") { continue; // skip non-BIM360 hub } string hubId = (string)hubInfo.Value.id; var projects = await projectsApi.GetHubProjectsAsync(hubId); foreach (KeyValuePair <string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data)) { allProjects.Add(JObject.FromObject(new { hub = new { id = hubInfo.Value.id, name = hubInfo.Value.attributes.name }, project = new { id = projectInfo.Value.id, name = projectInfo.Value.attributes.name } })); } } return(new JArray(allProjects.OrderBy(obj => (string)obj["project"]["name"]))); }
private async Task IndexProjectsAsync(Credentials credentials, string hubId, PerformContext context) { // the API SDK ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = credentials.TokenInternal; var projects = await projectsApi.GetHubProjectsAsync(hubId); foreach (KeyValuePair <string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data)) { var folders = await projectsApi.GetProjectTopFoldersAsync(hubId, projectInfo.Value.id); foreach (KeyValuePair <string, dynamic> folder in new DynamicDictionaryItems(folders.data)) { // Project File folder show Files, Plans folder show items:autodesk.bim360:Document // for this sample let's focus on Project Files only try { if (!folder.Value.attributes.extension.data.visibleTypes.ToString().Contains("items:autodesk.bim360:File")) { continue; } } catch { continue; } // if we cannot get visibleTypes, maybe it's Recycle, so let's skip... await GetFolderContentsAsync(credentials.UserId, hubId, folder.Value.links.self.href, 0, context); // string[] hrefParams = folder.Value.links.self.href.Split('/'); string folderUrn = hrefParams[hrefParams.Length - 1]; // start listening for this folder (Project Files) DMWebhook webhooksApi = new DMWebhook(credentials.TokenInternal, Config.WebhookUrl); await webhooksApi.DeleteHook(Event.VersionAdded, folderUrn); // remove old (needed when doing local test with ngrok or to create a new one) await webhooksApi.CreateHook(Event.VersionAdded, projectInfo.Value.id, folderUrn); } } }
public async Task <JArray> GetProjectsAsync(string hubId) { Credentials credentials = await Credentials.FromSessionAsync(base.Request.Cookies, Response.Cookies); // the API SDK ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = credentials.TokenInternal; var projectsDM = await projectsApi.GetHubProjectsAsync(hubId); // 2-legged account:read token TwoLeggedApi oauth = new TwoLeggedApi(); dynamic bearer = await oauth.AuthenticateAsync(Credentials.GetAppSetting("FORGE_CLIENT_ID"), Credentials.GetAppSetting("FORGE_CLIENT_SECRET"), "client_credentials", new Scope[] { Scope.AccountRead }); // get all projects RestClient client = new RestClient(BASE_URL); RestRequest projectsRequest = new RestRequest("/hq/v1/accounts/{account_id}/projects?limit=100", RestSharp.Method.GET); projectsRequest.AddParameter("account_id", hubId.Replace("b.", string.Empty), ParameterType.UrlSegment); projectsRequest.AddHeader("Authorization", "Bearer " + bearer.access_token); IRestResponse projectsResponse = await client.ExecuteTaskAsync(projectsRequest); dynamic projectsHQ = JArray.Parse(projectsResponse.Content); // get business units RestRequest bizUnitsRequest = new RestRequest("/hq/v1/accounts/{account_id}/business_units_structure", RestSharp.Method.GET); bizUnitsRequest.AddParameter("account_id", hubId.Replace("b.", string.Empty), ParameterType.UrlSegment); bizUnitsRequest.AddHeader("Authorization", "Bearer " + bearer.access_token); IRestResponse bizUnitsResponse = await client.ExecuteTaskAsync(bizUnitsRequest); dynamic bizUnits = JObject.Parse(bizUnitsResponse.Content); if (bizUnits.business_units != null) { foreach (dynamic projectHQ in projectsHQ) { foreach (dynamic bizUnit in bizUnits.business_units) { if (projectHQ.business_unit_id == bizUnit.id) { projectHQ.business_unit = bizUnit; } } } } dynamic projectsFullData = new JArray(); foreach (dynamic projectHQ in projectsHQ) { if (projectHQ.status != "active") { continue; } foreach (KeyValuePair <string, dynamic> projectDM in new DynamicDictionaryItems(projectsDM.data)) { if (projectHQ.id == projectDM.Value.id.Replace("b.", string.Empty)) { projectHQ.DMData = JObject.Parse(projectDM.Value.ToString()); break; } } projectsFullData.Add(projectHQ); } return(new JArray(((JArray)projectsFullData).OrderBy(p => (string)p["name"]))); }
private async Task <IList <TreeNode> > GetProjectsAsync(string href) { IList <TreeNode> nodes = new List <TreeNode>(); string[] idParams = href.Split('/'); string hubId = idParams[idParams.Length - 1]; ProjectsApi projectsApi = new ProjectsApi(); projectsApi.Configuration.AccessToken = AccessToken; var projects = await projectsApi.GetHubProjectsAsync(hubId); foreach (KeyValuePair <string, dynamic> projectInfo in new DynamicDictionaryItems(projects.data)) { TreeNode projectNode = new TreeNode(projectInfo.Value.links.self.href, projectInfo.Value.attributes.name, "projects", true); nodes.Add(projectNode); } if (hubId.IndexOf("b.") > -1) { // the HubId on DM shouble be the same as the account ID, prefixed by b. // BIM 360 is accessible via 2-legged tokens TwoLeggedApi twoLeggedApi = new TwoLeggedApi(); dynamic bearer = await twoLeggedApi.AuthenticateAsync(ConfigVariables.FORGE_CLIENT_ID, ConfigVariables.FORGE_CLIENT_SECRET, "client_credentials", new Scope[] { Scope.AccountRead }); string accountId = hubId.Remove(0, 2); RestClient client = new RestClient("https://developer.api.autodesk.com"); RestRequest request = new RestRequest("/hq/v1/accounts/{account_id}/projects?limit=100", RestSharp.Method.GET); request.AddParameter("account_id", accountId, ParameterType.UrlSegment); request.AddHeader("Authorization", "Bearer " + bearer.access_token); IRestResponse response = await client.ExecuteTaskAsync(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { JArray bim360projects = JArray.Parse(response.Content); foreach (JObject bim360project in bim360projects.Children <JObject>()) { var projectName = bim360project.Property("name").Value.ToString(); var projectId = bim360project.Property("id").Value.ToString(); bool projectAlready = false; foreach (TreeNode n in nodes) { if (n.id.Contains(projectId)) { projectAlready = true; break; } } if (!projectAlready) { TreeNode node = new TreeNode(string.Empty, projectName, "projectunavailable", false); nodes.Add(node); } } } } return(nodes); }