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