public bool RunViewAnalysis(ProgressBar progressBar, TextBlock statusLable) { bool result = true; using (TransactionGroup tg = new TransactionGroup(m_doc)) { tg.Start("Run View Analysis"); try { UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue); List <int> keys = roomDictionary.Keys.ToList(); int finishedRoom = 0; foreach (int roomId in keys) { if (AbortFlag.GetAbortFlag()) { return(false); } using (Transaction trans = new Transaction(m_doc)) { trans.Start("Find Visibility"); try { RoomData rData = roomDictionary[roomId]; string roomInfo = rData.RoomObj.Name + " (" + finishedRoom + " of " + keys.Count + ")"; Dispatcher.CurrentDispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, roomInfo }); progressBar.Visibility = System.Windows.Visibility.Visible; RoomData updatedData = FindVisibility(rData, progressBar); roomDictionary.Remove(roomId); roomDictionary.Add(roomId, updatedData); finishedRoom++; trans.Commit(); } catch (Exception ex) { trans.RollBack(); result = false; string message = ex.Message; } } } tg.Assimilate(); } catch (Exception ex) { result = false; MessageBox.Show("Failed to run view analysis.\n" + ex.Message, "Run View Analysis", MessageBoxButton.OK, MessageBoxImage.Warning); tg.RollBack(); } } return(result); }
private void buttonImport_Click(object sender, RoutedEventArgs e) { ProjectWindow projectWindow = new ProjectWindow(); if (projectWindow.ShowDialog() == true) { string labelText = "Importing Color Schemes..."; UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue); Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, labelText }); string projectId = projectWindow.ProjectId; File colorSheet = FileManager.FindSubItemByFolderId("Color Schemes", projectId); ColorSchemeInfo colorInfo = BCFParser.ReadColorSchemes(colorSheet.Id, true); List <ColorDefinition> actionColors = new List <ColorDefinition>(); List <ColorDefinition> responsibilityColors = new List <ColorDefinition>(); foreach (ColorScheme colorScheme in colorInfo.ColorSchemes) { switch (colorScheme.SchemeName) { case "BCF Action": actionColors = colorScheme.ColorDefinitions; break; case "BCF Responsibility": responsibilityColors = colorScheme.ColorDefinitions; break; } } actionDefinitions = actionColors.OrderBy(o => o.ParameterValue).ToList(); responsibleDefinitions = responsibilityColors.OrderBy(o => o.ParameterValue).ToList(); dataGridAction.ItemsSource = null; dataGridAction.ItemsSource = actionDefinitions; dataGridResponsibility.ItemsSource = null; dataGridResponsibility.ItemsSource = responsibleDefinitions; bool writeColor = BCFParser.WriteColorSheet(colorInfo, colorSheetId); labelText = "Ready"; Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, labelText }); } }
private void buttonManage_Click(object sender, RoutedEventArgs e) { try { UpdateLableDelegate updateLabelDelegate = new UpdateLableDelegate(statusLable.SetValue); UpdateProgressDelegate updateProgressDelegate = new UpdateProgressDelegate(progressBar.SetValue); BCFWindow bcfWindow = new BCFWindow(bcfFileDictionary, googleFolders); if (bcfWindow.ShowDialog() == true) { Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Loading BCF Information..." }); bcfFileDictionary = new Dictionary <string, LinkedBcfFileInfo>(); bcfFileDictionary = bcfWindow.BCFFileDictionary; bcfProjectId = bcfWindow.BCFProjectId; googleFolders = bcfWindow.GoogleFolders; if (!string.IsNullOrEmpty(bcfProjectId) && null != googleFolders) { bcfColorSchemeId = googleFolders.ColorSheet.Id; categorySheetId = googleFolders.CategorySheet.Id; bcfWindow.Close(); m_handler.BCFFileDictionary = bcfFileDictionary; m_handler.BCFProjectId = bcfProjectId; m_handler.BCFColorSchemeId = bcfColorSchemeId; m_handler.CategorySheetId = categorySheetId; m_handler.GoogleFolders = googleFolders; m_handler.Request.Make(RequestId.UpdateLinkedFileInfo); m_event.Raise(); SetFocus(); } Dispatcher.Invoke(updateLabelDelegate, System.Windows.Threading.DispatcherPriority.Background, new object[] { TextBlock.TextProperty, "Ready" }); } } catch (Exception ex) { MessageBox.Show("Failed to open BCF window.\n" + ex.Message, "Open Manage BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public ProgressWindow() { InitializeComponent(); updateLabelDelegate = new UpdateLableDelegate(statusLabel.SetValue); updateProgressDelegate = new UpdateProgressDelegate(statusProgressBar.SetValue); }
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; }