private void buttonDeleteRes_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridResponsibility.SelectedItem) { ColorDefinition colorDefinition = (ColorDefinition)dataGridResponsibility.SelectedItem; string oldName = colorDefinition.ParameterValue; dataGridResponsibility.ItemsSource = null; for (int i = 0; i < responsibleDefinitions.Count; i++) { if (responsibleDefinitions[i].ParameterValue == oldName) { responsibleDefinitions.RemoveAt(i); } } dataGridResponsibility.ItemsSource = responsibleDefinitions; bool updated = BCFParser.UpdateColorSheet(responsibleScheme, colorDefinition, null, ModifyItem.Delete, colorSheetId); } } catch (Exception ex) { MessageBox.Show("Failed to delete Responsibility item.\n" + ex.Message, "Delete Responsibility Item", MessageBoxButton.OK, MessageBoxImage.Warning); } }
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 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 buttonAddRes_Click(object sender, RoutedEventArgs e) { try { ColorDefinition colorDefinition = new ColorDefinition(); byte[] colorBytes = new byte[3]; colorBytes[0] = (byte)random.Next(256); colorBytes[1] = (byte)random.Next(256); colorBytes[2] = (byte)random.Next(256); colorDefinition.Color = colorBytes; System.Windows.Media.Color windowColor = System.Windows.Media.Color.FromRgb(colorDefinition.Color[0], colorDefinition.Color[1], colorDefinition.Color[2]); colorDefinition.BackgroundColor = new SolidColorBrush(windowColor); var names = from name in responsibleDefinitions select name.ParameterValue; StatusItemWindow itemWindow = new StatusItemWindow(colorDefinition, ColorSource.Responsibility, NewOrEdit.New); if (names.Count() > 0) { itemWindow.DefinitionNames = names.ToList(); } if (itemWindow.ShowDialog() == true) { ColorDefinition newDefinition = itemWindow.SelColorDefinition; itemWindow.Close(); dataGridResponsibility.ItemsSource = null; responsibleDefinitions.Add(newDefinition); responsibleDefinitions = responsibleDefinitions.OrderBy(o => o.ParameterValue).ToList(); dataGridResponsibility.ItemsSource = responsibleDefinitions; bool updated = BCFParser.UpdateColorSheet(responsibleScheme, null, newDefinition, ModifyItem.Add, colorSheetId); } } catch (Exception ex) { MessageBox.Show("Failed to add Responsibility item.\n" + ex.Message, "Add Responsibility Item", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void comboBoxResponsible_SelectionChanged(object sender, SelectionChangedEventArgs e) { try { if (null != comboBoxResponsible.SelectedItem && freezeHandler == false) { ColorDefinition selectedResponsible = (ColorDefinition)comboBoxResponsible.SelectedItem; if (null != selectedBCF && null != selectedIssue && null != selElementProperties) { selElementProperties.ResponsibleParty = selectedResponsible.ParameterValue; if (bcfDictionary.ContainsKey(selectedBCF.MarkupFileId)) { if (bcfDictionary[selectedBCF.MarkupFileId].ContainsKey(selectedIssue.IssueId)) { if (bcfDictionary[selectedBCF.MarkupFileId][selectedIssue.IssueId].ElementDictionary.ContainsKey(selElementProperties.ElementId)) { bcfDictionary[selectedBCF.MarkupFileId][selectedIssue.IssueId].ElementDictionary.Remove(selElementProperties.ElementId); bcfDictionary[selectedBCF.MarkupFileId][selectedIssue.IssueId].ElementDictionary.Add(selElementProperties.ElementId, selElementProperties); } } } bool updatedSheet = BCFParser.UpdateElementProperties(selElementProperties, BCFParameters.BCF_Responsibility, selectedBCF.ViewpointFileId); m_handler.CurrentElement = selElementProperties; m_handler.Request.Make(RequestId.UpdateResponsibility); m_event.Raise(); SetFocus(); } } } catch (Exception ex) { MessageBox.Show("Failed to set responsibility itme.\n" + ex.Message, "Set Responsibility Items", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonResponsibleColor_Click(object sender, RoutedEventArgs e) { try { WinForm.ColorDialog colorDialog = new WinForm.ColorDialog(); if (WinForm.DialogResult.OK == colorDialog.ShowDialog()) { System.Drawing.Color color = colorDialog.Color; colorDialog.Dispose(); ColorDefinition selectedDefinition = (sender as Button).DataContext as ColorDefinition; ColorDefinition colorDefinition = new ColorDefinition(selectedDefinition); colorDefinition.Color[0] = color.R; colorDefinition.Color[1] = color.G; colorDefinition.Color[2] = color.B; System.Windows.Media.Color windowColor = System.Windows.Media.Color.FromRgb(colorDefinition.Color[0], colorDefinition.Color[1], colorDefinition.Color[2]); colorDefinition.BackgroundColor = new SolidColorBrush(windowColor); dataGridResponsibility.ItemsSource = null; for (int i = 0; i < responsibleDefinitions.Count; i++) { if (responsibleDefinitions[i].ParameterValue == colorDefinition.ParameterValue) { responsibleDefinitions[i] = colorDefinition; break; } } dataGridResponsibility.ItemsSource = responsibleDefinitions; bool updated = BCFParser.UpdateColorSheet(responsibleScheme, selectedDefinition, colorDefinition, ModifyItem.Edit, colorSheetId); } } catch (Exception ex) { MessageBox.Show("Failed to set color.\n" + ex.Message, "Set Color", MessageBoxButton.OK, MessageBoxImage.Warning); } }
private void buttonEditRes_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridResponsibility.SelectedItem) { ColorDefinition colorDefinition = (ColorDefinition)dataGridResponsibility.SelectedItem; ColorDefinition oldDefinition = new ColorDefinition(colorDefinition); string oldName = colorDefinition.ParameterValue; var names = from name in responsibleDefinitions select name.ParameterValue; StatusItemWindow itemWindow = new StatusItemWindow(colorDefinition, ColorSource.Responsibility, NewOrEdit.Edit); if (names.Count() > 0) { itemWindow.DefinitionNames = names.ToList(); } if (itemWindow.ShowDialog() == true) { ColorDefinition newDefinition = itemWindow.SelColorDefinition; itemWindow.Close(); dataGridResponsibility.ItemsSource = null; responsibleDefinitions = responsibleDefinitions.OrderBy(o => o.ParameterValue).ToList(); dataGridResponsibility.ItemsSource = responsibleDefinitions; bool updated = BCFParser.UpdateColorSheet(responsibleScheme, oldDefinition, newDefinition, ModifyItem.Edit, colorSheetId); } } } catch (Exception ex) { MessageBox.Show("Failed to edit Responsibility item.\n" + ex.Message, "Edit Responsibility Item", 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 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; }