private TopFolderResponse GetTopFolders(string projId) { IRestResponse response = _hubsApi.GetTopFolders(projId); TopFolderResponse content = JsonConvert.DeserializeObject <TopFolderResponse>(response.Content); return(content); }
private bool CustomRootFoldersExist(TopFolderResponse topFolderRes) { if (topFolderRes.data == null) { return(false); } bool plansExist = false; bool projectFilesExist = false; for (int i = 0; i < topFolderRes.data.Length; i++) { if (topFolderRes.data[i].attributes.name.ToLower() == "plans") { plansExist = true; } if (topFolderRes.data[i].attributes.name.ToLower() == "project files") { projectFilesExist = true; } } if (!plansExist || !projectFilesExist) { return(false); } else { return(true); } }
private List <NestedFolder> CustomExtractFolderStructure(BimProject orgProj) { if (!folderStructures.ContainsKey(orgProj.name)) { List <NestedFolder> existingFolderStructure = new List <NestedFolder>(); Util.LogInfo($""); Util.LogInfo($"Folder structure extraction started"); Util.LogInfo("- retrieving top folders from " + orgProj.id); // call TopFolder to get the initial folder ids to start TopFolderResponse topFolderRes = GetTopFolders(orgProj.id); if (!CustomRootFoldersExist(topFolderRes)) { Util.LogInfo("No top folders retrieved."); // Wait until new project's folders are created for (int i = 0; i < 6; i++) { Util.LogInfo("Waiting for project's folders to be created..."); Thread.Sleep(5000); topFolderRes = GetTopFolders(orgProj.id); if (CustomRootFoldersExist(topFolderRes)) { break; } } if (!CustomRootFoldersExist(topFolderRes)) { Util.LogError($"There was a problem retrievieng root folders for project {orgProj.name}. The program has been stopped. Try running the program again."); throw new ApplicationException($"Stopping the program... You can see the log file for more information."); } } Util.LogInfo("- retrieving sub-folders for 'Plans' and 'Project Files' folder. This could take a while.."); // Iterate root folders foreach (Folder folder in topFolderRes.data) { string folderName = folder.attributes.name; if (folderName == "Project Files" || folderName == "Plans") { NestedFolder rootFolder = new NestedFolder(folderName, folder.id); // recursive calls to fetch folder structure NestedFolder rootWithChildrenFolder = _foldersApi.GetFoldersHierarchy(orgProj.id, rootFolder); existingFolderStructure.Add(rootWithChildrenFolder); } } folderStructures[orgProj.name] = existingFolderStructure; return(existingFolderStructure); } else { throw new ApplicationException($""); } }
private TopFolderResponse GetTopFolders(string projId) { IRestResponse response = _hubsApi.GetTopFolders(projId); //error message if project couldn´t reache if (!response.IsSuccessful) { Util.LogError($"Project can not be activated!\n" + $"Rename the Project and try again!\n"); throw new Exception($"Project can not be activated!\n" + $"Try again! If the same error occurs ->Rename the project"); } TopFolderResponse content = JsonConvert.DeserializeObject <TopFolderResponse>(response.Content); return(content); }
private void ExtractFolderStructure(BimProject orgProj) { if (folderStructures.ContainsKey(orgProj.name)) { return; } else { List <NestedFolder> existingFolderStructure = new List <NestedFolder>(); Log.Info($""); Log.Info($"Folder structure extraction started"); Log.Info("- retrieving top folders from " + orgProj.id); // call TopFolder to get the initial folder ids to start TopFolderResponse topFolderRes = GetTopFolders(orgProj.id); if (topFolderRes.data == null || topFolderRes.data.Count() == 0) { Log.Warn("No top folders retrieved."); return; } Log.Info("- retrieving sub-folders for 'Plans' and 'Project Files' folder. This could take a while.."); // Iterate root folders foreach (Folder folder in topFolderRes.data) { string folderName = folder.attributes.name; if (folderName == "Project Files" || folderName == "Plans") { NestedFolder rootFolder = new NestedFolder(folderName, folder.id); // recursive calls to fetch folder structure NestedFolder rootWithChildrenFolder = _foldersApi.GetFoldersHierarchy(orgProj.id, rootFolder); existingFolderStructure.Add(rootWithChildrenFolder); } } folderStructures[orgProj.name] = existingFolderStructure; } }
private void CopyProjectFolders(BimProject orgProj, string newProjId, string uid) { Log.Info(""); Log.Info("Project copy process started."); // Get root folders TopFolderResponse newTopFoldersRes = null; Log.Info("- retrieving top folders from " + newProjId); // quick fix for potential endless loop - add retry count as break condition int retry = 0; do { do { newTopFoldersRes = GetTopFolders(newProjId); Thread.Sleep(2000); retry++; if (retry > 20) { break; } } while (newTopFoldersRes.data == null); if (retry > 20) { break; } } while (newTopFoldersRes.data.Where(x => x.attributes.name == "Project Files").ToList().Count < 1); if (retry > 20) { Log.Warn("Couldn't get top folders of template project. No folders are copied."); return; } // Iterate root folders and match the name with original project folders Log.Info("- copying folders(including folder permission of role) to the new project."); foreach (Folder newRootFolder in newTopFoldersRes.data) { if (folderStructures.ContainsKey(orgProj.name)) { NestedFolder existingRootFolder = folderStructures[orgProj.name].Find(x => x.name == newRootFolder.attributes.name); if (existingRootFolder != null) { // Without below, access to the project is forbidden... Thread.Sleep(3000); // assign permission to root folder first Log.Info("- assigning role permissions to root folder: " + newRootFolder.attributes.name); bool res = _foldersApi.AssignPermission(newProjId, newRootFolder.id, existingRootFolder.permissions, uid); if (!res) { Log.Warn($"Failed to assgn role permissions to root folder: {newRootFolder.attributes.name}."); } Log.Info("- copying the subfolders(including folder permission of role) of root folder: " + newRootFolder.attributes.name); foreach (NestedFolder childFolder in existingRootFolder.childrenFolders) { // Recursively create new child folders RecursivelyCreateFolder(newProjId, uid, newRootFolder.id, childFolder); } } } } }
private List <NestedFolder> CustomExtractFolderStructure(BimProject orgProj, string adminMail) { // check if current project is activated var roleIds = GetIndustryRoleIds(orgProj.name, null); var admin = GetAdminUser(adminMail); var activated = ActivateProject(orgProj.id, admin, roleIds); if (!folderStructures.ContainsKey(orgProj.name)) { List <NestedFolder> existingFolderStructure = new List <NestedFolder>(); Util.LogInfo($""); Util.LogInfo($"Folder structure extraction started"); Util.LogInfo("- retrieving top folders from " + orgProj.id); // call TopFolder to get the initial folder ids to start TopFolderResponse topFolderRes = GetTopFolders(orgProj.id); if (!CustomRootFoldersExist(topFolderRes)) { Util.LogInfo("No top folders retrieved."); // Wait until new project's folders are created for (int i = 0; i < 6; i++) { Util.LogInfo("Waiting for project's folders to be created..."); Thread.Sleep(5000); // query the BIM360 hubs API and check if the current project already owns the requested folders Util.LogInfo("Query BIM360 and check of current project already contains folders."); topFolderRes = GetTopFolders(orgProj.id); if (CustomRootFoldersExist(topFolderRes)) { Util.LogInfo( "All CustomRootFolders exist already. "); // ToDo: please check if this log message relates with the intention of the method break; } } if (!CustomRootFoldersExist(topFolderRes)) { Util.LogError( $"There was a problem retrieving root folders for project {orgProj.name}. The program has been stopped. Try running the program again."); throw new ApplicationException( $"Stopping the program... You can see the log file for more information."); } } Util.LogInfo( "- retrieving sub-folders for 'Plans' and 'Project Files' folder. This could take a while.."); // Iterate root folders foreach (Folder folder in topFolderRes.data) { string folderName = folder.attributes.name; if (folderName == "Project Files" || folderName == "Plans") { NestedFolder rootFolder = new NestedFolder(folderName, folder.id); // recursive calls to fetch folder structure NestedFolder rootWithChildrenFolder = _foldersApi.GetFoldersHierarchy(orgProj.id, rootFolder); existingFolderStructure.Add(rootWithChildrenFolder); } } folderStructures[orgProj.name] = existingFolderStructure; return(existingFolderStructure); } else { throw new ApplicationException($""); } }