public static string AddProject(BimProject project, string accountId = null, int rowIndex = -1) { BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options); project.include_name_to_request_body = true; // replace empty strings with null PropertyInfo[] properties = project.GetType().GetProperties(); foreach (PropertyInfo propInfo in properties) { if (typeof(string) == propInfo.PropertyType) { string s = propInfo.GetValue(project) as string; //as string; if (s != null && s.Equals("")) { propInfo.SetValue(project, null); } } } IRestResponse response = _projectsApi.PostProject(project, accountId); return(HandleCreateProjectResponse(response, accountId, rowIndex)); }
public static string AddProject(BimProject project, string accountId = null, int rowIndex = -1) { BimProjectsApi _projectsApi = new BimProjectsApi(GetToken, _options); project.include_name_to_request_body = true; // replace empty strings with null PropertyInfo[] properties = project.GetType().GetProperties(); foreach (PropertyInfo propInfo in properties) { if (typeof(string) == propInfo.PropertyType) { string s = propInfo.GetValue(project) as string; //as string; if (s != null && s.Equals("")) { propInfo.SetValue(project, null); } } } bool success = false; BimProject newProject = null; IRestResponse response = _projectsApi.PostProject(project, accountId); if (response.StatusCode == System.Net.HttpStatusCode.Created) { newProject = JsonConvert.DeserializeObject <BimProject>(response.Content); success = true; } // In certain case, the BIM 360 backend takes more than 10 seconds to handle the request, // this will result in 504 gateway timeout error, but the project should be already successfully // created, add this check to fix this issue. if (response.StatusCode == System.Net.HttpStatusCode.GatewayTimeout) { Thread.Sleep(3000); List <BimProject> projectList = GetProjects(@"-created_at"); newProject = projectList.FirstOrDefault(); success = newProject != null && newProject.name == project.name; } if (success) { if (_AllProjects == null) { _AllProjects = GetProjects(); } if (accountId == null) { _AllProjects.Add(newProject); } if (rowIndex > -1) { _projectTable.Rows[rowIndex]["id"] = newProject.id; _projectTable.Rows[rowIndex]["result"] = ResultCodes.ProjectCreated; } Log.Info($"- project {newProject.name} created with ID {newProject.id}!"); return(newProject.id); } else { ResponseContent content = null; 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}"); return("error"); } }