private void CreateProjects() { Log.Info(""); Log.Info("Creating projects..."); List <BimProject> _projectsToCreate = DataController.GetBimProjects(); if (_projectsToCreate == null || _projectsToCreate.Count < 1) { Log.Info("Project creation was unable to start due to insufficient input data"); return; } for (int i = 0; i < DataController._projectTable.Rows.Count; i++) { string name = Convert.ToString(DataController._projectTable.Rows[i]["name"]); Log.Info($"- processing row {i + 1} - project name: {name}"); BimProject project = _projectsToCreate.FirstOrDefault(p => p.name != null && p.name.Equals(name)); if (project == null || false == CheckRequiredParams(project, DataController._projectTable.Rows[i])) { Log.Error($"There's an incomplete input data"); DataController._projectTable.Rows[i]["result"] = ResultCodes.IncompleteInputData; continue; } DataController.AddProject(project, null, i); } CsvExporter.WriteResults(DataController._projectTable, _options, _options.FilePath); }
public List <HqUser> CustomUpdateProjectUsers(DataTable table, int startRow, List <BimCompany> companies, BimProject project, ProjectUserWorkflow projectUserProcess) { Util.LogInfo("\nRetrieving existing members from project."); List <HqUser> projectUsers = projectUserProcess.CustomGetAllProjectUsers(project.id); Util.LogInfo("Adding members to project."); List <ProjectUser> _projectUsers = CustomGetUsers(table, projectUsers, companies, project.name, startRow); AddUsers(_projectUsers); // Sometimes the users are not fully added and no permission could be added if (_projectUsers.Count > 0) { for (int i = 3; i > 0; i--) { Util.LogInfo($"Waiting for all users to be fully added... Time remaining: {i * 5} seconds..."); System.Threading.Thread.Sleep(5000); } } List <HqUser> updatedProjectUsers = projectUserProcess.CustomGetAllProjectUsers(project.id); return(updatedProjectUsers); }
private bool CheckRequiredParams(BimProject proj) { bool isNull = string.IsNullOrEmpty(proj.name) || string.IsNullOrEmpty(proj.project_type) || string.IsNullOrEmpty(proj.value) || string.IsNullOrEmpty(proj.currency); return(!isNull); }
private List <string> GetIndustryRoleIds(BimProject proj, List <string> roles, string accountId) { BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options); List <IndustryRole> rolesFromProj = new List <IndustryRole>(); List <string> roleIds = new List <string>(); if (roles == null) { roles = new List <string>(); roles.Add(_options.AdminRole); // Default: VDC Manager. For CLI. } _projectsApi.GetIndustryRoles(proj.id, out rolesFromProj, accountId); if (rolesFromProj == null || rolesFromProj.Any() == false) { Log.Warn($"- Couldn't get any project industry roles for project '{proj.name}'"); return(null); } foreach (string role in roles) { string roleId = rolesFromProj.Find(x => x.name == role).id; if (role != null) { roleIds.Add(roleId); } } return(roleIds != null ? roleIds : null); }
public IRestResponse PostProject(BimProject project, string accountId = null) { var request = new RestRequest(Method.POST); //request.Resource = "hq/v1/accounts/{AccountId}/projects"; request.Resource = Urls["projects"]; if (accountId == null) { request.AddParameter("AccountId", options.ForgeBimAccountId, ParameterType.UrlSegment); } else { request.AddParameter("AccountId", accountId, ParameterType.UrlSegment); } JsonSerializerSettings settings = new JsonSerializerSettings(); settings.DateFormatString = "yyyy-MM-dd"; settings.NullValueHandling = NullValueHandling.Ignore; string projectString = JsonConvert.SerializeObject(project, settings); request.AddParameter("application/json", projectString, ParameterType.RequestBody); request.AddHeader("content-type", ContentType); request.AddHeader("authorization", $"Bearer {Token}"); IRestResponse response = ExecuteRequest(request); return(response); }
public static string GetProjectIdByName(string projectName) { BimProject result = null; result = AllProjects.FirstOrDefault(p => p.name.Equals(projectName)); return(result != null ? result.id : null); }
public static void UpdateProject(BimProject project, int rowIndex = -1) { BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options); IRestResponse response = _projectsApi.PatchProjects(project.id, project); HandleUpdateProjectResponse(response, project, rowIndex); }
public static BimProject GetProjectWithServiceById(string projectId) { BimProject result = null; result = GetProject(projectId); return(result != null ? result : null); }
public static BimProject GetProjectById(string projectId) { BimProject result = null; result = AllProjects.FirstOrDefault(p => p.id.Equals(projectId)); return(result != null ? result : null); }
internal static void HandleUpdateProjectResponse(IRestResponse response, BimProject project, int rowIndex = -1) { LogResponse(response); ResponseContent content = null; if (response.StatusCode == System.Net.HttpStatusCode.OK) { BimProject projectResponse = JsonConvert.DeserializeObject <BimProject>(response.Content); BimProject updatedProject = AllProjects.FirstOrDefault(p => p.id == projectResponse.id); _AllProjects.Remove(updatedProject); _AllProjects.Add(projectResponse); if (rowIndex > -1) { _projectTable.Rows[rowIndex]["id"] = projectResponse.id; _projectTable.Rows[rowIndex]["result"] = ResultCodes.ProjectUpdated; } Log.Info($"- project {projectResponse.name} updated. (original Name: {updatedProject.name})"); } else { content = JsonConvert.DeserializeObject <ResponseContent>(response.Content); string msg = ((content != null && content.message != null) ? content.message : null); if (rowIndex > -1) { _projectTable.Rows[rowIndex]["result"] = ResultCodes.Error; _projectTable.Rows[rowIndex]["result_message"] = msg; } Log.Warn($"Status Code: {response.StatusCode.ToString()}\t Message: {msg}"); } }
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($""); } }
public void CopyFoldersProcess() { CsvReader.ReadDataFromProjectCSV(); if (DataController._projectTable.Rows.Count > 0) { foreach (BimProject proj in DataController.GetBimProjects()) { if (string.IsNullOrWhiteSpace(proj.folders_created_from)) { Log.Error($"Project name to copy folders is not provided"); return; } BimProject orgProj = DataController.AllProjects.Find(x => x.name == proj.folders_created_from); if (string.IsNullOrWhiteSpace(proj.service_types)) { orgProj = DataController.GetProjectWithServiceById(orgProj.id); if (orgProj.service_types.Contains("insight")) { proj.service_types = orgProj.service_types.Replace("insight,", ""); } } proj.include_name_to_request_body = true; CopyFoldersProcess(orgProj, proj, _options.HqAdmin); } } }
public static BimProject CustomGetBimProject(DataTable table, int row, string projectName) { BimProject project = new BimProject(); string projectType = table.Rows[row]["project_type"].ToString(); if (!string.IsNullOrEmpty(projectType)) { List <string> projectTypes = GetProjectTypes(); projectTypes = projectTypes.ConvertAll(d => d.ToLower()); if (!projectTypes.Contains(projectType.ToLower())) { // Default type projectType = "Commercial"; Util.LogImportant($"The given project type for project '{projectName}' is not recognized. Default project type '{projectType}' " + $"will be used. Please check the allowed project types! For reference see row number {row + 2} in the CSV-File."); } } project.name = projectName; project.project_type = projectType; // Default values project.value = "0"; project.currency = "EUR"; return(project); }
public void CopyProjectToTargetHubProcess(BimProject orgProj, string targetAccountId, string adminEmail, List <string> roles = null) { Log.Info(""); Log.Info("============================================================"); Log.Info("HUB2HUB PROJECT COPY WORKFLOW started for " + orgProj.name); Log.Info("============================================================"); Log.Info(""); Log.Info($"Creating project by copying data from original project '{orgProj.name}'"); List <string> roleIds = new List <string>(); HqUser admin = new HqUser(); // Get service activated in the original project if (orgProj.service_types == null || orgProj.service_types == "") { orgProj = DataController.GetProjectWithServiceById(orgProj.id); if (orgProj.service_types.Contains("insight")) { orgProj.service_types = orgProj.service_types.Replace("insight,", ""); } } // Check if target hub supports the services // Make sure the target hub is allowing same service types. // Create project to the target hub try { ExtractFolderStructure(orgProj); bool result = CreateProjectFromTargetHub(orgProj, targetAccountId, out string newProjId); if (result) { IRestResponse res = _projectApi.GetProject(newProjId, targetAccountId); BimProject newProj = DataController.HandleGetProjectResponse(res); roleIds = GetIndustryRoleIds(newProj, roles, targetAccountId); admin = GetAdminUserFromTargetHub(adminEmail, targetAccountId); bool status = false; do { status = ActivateProject(newProjId, admin, roleIds, targetAccountId); } while (status == false); if (status) { if (folderStructures.ContainsKey(orgProj.name)) { CopyProjectFolders(orgProj, newProjId, admin.uid); } } } Log.Info(""); Log.Info("HUB2HUB PROJECT COPY WORKFLOW finished for " + orgProj.name); } catch (Exception ex) { Log.Error(ex); } }
internal static void CheckProjectCreated(BimProject project, string projectName) { if (project == null) { Util.LogError($"There was a problem retrieving project with name: {projectName}. The program has been stopped."); throw new ApplicationException($"Stopping the program... You can see the log file for more information."); } }
public static void ArchiveProject(BimProject project) { BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options); project.status = Status.archived; project.include_name_to_request_body = false; project.service_types = ""; IRestResponse response = _projectsApi.PatchProjects(project.id, project); HandleUpdateProjectResponse(response, project); }
private bool CreateProjectFromTargetHub(BimProject proj, string accountId, out string newProjId) { newProjId = DataController.AddProject(proj, accountId); if (newProjId == "error") { Log.Error("- error occured during project creation"); return(false); } Log.Info("- new project id: " + newProjId); return(true); }
private bool CreateProject(BimProject orgProj, BimProject newProj, out string newProjId) { newProjId = DataController.AddProject(newProj); if (newProjId == "error") { Log.Error("- error occured during project creation"); return(false); } Log.Info("- new project id: " + newProjId); return(true); }
public string GetProjectServiceTypes(string projId) { BimProject project = DataController.GetProjectWithServiceById(projId); string _serviceTypes = ""; if (project.service_types.Count() > 0) { _serviceTypes = project.service_types.Replace(',', DefaultConfig.secondDelimiter); } return(_serviceTypes); }
public void ActivateServicesProcess(List <string> projectNames, List <ServiceActivation> service) { List <BimProject> projects = new List <BimProject>(); foreach (string projName in projectNames) { BimProject proj = DataController.AllProjects.Find(x => x.name == projName); projects.Add(proj); } ActivateServicesProcess(projects, service); }
internal static BimProject HandleGetProjectResponse(IRestResponse response) { BimProject project = null; if (response.StatusCode == System.Net.HttpStatusCode.OK) { JsonSerializerSettings settings = new JsonSerializerSettings(); settings.NullValueHandling = NullValueHandling.Ignore; project = JsonConvert.DeserializeObject <BimProject>(response.Content, settings); } return(project); }
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); } }
private bool CheckRequiredParams(BimProject proj, DataRow row) { bool isNull = string.IsNullOrEmpty(proj.name) || string.IsNullOrEmpty(proj.project_type) || string.IsNullOrEmpty(proj.value) || string.IsNullOrEmpty(proj.currency); if (isNull) { string msg = $"One of the required parameters is null or empty. Required are: name, proj_type,value,currency,start_date,end_date"; row["result"] = "Invalid Parameters"; row["result_message"] = msg; Log.Error(msg); } return(!isNull); }
public List <IndustryRole> GetRolesForProject(string projectName) { List <IndustryRole> result = null; if (false == _projectToRolesDict.TryGetValue(projectName, out result)) { BimProject project = DataController.AllProjects.FirstOrDefault(p => p.name != null && p.name.Equals(projectName)); if (project == null) { throw new ApplicationException($"No project found for name '{projectName}'"); } result = DataController.GetProjectRoles(project.id); _projectToRolesDict.Add(projectName, result); } return(result); }
/// <summary> /// Creates a project from custom DataTable /// </summary> /// <param name="table"></param> /// <param name="row"></param> /// <param name="projectName"></param> /// <param name="projectProcess"></param> /// <returns></returns> public List <BimProject> CustomCreateProject(DataTable table, int row, string projectName, ProjectWorkflow projectProcess) { Util.LogInfo("\nCreating project: " + projectName + "\n"); BimProject newProject = DataController.CustomGetBimProject(table, row, projectName); string response = DataController.AddProject(newProject); if (response == "error") { Util.LogError($"There was a problem creating project with name: {projectName}. The program has been stopped."); throw new ApplicationException($"Stopping the program... You can see the log file for more information."); } List <BimProject> updatedProjects = projectProcess.GetAllProjects(); return(updatedProjects); }
public void CopyFoldersProcess(BimProject orgProj, BimProject newProj, string adminEmail, List <string> roles = null) { List <string> roleIds = new List <string>(); HqUser admin = new HqUser(); Log.Info(""); Log.Info("============================================================"); Log.Info("FOLDER COPY WORKFLOW started for " + newProj.name); Log.Info("============================================================"); Log.Info(""); Log.Info($"Creating project by copying data from original project '{orgProj.name}'"); try { if (false == CheckRequiredParams(newProj)) { Log.Error( "One of the required parameters is missing. Required are: Name, Project Type, Value, Currency, Start date, End date"); Log.Error("End procesing for this project"); } ExtractFolderStructure(orgProj); newProj.include_name_to_request_body = true; bool result = CreateProject(orgProj, newProj, out string newProjId); if (result) { roleIds = GetIndustryRoleIds(newProj.name, roles); admin = GetAdminUser(adminEmail); if (true == ActivateProject(newProjId, admin, roleIds)) { CopyProjectFolders(orgProj, newProjId, admin.uid); } } Log.Info(""); Log.Info("FOLDER COPY WORKFLOW finished for " + newProj.name); } catch (Exception ex) { Log.Error(ex); } }
public static IList <BimProject> listProjects(Session paramSession) { string str = "\tSELECT ID, NAME FROM BC_PROJECT WHERE DELETED = 0 or DELETED is null"; System.Collections.IList list = paramSession.createSQLQuery(str).list(); List <object> arrayList = new List <object>(); list.ForEach(paramArrayOfObject => { Number number = (Number)paramArrayOfObject[0]; string str = (string)paramArrayOfObject[1]; BimProject bimProject = new BimProject(); bimProject.Id = Convert.ToInt64(number.longValue()); bimProject.Name = str; paramList.add(bimProject); }); return(arrayList); }
private void UpdateProjects() { Log.Info(""); Log.Info("Updating projects.."); List <BimProject> _projectsToCreate = DataController.GetBimProjects(); for (int i = 0; i < DataController._projectTable.Rows.Count; i++) { string name = Convert.ToString(DataController._projectTable.Rows[i]["name"]); Log.Info($"Processing row {i + 1} - project name: {name}"); BimProject project = _projectsToCreate.FirstOrDefault(p => p.name != null && p.name.Equals(name)); if (project == null || false == CheckRequiredParams(project, DataController._projectTable.Rows[i])) { Log.Error($"Incomplete input data"); DataController._projectTable.Rows[i]["result"] = ResultCodes.IncompleteInputData; continue; } if (project.id != null) { // the dynamic exclusion for project name during serialization BimProject originalProject = DataController.AllProjects.First(p => p.id.Equals(project.id)); if (originalProject.name != project.name) { project.include_name_to_request_body = true; } else if (originalProject.name == project.name) { project.include_name_to_request_body = false; } DataController.UpdateProject(project, i); } else if (project.id == null) { Log.Error($"Project ID is not given. Cannot update."); } } CsvExporter.WriteResults(DataController._projectTable, _options, _options.FilePath); }
public void CopyFoldersProcess(string orgProjName, string newProjName, string adminEmail, List <string> roles) { if (orgProjName == "" || orgProjName == null) { Log.Error($"Project name to copy folders is not provided"); return; } // create project using existing project data BimProject orgProj = DataController.AllProjects.Find(x => x.name == orgProjName); BimProject newProj = DataController.GetProjectWithServiceById(orgProj.id); if (newProj.service_types.Contains("insight")) { newProj.service_types = newProj.service_types.Replace("insight,", ""); } newProj.name = newProjName; //newProj.updateName = true; CopyFoldersProcess(orgProj, newProj, adminEmail, roles); }
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; } }