public Result Execute(ExternalCommandData commandData, ref string message, Autodesk.Revit.DB.ElementSet elements) { try { m_app = commandData.Application; m_doc = m_app.ActiveUIDocument.Document; BCFUtil bcfUtil = new BCFUtil(m_app); bcfUtil.CleanLocalFolder(); MainWindow mainWindow = new MainWindow(m_app); if (true == mainWindow.ShowDialog()) { } } catch (Exception ex) { MessageBox.Show("Failed to initialize the Color Scheme Editor.\n" + ex.Message, "Color Scheme Editor", MessageBoxButton.OK, MessageBoxImage.Warning); } return(Result.Succeeded); }
private void buttonImport_Click(object sender, RoutedEventArgs e) { UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue); UpdateProgressDelegate updateProgressDelegate = new UpdateProgressDelegate(progressBar.SetValue); try { double progressValue = 0; progressBar.Maximum = 3; progressBar.Value = progressValue; progressBar.Visibility = Visibility.Visible; bcfPath = textBoxBCF.Text; sharedLink = textBoxFolder.Text; string folderId = ""; if (sharedLink.Contains("id=")) { folderId = FileManager.GetFolderId(sharedLink); } if (!string.IsNullOrEmpty(bcfProjectId)) { if (folderId != bcfProjectId) { bcfProjectId = folderId; googleFolders = FileManager.FindGoogleFolders(bcfProjectId); } } else { bcfProjectId = folderId; googleFolders = FileManager.FindGoogleFolders(bcfProjectId); } if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } File colorSheet = null; File uploadedBCF = null; File markupSheet = null; File viewpointSheet = null; List <File> uploadedImages = null; if (!string.IsNullOrEmpty(bcfPath) && null != googleFolders) { if (null != googleFolders) { progressValue += 1; Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Searching default folders..." }); Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue }); colorSheet = googleFolders.ColorSheet; bcfColorSchemeId = colorSheet.Id; string bcfName = System.IO.Path.GetFileNameWithoutExtension(bcfPath); if (FileManager.CheckExistingFiles(bcfName, googleFolders)) { string uploadId = Guid.NewGuid().ToString(); if (null != googleFolders.ArchiveBCFFolder) { if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } progressValue += 1; Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Uploading bcfzip to an archive folder..." }); Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue }); string parentId = googleFolders.ArchiveBCFFolder.Id; uploadedBCF = FileManager.UploadBCF(bcfPath, parentId, uploadId); } if (null != googleFolders.ActiveBCFFolder && null != googleFolders.ArchiveImgFolder) { if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } BCFUtil bcfUtil = new BCFUtil(); bcfzip = bcfUtil.ReadBCF(bcfPath); progressValue += 1; Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Creating Google spreadsheet..." }); Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue }); if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } string parentId = googleFolders.ActiveBCFFolder.Id; System.IO.MemoryStream markupStream = BCFParser.CreateMarkupStream(bcfzip); if (null != markupStream) { string title = bcfName + "_Markup.csv"; markupSheet = FileManager.UploadSpreadsheet(markupStream, title, parentId, uploadId); } System.IO.MemoryStream viewpointStream = BCFParser.CreateViewpointStream(bcfzip); if (null != viewpointStream) { string title = bcfName + "_Viewpoint.csv"; viewpointSheet = FileManager.UploadSpreadsheet(viewpointStream, title, parentId, uploadId); } if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } if (null != bcfzip) { Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Uploading BCF images..." }); Dispatcher.Invoke(updateProgressDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { ProgressBar.ValueProperty, progressValue }); parentId = googleFolders.ActiveImgFolder.Id; uploadedImages = FileManager.UploadBCFImages(bcfzip, parentId, uploadId, progressBar); } if (AbortFlag.GetAbortFlag()) { this.DialogResult = false; return; } if (null != uploadedBCF && null != markupSheet && null != viewpointSheet && null != uploadedImages) { Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Completed." }); progressBar.Visibility = Visibility.Hidden; bcfFileInfo = new LinkedBcfFileInfo(bcfName, markupSheet.Id, viewpointSheet.Id, sharedLink, googleFolders.RootTitle, bcfProjectId); this.DialogResult = true; } } } } else { MessageBox.Show("Folder Id cannot be identified.\n Please enter a valid shared link.\n", "Invalid Shared Link", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Please enter a correct form of the file path of bcf or the address of shared link.\n", "Invalid Path", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to import BCF.\n" + ex.Message, "Import BCF", MessageBoxButton.OK, MessageBoxImage.Warning); Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Ready." }); } progressBar.Visibility = Visibility.Hidden; }