internal static NestedFolder FindParentFolder(List <string> parentFolders, List <NestedFolder> folderStructure) { NestedFolder resultFolder = null; for (int i = 0; i < parentFolders.Count; i++) { bool foundFolder = false; foreach (NestedFolder folder in folderStructure) { if (folder.name.ToLower() == parentFolders[parentFolders.Count - 1].ToLower()) { resultFolder = folder; } if (folder.name.ToLower() == parentFolders[i].ToLower()) { foundFolder = true; folderStructure = folder.childrenFolders; break; } } if (!foundFolder) { Util.LogError($"No parent folder found in the structure!. Something went wrong. The program has been stopped."); throw new ApplicationException($"Stopping the program... You can see the log file for more information."); } } return(resultFolder); }
internal static void UploadFiles(DataTable table, int rowIndex, FolderWorkflow folderProcess, NestedFolder folder, string projectId, string localFoldersPath) { string localFolderName = table.Rows[rowIndex]["local_folder"].ToString(); if (!string.IsNullOrEmpty(localFolderName)) { if (string.IsNullOrEmpty(localFoldersPath) == true) { Util.LogError($"Argument -f for LocalFoldersPath is not given! The program has been stopped."); throw new ApplicationException($"Stopping the program... You can see the log file for more information."); } string localFolderPath = localFoldersPath + @"\" + localFolderName; bool folderExist = Directory.Exists(localFolderPath); if (folderExist) { Util.LogInfo($"Uploading files from local folder '{localFolderName}' to BIM360 folder '{folder.name}'..."); string[] filePaths = Directory.GetFiles(localFolderPath); List <string> existingFileNames = folderProcess.CustomGetExistingFileNames(projectId, folder.id); List <string> allowedFileTypesPlans = new List <string> { ".rvt", ".pdf", ".dwg", ".dwf", ".dwfx", ".ifc" }; foreach (string filePath in filePaths) { if (!existingFileNames.Contains(Path.GetFileName(filePath))) { // Find root folder NestedFolder rootFolder = folder; while (rootFolder.parentFolder != null) { rootFolder = rootFolder.parentFolder; } string fileExtension = Path.GetExtension(filePath); if (rootFolder.name == "Plans" && !allowedFileTypesPlans.Contains(fileExtension)) { Util.LogImportant($"File with name '{Path.GetFileName(filePath)}' is not a supported file type for folder 'Plans'. Skipping... Supported file types are: '.rvt', '.pdf', '.dwg', '.dwf', '.dwfx', '.ifc'."); continue; } folderProcess.CustomUploadFile(projectId, folder.id, filePath); } else { Util.LogInfo($"File with name '{Path.GetFileName(filePath)}' already exists in folder '{folder.name}'. Skipping..."); } } } else { Util.LogImportant($"Local folder with name {localFolderName} does not exist! Check if the folder is placed in the correct directory. Skipping files..."); } } }
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($""); } }
internal static NestedFolder CreateFoldersAndAssignPermissions(DataTable table, int rowIndex, List <HqUser> projectUsers, FolderWorkflow folderProcess, List <NestedFolder> folders, NestedFolder currentFolder, BimProject project, ProjectUserWorkflow projectUserProcess) { bool isUserAtRow = !string.IsNullOrEmpty(table.Rows[rowIndex]["user_email"].ToString()); bool isRoleAtRow = !string.IsNullOrEmpty(table.Rows[rowIndex]["role_permission"].ToString()); string folderColumnName = GetFolderColumnName(table, rowIndex); // Check if folder at this row if (folderColumnName != null) { string currFolderName = table.Rows[rowIndex][folderColumnName].ToString(); List <string> currParentFolders = GetParentFolders(table, rowIndex, folderColumnName); // If currently subfolder if (currParentFolders.Count > 0) { NestedFolder currParentFolder = FindParentFolder(currParentFolders, folders); currentFolder = RecursiveFindFolder(currFolderName, currParentFolder.childrenFolders); if (currentFolder == null) { currentFolder = CreateFolder(folderProcess, project.id, currParentFolder, currFolderName, currParentFolders[0]); } else { Util.LogInfo($"Folder in '{currParentFolders[0]}' already exists with name: {currFolderName}."); } if (isUserAtRow || isRoleAtRow) { AssignPermission(table, rowIndex, projectUsers, folderProcess, currentFolder, project, projectUserProcess); } } // If currently a root folder else { if (isUserAtRow || isRoleAtRow) { Util.LogInfo($"\nCurrently at root folder '{currFolderName}'...\n"); NestedFolder rootFolder = folders.Find(x => x.name.ToLower() == currFolderName.ToLower()); AssignPermission(table, rowIndex, projectUsers, folderProcess, rootFolder, project, projectUserProcess); currentFolder = rootFolder; } } } // Asign user to folder if user at row but no folder at row else if ((isUserAtRow || isRoleAtRow) && folderColumnName == null) { if (currentFolder != null) { AssignPermission(table, rowIndex, projectUsers, folderProcess, currentFolder, project, projectUserProcess); } } return(currentFolder); }
/// <summary> /// /// </summary> /// <param name="roots"></param> /// <returns></returns> private Folder getNestedFolder(NestedFolder roots) { var currentFolder = new Folder(roots.name); foreach (var iterfolder in roots.childrenFolders) { currentFolder.AddSubFolder(getNestedFolder(iterfolder)); } return(currentFolder); }
internal static List <string> CopyParentFolders(NestedFolder folder) { List <string> parentFolders = new List <string>(); while (folder.parentFolder != null) { folder = folder.parentFolder; parentFolders.Add(folder.name); } return(parentFolders); }
internal static NestedFolder CreateFolder(FolderWorkflow folderProcess, string projectId, NestedFolder parentFolder, string folderName, string rootFolderName) { Util.LogInfo($"Creating folder in '{rootFolderName}' with name: {folderName}..."); string newFolderId = folderProcess.CustomCreateFolder(projectId, parentFolder.id, folderName); NestedFolder subFolder = new NestedFolder(folderName, newFolderId, parentFolder); parentFolder.childrenFolders.Add(subFolder); return(subFolder); }
static void Main(string[] args) { // Delete previous versions of log.txt System.IO.File.Delete("Log/logInfo.txt"); System.IO.File.Delete("Log/logImportant.txt"); AppOptions options = AppOptions.Parse(args); ProjectWorkflow projectProcess = new ProjectWorkflow(options); FolderWorkflow folderProcess = new FolderWorkflow(options); ProjectUserWorkflow projectUserProcess = new ProjectUserWorkflow(options); AccountWorkflow accountProcess = new AccountWorkflow(options); DataTable csvData = projectProcess.CustomGetDataFromCsv(); List <BimProject> projects = projectProcess.GetAllProjects(); List <BimCompany> companies = null; BimProject currentProject = null; List <HqUser> projectUsers = null; List <NestedFolder> folders = null; NestedFolder currentFolder = null; for (int row = 0; row < csvData.Rows.Count; row++) { string projectName = csvData.Rows[row]["project_name"].ToString(); if (!string.IsNullOrEmpty(projectName)) { Util.LogImportant($"\nCurrent project: {projectName}"); currentProject = projects.Find(x => x.name == projectName); if (currentProject == null) { projects = projectProcess.CustomCreateProject(csvData, row, projectName, projectProcess); currentProject = projects.Find(x => x.name == projectName); CheckProjectCreated(currentProject, projectName); } folders = folderProcess.CustomGetFolderStructure(currentProject); companies = accountProcess.CustomUpdateCompanies(csvData, row, accountProcess); projectUsers = projectUserProcess.CustomUpdateProjectUsers(csvData, row, companies, currentProject, projectUserProcess); } currentFolder = CreateFoldersAndAssignPermissions(csvData, row, projectUsers, folderProcess, folders, currentFolder, currentProject, projectUserProcess); UploadFilesFromFolder(csvData, row, folderProcess, currentFolder, currentProject.id, options.LocalFoldersPath); } }
public NestedFolder GetFoldersHierarchy(string projectId, NestedFolder thisFolder) { if (projectId.StartsWith("b.") == false) { projectId = "b." + projectId; } try { // keep the current folder permission List <FolderPermission> folderPermissions = new List <FolderPermission>(); IRestResponse res = GetFolderPermissions(projectId, thisFolder.id, out folderPermissions); if (res.StatusCode == System.Net.HttpStatusCode.OK) { thisFolder.permissions.AddRange(folderPermissions); } IList <NestedFolder> output = new List <NestedFolder>(); //get the subfolders and items residing in the folder IList <Folder> subFolders = GetSubFolders(projectId, thisFolder.id); IList <Data> items = GetItems(projectId, thisFolder.id); if (subFolders != null) { //process each subfolder foreach (Folder folder in subFolders) { NestedFolder subFolder = new NestedFolder(folder.attributes.name, folder.id, thisFolder); //now process the sub-subfolders within this subfolder NestedFolder subFolderWithChildren = GetFoldersHierarchy(projectId, subFolder); thisFolder.childrenFolders.Add(subFolderWithChildren); } } if (items != null) { thisFolder.items = items; } return(thisFolder); } catch (Exception ex) { throw ex; } }
internal static NestedFolder RecursiveFindFolder(string folderName, List <NestedFolder> folderStructure) { NestedFolder resultFolder = null; foreach (NestedFolder folder in folderStructure) { if (folder.name.ToLower() == folderName.ToLower()) { resultFolder = folder; break; } if (folder.childrenFolders.Count > 0) { resultFolder = RecursiveFindFolder(folderName, folder.childrenFolders); } } return(resultFolder); }
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; } }
/// <summary> /// runs the upload to the BIM360 environment /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Upload_OnClick(object sender, RoutedEventArgs e) { var progress = new updates_upload(); progress.Show(); // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(AccProjectConfig.ExportBim360Projects()); MemoryStream dataset = new MemoryStream(byteArray); //dataset.Position = 0; //Updates progress.pgb.Value = 10; progress.ProgressLabel.Content = "Build Connection"; // ProgressBar "refresh" CallDispatch(progress); //maybe change string[] input = new string[] { "-c", ClientId, "-s", ClientSecret, "-a", BimId, "-h", AdminMail, "-f", " .\\sample", "-t", ",", "-z", ",", "-e", "UTF-8", "-d", "yyyy-MM-dd" }; // Delete previous versions of log.txt System.IO.File.Delete("Log/logInfo.txt"); System.IO.File.Delete("Log/logImportant.txt"); AppOptions options = AppOptions.Parse(input); // options.AccountRegion = "EU"; options.AdminRole = "Project Manager"; ProjectWorkflow projectProcess = new ProjectWorkflow(options); System.Threading.Thread.Sleep(1000); // load all existing projects from the BIM360 environment List <BimProject> projects = projectProcess.GetAllProjects(); FolderWorkflow folderProcess = new FolderWorkflow(options); ProjectUserWorkflow projectUserProcess = new ProjectUserWorkflow(options); AccountWorkflow accountProcess = new AccountWorkflow(options); //Updates progress.pgb.Value = 25; progress.ProgressLabel.Content = "Convert Data from GUI"; // ProgressBar "refresh" CallDispatch(progress); // load data from custom CSV file. Filepath was set in constructor of projectProcess by pushing the options instance DataTable csvData = new DataTable(); csvData = ProjectWorkflow.CustomGetDataFromCsv_stream(dataset); //Updates progress.pgb.Value = 40; progress.ProgressLabel.Content = "Uploading"; // ProgressBar "refresh" CallDispatch(progress); List <BimCompany> companies = null; BimProject currentProject = null; List <HqUser> projectUsers = null; List <NestedFolder> folders = null; NestedFolder currentFolder = null; //Uploading try { for (int row = 0; row < csvData.Rows.Count; row++) { string projectName = csvData.Rows[row]["project_name"].ToString(); // check if the current row defines the start point for another project (project_name column must be set) if (!string.IsNullOrEmpty(projectName)) { Util.LogImportant($"\nCurrent project: {projectName}"); // check if the requested project name is already present inside BIM360 currentProject = projects.Find(x => x.name == projectName); if (currentProject == null) { // create the project projects = projectProcess.CustomCreateProject(csvData, row, projectName, projectProcess); // set the current project variable to the recently created project currentProject = projects.Find(x => x.name == projectName); // verify the initialization of the new project CheckProjectCreated(currentProject, projectName); } // create the folder structure folders = folderProcess.CustomGetFolderStructure(currentProject); // add the companies companies = accountProcess.CustomUpdateCompanies(csvData, row, accountProcess); // create or update the project users projectUsers = projectUserProcess.CustomUpdateProjectUsers(csvData, row, companies, currentProject, projectUserProcess); //activate all services ServiceWorkflow serviceProcess = new ServiceWorkflow(options); //check what servers needs to be activated if (ServiceTab.CheckBoxservices.IsChecked == true) { #region Add Services var listname = new List <string>(); listname.Add("admin"); listname.Add("doc_manage"); if (ServiceTab.CheckBoxpm.IsChecked == true) { listname.Add("pm"); } if (ServiceTab.CheckBoxfng.IsChecked == true) { listname.Add("fng"); } if (ServiceTab.CheckBoxcollab.IsChecked == true) { listname.Add("collab"); } if (ServiceTab.CheckBoxcost.IsChecked == true) { listname.Add("cost"); } if (ServiceTab.CheckBoxgng.IsChecked == true) { listname.Add("gng"); } if (ServiceTab.CheckBoxglue.IsChecked == true) { listname.Add("glue"); } if (ServiceTab.CheckBoxplan.IsChecked == true) { listname.Add("plan"); } if (ServiceTab.CheckBoxfield.IsChecked == true) { listname.Add("field"); } if (ServiceTab.CheckBoxassete.IsChecked == true) { listname.Add("assets"); } #endregion var serviceList = new List <ServiceActivation>(); foreach (var iter in listname) { serviceList.Add(new ServiceActivation()); serviceList.Last().service_type = iter; serviceList.Last().project_name = projectName; //test hardcoded Test company name needs to be enter or find out serviceList.Last().company = ServiceTab.Company.Text.Trim(); serviceList.Last().email = AdminMail; } serviceProcess.ActivateServicesProcess( new List <BimProject>(new BimProject[] { currentProject }), serviceList); } } // assign permissions currentFolder = CreateFoldersAndAssignPermissions(csvData, row, projectUsers, folderProcess, folders, currentFolder, currentProject, projectUserProcess); // run the file upload if requested UploadFilesFromFolder(csvData, row, folderProcess, currentFolder, currentProject.id, options.LocalFoldersPath); //Updates progress.pgb.Value = 50 + (50 / csvData.Rows.Count * row); progress.ProgressLabel.Content = "Uploading"; // ProgressBar "refresh" CallDispatch(progress); } } catch (Exception ex) { //show the error statusbar.Text = ex.Message; progress.Close(); return; } statusbar.Text = "Upload successful"; progress.Close(); }
static void Main(string[] args) { // Delete previous versions of log.txt System.IO.File.Delete("Log/logInfo.txt"); System.IO.File.Delete("Log/logImportant.txt"); AppOptions options = AppOptions.Parse(args); // options.AccountRegion = "EU"; ProjectWorkflow projectProcess = new ProjectWorkflow(options); FolderWorkflow folderProcess = new FolderWorkflow(options); ProjectUserWorkflow projectUserProcess = new ProjectUserWorkflow(options); AccountWorkflow accountProcess = new AccountWorkflow(options); // load data from custom CSV file. Filepath was set in constructor of projectProcess by pushing the options instance DataTable csvData = projectProcess.CustomGetDataFromCsv(); // load all existing projects from the BIM360 environment List <BimProject> projects = projectProcess.GetAllProjects(); List <BimCompany> companies = null; BimProject currentProject = null; List <HqUser> projectUsers = null; List <NestedFolder> folders = null; NestedFolder currentFolder = null; for (int row = 0; row < csvData.Rows.Count; row++) { string projectName = csvData.Rows[row]["project_name"].ToString(); // check if the current row defines the start point for another project (project_name column must be set) if (!string.IsNullOrEmpty(projectName)) { Util.LogImportant($"\nCurrent project: {projectName}"); // check if the requested project name is already present inside BIM360 currentProject = projects.Find(x => x.name == projectName); if (currentProject == null) { // create the project projects = projectProcess.CustomCreateProject(csvData, row, projectName, projectProcess); // set the current project variable to the recently created project currentProject = projects.Find(x => x.name == projectName); // verify the initialization of the new project CheckProjectCreated(currentProject, projectName); } // create the folder structure folders = folderProcess.CustomGetFolderStructure(currentProject); // add the companies companies = accountProcess.CustomUpdateCompanies(csvData, row, accountProcess); // create or update the project users projectUsers = projectUserProcess.CustomUpdateProjectUsers(csvData, row, companies, currentProject, projectUserProcess); } // assign permissions currentFolder = CreateFoldersAndAssignPermissions(csvData, row, projectUsers, folderProcess, folders, currentFolder, currentProject, projectUserProcess); // run the file upload if requested UploadFilesFromFolder(csvData, row, folderProcess, currentFolder, currentProject.id, options.LocalFoldersPath); } }
private void RecursivelyCreateFolder(string projId, string uid, string parentFolderId, NestedFolder newFolder) { Log.Info("-- copying child folder: " + newFolder.name); // Try to create folders until it is actually created string newFolderId = _foldersApi.CreateFolder(projId, uid, parentFolderId, newFolder.name); if (newFolderId == "error") { if (retryCounter < 10) { retryCounter++; Log.Warn($"Error occured while creating the folder: {newFolder.name}. Retrying ({retryCounter.ToString()}/10)"); RecursivelyCreateFolder(projId, uid, parentFolderId, newFolder); } else { Log.Warn($"Retry attempt for creating folder has reached the limit. Couldn't copy all folders."); return; } } else { retryCounter = 0; // Reset the counter Log.Info("-- assigning role permission to folder: " + newFolder.name); // assign permission to the new created folder bool res = _foldersApi.AssignPermission(projId, newFolderId, newFolder.permissions, uid); if (!res) { Log.Warn($"Failed to assgn role permissions to the new created folder: {newFolder.name}."); } if (newFolder.childrenFolders.Count > 0) { foreach (NestedFolder childFolder in newFolder.childrenFolders) { RecursivelyCreateFolder(projId, uid, newFolderId, childFolder); } } } }
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($""); } }
internal static void UploadFilesFromFolder(DataTable table, int rowIndex, FolderWorkflow folderProcess, NestedFolder currentFolder, string projectId, string localFoldersPath) { bool isFolderAtRow = !string.IsNullOrEmpty(table.Rows[rowIndex]["local_folder"].ToString()); string folderColumnName = GetFolderColumnName(table, rowIndex); // Check if folder at this row if (folderColumnName != null && isFolderAtRow) { UploadFiles(table, rowIndex, folderProcess, currentFolder, projectId, localFoldersPath); } // Upload files from folder if local folder given at row but no BIM360 folder at row else if (isFolderAtRow && folderColumnName == null) { if (currentFolder != null) { UploadFiles(table, rowIndex, folderProcess, currentFolder, projectId, localFoldersPath); } } }
/// <summary> /// runs the upload to the BIM360 environment /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Upload_OnClick(object sender, RoutedEventArgs e) { var progress = new updates_upload(); progress.Show(); //main window closing prevention try { // convert string to stream byte[] byteArray = Encoding.UTF8.GetBytes(AccProjectConfig.ExportBim360Projects()); MemoryStream dataset = new MemoryStream(byteArray); //dataset.Position = 0; //Updates progress.pgb.Value = 10; progress.ProgressLabel.Content = "Build Connection"; // ProgressBar "refresh" CallDispatch(progress); //input for upload string[] input = new string[] { "-c", ClientId, "-s", ClientSecret, "-a", BimId, "-h", AdminMail, "-f", " .\\sample", "-t", ",", "-z", ",", "-e", "UTF-8", "-d", "yyyy-MM-dd" }; // specify a folder in the %APPDATA% to store the logging files var loggingFolder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); // Delete previous versions of log.txt try { System.IO.File.Delete(Path.Combine(loggingFolder, "Bim360Interface/logInfo.txt")); System.IO.File.Delete(Path.Combine(loggingFolder, "Bim360Interface/logInfo_important.txt")); } catch (Exception exception) { Console.WriteLine(exception); // throw; } AppOptions options = AppOptions.Parse(input); // options.AccountRegion = "EU"; options.AdminRole = "Project Manager"; ProjectWorkflow projectProcess = new ProjectWorkflow(options); System.Threading.Thread.Sleep(1000); // load all existing projects from the BIM360 environment List <BimProject> projects = projectProcess.GetAllProjects(); FolderWorkflow folderProcess = new FolderWorkflow(options); ProjectUserWorkflow projectUserProcess = new ProjectUserWorkflow(options); AccountWorkflow accountProcess = new AccountWorkflow(options); // this is the admin mail to activate the projects var adminMail = AdminMail; //Get defaut company name string defaultcomp; try { defaultcomp = folderProcess.CustomDefaultCompanyName(adminMail); } catch (NullReferenceException) { defaultcomp = "DefaultCompany"; } //Updates progress.pgb.Value = 25; progress.ProgressLabel.Content = "Convert Data from GUI"; // ProgressBar "refresh" CallDispatch(progress); // load data from custom CSV file. Filepath was set in constructor of projectProcess by pushing the options instance DataTable csvData = new DataTable(); csvData = ProjectWorkflow.CustomGetDataFromCsv_stream(dataset); //Updates progress.pgb.Value = 40; progress.ProgressLabel.Content = "Uploading"; // ProgressBar "refresh" CallDispatch(progress); List <BimCompany> companies = null; BimProject currentProject = null; List <HqUser> projectUsers = null; List <NestedFolder> folders = null; NestedFolder currentFolder = null; //Uploading try { for (int row = 0; row < csvData.Rows.Count; row++) { string projectName = csvData.Rows[row]["project_name"].ToString(); // check if the current row defines the start point for another project (project_name column must be set) if (!string.IsNullOrEmpty(projectName)) { Util.LogImportant($"\nCurrent project: {projectName}"); // check if the requested project name is already present inside BIM360 currentProject = projects.Find(x => x.name == projectName); if (currentProject == null) { // create the project projects = projectProcess.CustomCreateProject(csvData, row, projectName, projectProcess); // set the current project variable to the recently created project currentProject = projects.Find(x => x.name == projectName); // verify the initialization of the new project CheckProjectCreated(currentProject, projectName); } // create the folder structure folders = folderProcess.CustomGetFolderStructure(currentProject, adminMail); // add the companies companies = accountProcess.CustomUpdateCompanies(csvData, row, accountProcess); // create or update the project users projectUsers = projectUserProcess.CustomUpdateProjectUsers(csvData, row, companies, currentProject, projectUserProcess); //activate services ServiceWorkflow serviceProcess = new ServiceWorkflow(options); #region Add Services // admin and doc_manage should be always activated var serviceShortcuts = new List <string> { "admin", "doc_manage" }; // check which service should be activated in addition to admin and doc_manage if (ServiceTab.CheckBoxProjectManagement.IsChecked == true) { serviceShortcuts.Add("pm"); } if (ServiceTab.CheckBoxFieldManagement.IsChecked == true) { serviceShortcuts.Add("fng"); } if (ServiceTab.CheckBoxDesignCollab.IsChecked == true) { serviceShortcuts.Add("collab"); } if (ServiceTab.CheckBoxCostManagement.IsChecked == true) { serviceShortcuts.Add("cost"); } if (ServiceTab.CheckBoxgng.IsChecked == true) { serviceShortcuts.Add("gng"); } if (ServiceTab.CheckBoxglue.IsChecked == true) { serviceShortcuts.Add("glue"); } if (ServiceTab.CheckBoxPlan.IsChecked == true) { serviceShortcuts.Add("plan"); } if (ServiceTab.CheckBoxField.IsChecked == true) { serviceShortcuts.Add("field"); } if (ServiceTab.CheckBoxAssets.IsChecked == true) { serviceShortcuts.Add("assets"); } #endregion var serviceList = new List <ServiceActivation>(); foreach (var serviceShortcut in serviceShortcuts) { //ToDo: this part needs revision serviceList.Add(new ServiceActivation() { email = AdminMail, service_type = serviceShortcut, project_name = projectName, company = defaultcomp }); } // take the current project and activate all services that were checked serviceProcess.ActivateServicesProcess( new List <BimProject>(new BimProject[] { currentProject }), serviceList); } // assign permissions currentFolder = CreateFoldersAndAssignPermissions(csvData, row, projectUsers, folderProcess, folders, currentFolder, currentProject, projectUserProcess); // run the file upload if requested UploadFilesFromFolder(csvData, row, folderProcess, currentFolder, currentProject.id, options.LocalFoldersPath); //Updates progress.pgb.Value = 50 + (50 / csvData.Rows.Count * row); progress.ProgressLabel.Content = "Uploading"; // ProgressBar "refresh" CallDispatch(progress); } } catch (Exception ex) { //show the error statusbar.Text = ex.Message; progress.Close(); return; } statusbar.Text = "Upload successful"; progress.Close(); } catch (Exception ex) { this.statusbar.Text = "Error on upload:" + ex.Message; progress.Close(); } }
internal static void AssignUserPermissionToFolder(FolderWorkflow folderProcess, NestedFolder folder, HqUser user, string letterPermission, string ProjectId) { Util.LogInfo($"Assigning permission '{letterPermission}' to folder '{folder.name}' for user '{user.email}'."); List <string> permissionLevel = GetPermission(letterPermission); if (permissionLevel == null) { permissionLevel = new List <string> { "VIEW", "COLLABORATE" }; Util.LogImportant($"Permission '{letterPermission}' for user '{user.email}' for folder '{folder.name}' was not recognized. Default permission 'V' is taken for this folder."); } List <FolderPermission> curr_permissions = new List <FolderPermission>(); curr_permissions.Add(new FolderPermission() { subjectId = user.id, subjectType = "USER", actions = permissionLevel, inheritActions = permissionLevel }); folderProcess.CustomAssignPermissionToFolder(ProjectId, folder.id, curr_permissions); }
internal static void AssignPermission(DataTable table, int rowIndex, List <HqUser> projectUsers, FolderWorkflow folderProcess, NestedFolder folder, BimProject project, ProjectUserWorkflow projectUserProcess) { // Add role permission string roleName = table.Rows[rowIndex]["role_permission"].ToString(); if (!string.IsNullOrEmpty(roleName)) { List <IndustryRole> roles = projectUserProcess.GetRolesForProject(project.name); IndustryRole role = roles.Find(x => x.name.ToLower() == roleName.ToLower()); if (role != null) { string letterPermission = table.Rows[rowIndex]["permission"].ToString(); AssignRolePermissionToFolder(folderProcess, folder, role, letterPermission, project.id); } else { Util.LogImportant($"No role found with name: {roleName}. No permission for this role for folder '{folder.name}' will be assigned. See row number {rowIndex + 2} in the CSV-File."); } } // Add user permission string userEmail = table.Rows[rowIndex]["user_email"].ToString(); if (!string.IsNullOrEmpty(userEmail)) { HqUser existingUser = projectUsers.Find(x => x.email == userEmail); // Check if user exists if (existingUser != null) { string letterPermission = table.Rows[rowIndex]["permission"].ToString(); AssignUserPermissionToFolder(folderProcess, folder, existingUser, letterPermission, project.id); } else { Util.LogImportant($"No user found with email: {userEmail}. No permission for this user for folder '{folder.name}' will be assigned. See row number {rowIndex + 2} in the CSV-File."); } } }
internal static void AssignRolePermissionToFolder(FolderWorkflow folderProcess, NestedFolder folder, IndustryRole role, string letterPermission, string ProjectId) { Util.LogInfo($"Assigning permission '{letterPermission}' to folder '{folder.name}' for role '{role.name}'."); List <string> permissionLevel = GetPermission(letterPermission); if (permissionLevel == null) { permissionLevel = new List <string> { "VIEW", "COLLABORATE" }; Util.LogImportant($"Permission '{letterPermission}' for role '{role.name}' for folder '{folder.name}' was not recognized. Default permission 'V' is taken for this folder."); } List <FolderPermission> currPermissions = new List <FolderPermission> { new FolderPermission() { subjectId = role.id, subjectType = "ROLE", actions = permissionLevel, inheritActions = permissionLevel } }; folderProcess.CustomAssignPermissionToFolder(ProjectId, folder.id, currPermissions); }