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 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; }