/// <summary> /// Waits for the producer to produce an object. Returns true if the producer produces an object, or false if the AbortFlag was set before an object was produced. /// If aborted, then the object, when it loads, will be discarded. This way, the AsyncLoadingObject instance can be reused without going out of sync. /// </summary> /// <param name="flag">An AbortFlag to observe.</param> /// <param name="obj">The produced object, valid only if the return value from this method is true.</param> /// <param name="timeout">The amount of time in milliseconds to wait between checking the abort flag. Very low values may increase CPU usage due to overhead of the internal EventWaitHandle.</param> /// <returns></returns> public bool Consume(AbortFlag flag, out T obj, int timeout = 500) { bool gotObject = false; while (!flag.abort && (gotObject = ewh.WaitOne(timeout)) == false) { ; } if (gotObject) { lock (syncLock) { obj = produced; produced = default(T); } return(true); } else { //We gave up on waiting for it, but API expectations guarantee that it will arrive eventually. // Incrementing canceledConsumes causes the next Produced object to be discarded without signaling the EventWaitHandle. lock (syncLock) { canceledConsumes++; } obj = default(T); return(false); } }
private void buttonCancel_Click(object sender, RoutedEventArgs e) { MessageBoxResult result = System.Windows.MessageBox.Show("Would you like to stop importing the BCF file?", "Cancellation - Import BCF", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { AbortFlag.SetAbortFlag(true); } }
public ProgressWindow(string labelText) { InitializeComponent(); statusText = labelText; labelStatus.Content = statusText; this.Title = "smartBCF v." + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); updateProgressDelegate = new UpdateProgressDelegate(progressBarBCF.SetValue); AbortFlag.SetAbortFlag(false); }
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); }
public ImportBCFWindow(FolderHolders folders) { googleFolders = folders; if (null != googleFolders) { bcfProjectId = googleFolders.RootId; } InitializeComponent(); if (!string.IsNullOrEmpty(bcfProjectId)) { sharedLink = FileManager.GetSharedLinkAddress(bcfProjectId); textBoxFolder.Text = sharedLink; } AbortFlag.SetAbortFlag(false); }
/// <summary> /// Returns a buffer containing serialized ImageFragments. /// May return null in case of error. /// This method blocks until a frame is received from the Streamer process. /// </summary> /// <returns></returns> public FragmentedImage GetRawDesktopCapture(ImgFlags imgFlags, byte jpegQuality, AbortFlag abortFlag) { try { lock (lock_GetRawDesktopCapture) { lock (syncObject) { if (!Maintain()) { return(new FragmentedImage()); } sm.WriteByte((byte)Command.GetScreenCapture); sm.WriteByte((byte)imgFlags); sm.WriteByte(jpegQuality); } FragmentedImage img; if (newFrame.Consume(abortFlag, out img)) { return(img); } else { return(null); } } } catch (ThreadAbortException) { throw; } catch (StreamDisconnectedException ex) { Logger.Info(ex.Message); } catch (Exception ex) { Logger.Debug(ex); } return(new FragmentedImage()); }
private void buttonCancel_Click(object sender, RoutedEventArgs e) { AbortFlag.SetAbortFlag(true); }
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; }