/// <summary> /// exposes a saveFileDialog window to the user to store the current configuration /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Export_OnClick(object sender, RoutedEventArgs e) { var browser = new SaveFileDialog { FileName = "BIM360_Custom_Template.csv", RestoreDirectory = true, Title = "Saving configuration file...", Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*" }; browser.ShowDialog(); // specify path var path = Path.GetFullPath(browser.FileName); //export the Projects try { AccProjectConfig.ExportBim360Projects(path); } catch (Exception ex) { statusbar.Text = ex.Message; return; } statusbar.Text = "Export successful"; }
/// <summary> /// provides a user dialog to load a csv file /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Import_OnClick(object sender, RoutedEventArgs e) { var browser = new OpenFileDialog { Multiselect = false, Filter = "csv files (*.csv)|*.csv|All files (*.*)|*.*" }; // show browser browser.ShowDialog(); var fileName = browser.FileName; //Load CSV into Mainwindow if (AccProjectConfig.LoadBim360Projects(fileName)) { statusbar.Text = "Import successful!"; using (FileStream fs = File.OpenWrite(path_last)) { using (var sr = new StreamWriter(fs)) { //Delete the content of the file sr.Write(string.Empty); sr.WriteLine(fileName); } } } else { statusbar.Text = "Import failed! Unknown CSV Config or File not found!"; } }
private void Import_OnClick(object sender, RoutedEventArgs e) { //Folderbrowser var dialog = new CommonOpenFileDialog(); dialog.IsFolderPicker = false; dialog.Multiselect = false; //if use canceled the selection if (Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult.Cancel == dialog.ShowDialog()) { statusbar.Text = "canceled"; return; } //Load CSV into Mainwindow if (AccProjectConfig.LoadBim360Projects(dialog.FileName)) { statusbar.Text = "Import successful!"; using (FileStream fs = File.OpenWrite(path_last)) { using (var sr = new StreamWriter(fs)) { //Delete the content of the file sr.Write(string.Empty); sr.WriteLine(dialog.FileName); } } } else { statusbar.Text = "Import failed! Unknown CSV Config or File not found!"; } }
private void Export_OnClick(object sender, RoutedEventArgs e) { //maybe change string filename = "\\BIM360_Custom_Template.csv"; //window for user to enter data var dialog = new InputDialog("Please enter the path for exporting the CSV:", Environment.GetFolderPath(Environment.SpecialFolder.Desktop)); dialog.ResizeMode = ResizeMode.NoResize; dialog.ShowDialog(); if (dialog.DialogResult != true) { return; } var exportpath = dialog.Answer; //move to conifg if (File.Exists(exportpath + filename)) { statusbar.Text = "Export Failed! File already exists!"; return; } if (!Directory.Exists((exportpath))) { try { Directory.CreateDirectory(exportpath); } catch (Exception ex) { statusbar.Text = ex.Message; return; } } //Hardcoded Name in here maybe user should be able to change //export the Projects try { AccProjectConfig.ExportBim360Projects(exportpath + filename); } catch (Exception ex) { statusbar.Text = ex.Message; return; } statusbar.Text = "Export successful"; dialog.Close(); }
//UserManagement private void MainWindow_OnInitialized(object?sender, EventArgs e) { string csvpath = null; //create history if (!File.Exists(path_last)) { //Create Directory and File for the Config Directory.CreateDirectory(path_last.Remove(path_last.LastIndexOf("\\"))); var tmp = File.Create(path_last); tmp.Close(); } else { using (FileStream fs = File.OpenRead(path_last)) { using (var sr = new StreamReader(fs)) { //Delete the content of the file csvpath = sr.ReadLine(); } } try { AccProjectConfig.LoadBim360Projects(csvpath); } catch (Exception) { } } var ConfigFilePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Bim360Interface\Config\config.txt";; //Get Last Config from Login Data if (File.Exists(ConfigFilePath)) { using (FileStream fs = File.OpenRead(ConfigFilePath)) { using (StreamReader reader = new StreamReader(fs)) { ClientId = reader.ReadLine(); ClientSecret = reader.ReadLine(); BimId = reader.ReadLine(); AdminMail = reader.ReadLine(); } } } }
/// <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(); }
/// <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(); } }