public bool CanAttachTo(IViewContent content) { if (Path.GetExtension(content.PrimaryFileName).Equals(".xaml", StringComparison.OrdinalIgnoreCase)) { IEditable editable = content.GetService <IEditable>(); if (editable != null) { try { XmlTextReader r = new XmlTextReader(editable.CreateSnapshot().CreateReader()); r.XmlResolver = null; r.WhitespaceHandling = WhitespaceHandling.None; while (r.NodeType != XmlNodeType.Element && r.Read()) { ; } if (r.LocalName == "ResourceDictionary" || r.LocalName == "Application" || r.LocalName == "Activity") { return(false); } } catch (XmlException) { return(true); } return(true); } } return(false); }
static void timer_Tick(object sender, EventArgs e) { if (lastParseRun != null) { // don't start another parse run if the last one is still running if (!lastParseRun.IsCompleted) { return; } lastParseRun = null; } IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; if (viewContent == null) { return; } FileName fileName = viewContent.PrimaryFileName; if (fileName == null) { return; } if (GetParser(fileName) == null) { return; } ITextBuffer snapshot; IEditable editable = viewContent as IEditable; if (editable != null) { snapshot = editable.CreateSnapshot(); } else { snapshot = GetParseableFileContent(viewContent.PrimaryFileName); } lastParseRun = BeginParse(fileName, snapshot).ContinueWith( delegate(Task <ParseInformation> backgroundTask) { ParseInformation parseInfo = backgroundTask.Result; RaiseParserUpdateStepFinished(new ParserUpdateStepEventArgs(fileName, snapshot, parseInfo)); }); }
/// <summary> /// Begins parsing the specified view content. /// This method can only be called from the main thread. /// </summary> /// <remarks> /// EnqueueForParsing has been renamed to BeginParse and now provides a future (Task<ParseInformation>) /// to allow waiting for the result. However, to avoid deadlocks, this should not be done by any /// thread the parser might be waiting for (especially the main thread). /// /// Unlike BeginParse().Wait(), ParseFile() is safe to call from the main thread. /// </remarks> public static Task <ParseInformation> BeginParseViewContent(IViewContent viewContent) { if (viewContent == null) { throw new ArgumentNullException("viewContent"); } WorkbenchSingleton.AssertMainThread(); if (string.IsNullOrEmpty(viewContent.PrimaryFileName)) { return(NullTask()); } IEditable editable = viewContent as IEditable; if (editable != null) { return(BeginParse(viewContent.PrimaryFileName, editable.CreateSnapshot())); } else { return(BeginParse(viewContent.PrimaryFileName)); } }
void startEvent(object sender, System.EventArgs e) { items = new List <Report>(); total = null; switch (((ComboBox)ControlDictionary["locationComboBox"]).SelectedIndex) { case 0: { // current file IViewContent viewContent = WorkbenchSingleton.Workbench.ActiveViewContent; if (viewContent != null) { IEditable editable = viewContent as IEditable; if (editable == null) { MessageService.ShowWarning("${res:Dialog.WordCountDialog.IsNotTextFile}"); } else { Report r = GetReport(viewContent, editable.CreateSnapshot().CreateReader()); if (r != null) { items.Add(r); } } } break; } case 1: { // all open files if (WorkbenchSingleton.Workbench.ViewContentCollection.Count > 0) { total = new Report(StringParser.Parse("${res:Dialog.WordCountDialog.TotalText}"), 0, 0, 0); foreach (IViewContent content in WorkbenchSingleton.Workbench.ViewContentCollection) { IEditable editable = content as IEditable; if (editable != null) { Report r = GetReport(content, editable.CreateSnapshot().CreateReader()); if (r != null) { total += r; items.Add(r); } } } } break; } case 2: { // whole project if (ProjectService.OpenSolution == null) { MessageService.ShowError("${res:Dialog.WordCountDialog.MustBeInProtectedModeWarning}"); break; } total = new Report(StringParser.Parse("${res:Dialog.WordCountDialog.TotalText}"), 0, 0, 0); CountSolution(ProjectService.OpenSolution, ref total); // ((ListView)ControlDictionary["resultListView"]).Items.Add(new ListViewItem("")); // ((ListView)ControlDictionary["resultListView"]).Items.Add(all.ToListItem()); break; } } UpdateList(0); }