private Dictionary <string /*spreadsheetId*/, Dictionary <string /*issueId*/, IssueEntry> > GetBCFDictionary(Document doc) { Dictionary <string, Dictionary <string, IssueEntry> > dictionary = new Dictionary <string, Dictionary <string, IssueEntry> >(); try { AbortFlag.SetAbortFlag(false); progressWindow = new ProgressWindow("Loading BCF issues and images..."); progressWindow.Show(); List <string> markupIds = bcfFileDictionary.Keys.ToList(); foreach (string markupId in markupIds) { LinkedBcfFileInfo bcfFileInfo = bcfFileDictionary[markupId]; if (null != FileManager.FindFileById(bcfFileInfo.MarkupFileId) && null != FileManager.FindFileById(bcfFileInfo.ViewpointFileId)) { Dictionary <string, IssueEntry> issueDictionary = GetBCFIssueInfo(doc, bcfFileInfo); if (AbortFlag.GetAbortFlag()) { return(new Dictionary <string, Dictionary <string, IssueEntry> >()); } if (!dictionary.ContainsKey(markupId) && issueDictionary.Count > 0) { dictionary.Add(markupId, issueDictionary); } } else { bcfFileDictionary.Remove(markupId); } } if (!string.IsNullOrEmpty(categorySheetId)) { System.IO.MemoryStream stream = BCFParser.CreateCategoryStream(categoryNames); if (null != stream) { Google.Apis.Drive.v2.Data.File file = FileManager.UpdateSpreadsheet(stream, categorySheetId, bcfProjectId); } } if (progressWindow.IsActive) { progressWindow.Close(); } } catch (Exception ex) { MessageBox.Show("Failed to get BCF dictionary.\n" + ex.Message, "Get BCF Dictionary", MessageBoxButton.OK, MessageBoxImage.Warning); } return(dictionary); }
private void buttonAdd_Click(object sender, RoutedEventArgs e) { try { bcfProjectId = textBoxId.Text; sharedLink = FileManager.GetSharedLinkAddress(bcfProjectId); if (!string.IsNullOrEmpty(bcfProjectId)) { if (null == googleFolders) { googleFolders = FileManager.FindGoogleFolders(bcfProjectId); } if (null != googleFolders) { //add online BCF OnlineBCFWindow onlineBCFWindow = new OnlineBCFWindow(googleFolders); if (onlineBCFWindow.ShowDialog() == true) { List <OnlineBCFInfo> onlineBCFs = onlineBCFWindow.OnlineBCFs; foreach (OnlineBCFInfo info in onlineBCFs) { if (info.IsSelected) { OnlineBCFInfo uploadedBCF = FileManager.UploadOnlineBCF(googleFolders, info); string bcfName = uploadedBCF.SheetTitle.Replace("_Markup.csv", ""); LinkedBcfFileInfo linkedBCF = new LinkedBcfFileInfo(bcfName, uploadedBCF.MarkupSheetId, uploadedBCF.ViewpointSheetId, sharedLink, googleFolders.RootTitle, bcfProjectId); dataGridBCFs.ItemsSource = null; linkedBCFs.Add(linkedBCF); linkedBCFs = linkedBCFs.OrderBy(o => o.BCFName).ToList(); dataGridBCFs.ItemsSource = linkedBCFs; } } onlineBCFWindow.Close(); } } } else { MessageBox.Show("Please enter a valid BCF project Id.", "Invalid BCF Project Id", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to add an online BCF./n" + ex.Message, "Add Online BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonImport_Click(object sender, RoutedEventArgs e) { try { if (!string.IsNullOrEmpty(textBoxId.Text)) { if (textBoxId.Text != bcfProjectId) { bcfProjectId = textBoxId.Text; sharedLink = FileManager.GetSharedLinkAddress(bcfProjectId); googleFolders = FileManager.FindGoogleFolders(textBoxId.Text); } } ImportBCFWindow importWindow = new ImportBCFWindow(googleFolders); if (importWindow.ShowDialog() == true) { if (importWindow.RememberProjectId) { bcfProjectId = importWindow.BCFProjectId; bcfColorSchemeId = importWindow.BCFColorSchemeId; googleFolders = importWindow.GoogleFolders; if (!string.IsNullOrEmpty(bcfProjectId)) { textBoxId.Text = bcfProjectId; } } LinkedBcfFileInfo fileInfo = importWindow.BCFFileInfo; dataGridBCFs.ItemsSource = null; linkedBCFs.Add(fileInfo); linkedBCFs = linkedBCFs.OrderBy(o => o.BCFName).ToList(); dataGridBCFs.ItemsSource = linkedBCFs; importWindow.Close(); } else { importWindow.Close(); } } catch (Exception ex) { MessageBox.Show("Failed to import BCF.\n" + ex.Message, "Import BCF", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void comboBoxBCF_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (null != comboBoxBCF.SelectedItem) { LinkedBcfFileInfo fileInfo = (LinkedBcfFileInfo)comboBoxBCF.SelectedItem; selectedBCF = fileInfo; if (bcfDictionary.ContainsKey(fileInfo.MarkupFileId)) { Dictionary <string, IssueEntry> dictionary = bcfDictionary[fileInfo.MarkupFileId]; List <IssueEntry> issueList = dictionary.Values.OrderBy(o => o.IssueTopic).ToList(); comboBoxIssue.ItemsSource = null; comboBoxIssue.ItemsSource = issueList; comboBoxIssue.DisplayMemberPath = "IssueTopic"; comboBoxIssue.SelectedIndex = 0; } } } catch (Exception ex) { MessageBox.Show("Failed to trigger the event of selection changed for BCF Name.\n" + ex.Message, "comboBoxBCF SelectionChanged", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public void Execute(UIApplication app) { try { m_doc = app.ActiveUIDocument.Document; switch (Request.Take()) { case RequestId.None: return; case RequestId.ReadLinkedFileInfo: break; case RequestId.UpdateLinkedFileInfo: bool updated = DataStorageUtil.UpdateLinkedBCFFileInfo(m_doc, bcfFileDictionary); Dictionary <string, Dictionary <string, IssueEntry> > dictionary = new Dictionary <string, Dictionary <string, IssueEntry> >(); int numCat = categoryNames.Count; AbortFlag.SetAbortFlag(false); progressWindow = new ProgressWindow("Loading BCF issues and images..."); progressWindow.Show(); foreach (string markupId in bcfFileDictionary.Keys) { LinkedBcfFileInfo bcfInfo = bcfFileDictionary[markupId]; if (bcfDictionary.ContainsKey(markupId)) { dictionary.Add(markupId, bcfDictionary[markupId]); } else { Dictionary <string, IssueEntry> issueDictionary = GetBCFIssueInfo(m_doc, bcfInfo); if (issueDictionary.Count > 0) { dictionary.Add(markupId, issueDictionary); } } } if (progressWindow.IsActive) { progressWindow.Close(); } bcfDictionary = dictionary; if (numCat != categoryNames.Count) { System.IO.MemoryStream stream = BCFParser.CreateCategoryStream(categoryNames); if (null != stream) { Google.Apis.Drive.v2.Data.File file = FileManager.UpdateSpreadsheet(stream, categorySheetId, bcfProjectId); } List <BuiltInCategory> bltCategories = catDictionary.Values.ToList(); bool parameterCreated = ParameterUtil.CreateBCFParameters(m_app, bltCategories); foreach (string catName in categoryNames) { var catFound = from category in categoryInfoList where category.CategoryName == catName select category; if (catFound.Count() == 0) { CategoryInfo catInfo = new CategoryInfo(catName, true); categoryInfoList.Add(catInfo); } } } if (null != walkerWindow) { walkerWindow.BCFFileDictionary = bcfFileDictionary; walkerWindow.BCFDictionary = bcfDictionary; walkerWindow.CategoryInfoList = categoryInfoList; walkerWindow.CurrentIndex = 0; walkerWindow.DisplayLinkedBCF(); } bool updatedId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); schemeInfo = FileManager.ReadColorSchemes(bcfColorSchemeId, categorySheetId, false); if (null != walkerWindow) { walkerWindow.SchemeInfo = schemeInfo; walkerWindow.DisplayColorscheme(schemeInfo); } break; case RequestId.ReadProjectId: bcfProjectId = ParameterUtil.GetBCFProjectId(app); break; case RequestId.UpdateProjectId: bool updatedProjectId = ParameterUtil.SetBCFProjectId(m_doc, bcfProjectId); break; case RequestId.ReadBCFParameterInfo: break; case RequestId.UpdateBCFParameterInfo: bool updatedParameters = ParameterUtil.UpdateBCFParameters(m_doc, currentElement, selectedIssue, selectedComment); break; case RequestId.UpdateAction: bool actionUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Action, currentElement.Action); break; case RequestId.UpdateResponsibility: bool responsibilityUpdated = ParameterUtil.UpdateBCFParameter(m_doc, currentElement, BCFParameters.BCF_Responsibility, currentElement.ResponsibleParty); break; case RequestId.CreateIssue: break; case RequestId.UpdateViews: IsolateElement(isIsolateOn, m_doc); CreateSectionBox(isSectionBoxOn, m_doc); HighlightElement(isHighlightOn, m_doc); break; case RequestId.UpdateParameterByComment: UpdateParameters(m_doc); break; } } catch (Exception ex) { MessageBox.Show("Failed to execute an external event.\n" + ex.Message, "Execute Event", MessageBoxButton.OK, MessageBoxImage.Warning); } return; }
private Dictionary <string, IssueEntry> GetBCFIssueInfo(Document doc, LinkedBcfFileInfo bcfFileInfo) { Dictionary <string, IssueEntry> issueDictionary = new Dictionary <string, IssueEntry>(); try { issueDictionary = FileManager.ReadIssues(bcfFileInfo); List <string> issueIds = issueDictionary.Keys.ToList(); progressWindow.SetMaximum(issueIds.Count); double progressValue = 0; foreach (string issueId in issueIds) { if (AbortFlag.GetAbortFlag()) { progressWindow.Close(); return(new Dictionary <string, IssueEntry>()); } progressValue++; progressWindow.SetProgressValue(progressValue); IssueEntry issueEntry = issueDictionary[issueId]; List <int> elementIds = issueEntry.ElementDictionary.Keys.ToList(); foreach (int elementId in elementIds) { ElementProperties property = issueEntry.ElementDictionary[elementId]; Element element = m_doc.GetElement(new ElementId(elementId)); if (null != element) { if (null != element.Category) { if (!categoryNames.Contains(element.Category.Name)) { categoryNames.Add(element.Category.Name); } if (element.Category.AllowsBoundParameters) { int categoryId = element.Category.Id.IntegerValue; if (!catDictionary.ContainsKey(categoryId)) { BuiltInCategory bltCategory = (BuiltInCategory)categoryId; if (bltCategory != BuiltInCategory.INVALID) { catDictionary.Add(categoryId, bltCategory); } } } } ElementProperties ep = new ElementProperties(element); ep.IssueId = property.IssueId; ep.Action = property.Action; ep.ResponsibleParty = property.ResponsibleParty; ep.CellEntries = property.CellEntries; issueDictionary[issueId].ElementDictionary.Remove(elementId); issueDictionary[issueId].ElementDictionary.Add(elementId, ep); } } issueDictionary[issueId].NumElements = issueDictionary[issueId].ElementDictionary.Count; if (null == issueDictionary[issueId].Snapshot) { if (bcfFileInfo.SharedLinkId == bcfProjectId && null != googleFolders) { issueDictionary[issueId].Snapshot = FileManager.DownloadImage(issueId, googleFolders.ActiveImgFolder.Id); } else if (bcfFileInfo.SharedLinkId == bcfProjectId) { googleFolders = FileManager.FindGoogleFolders(bcfProjectId); if (null != googleFolders) { issueDictionary[issueId].Snapshot = FileManager.DownloadImage(issueId, googleFolders.ActiveImgFolder.Id); } } else { FolderHolders tempFolders = FileManager.FindGoogleFolders(bcfFileInfo.SharedLinkId); if (null != tempFolders) { issueDictionary[issueId].Snapshot = FileManager.DownloadImage(issueId, tempFolders.ActiveImgFolder.Id); } } } } if (bcfDictionary.ContainsKey(bcfFileInfo.MarkupFileId)) { bcfDictionary.Remove(bcfFileInfo.MarkupFileId); } bcfDictionary.Add(bcfFileInfo.MarkupFileId, issueDictionary); } catch (Exception ex) { MessageBox.Show("Failed to add issue items into BCF dictionary.\n" + ex.Message, "Add BCF to Dictionary", MessageBoxButton.OK, MessageBoxImage.Warning); } return(issueDictionary); }
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; }