public async System.Threading.Tasks.Task HandleChangeAsync(IWpfTextView textView) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); try { var profiler = MiniProfiler.StartNew(nameof(HandleChangeAsync)); profiler.Storage = new NLogStorage(LogManager.GetLogger("profiler")); using (profiler.Step("HandleChangeCode")) { SnapshotPoint caretPosition = textView.Caret.Position.BufferPosition; Microsoft.CodeAnalysis.Document roslynDocument = caretPosition.Snapshot.GetOpenDocumentInCurrentContextWithChanges(); if (roslynDocument == null) { OutputWindowLogger.WriteLn($"Unable to get c# file to process. Name {caretPosition.Snapshot.ContentType.DisplayName}"); return; } await GotoAsyncPackage.Storage.AnalyzeAndUpdateSingleAsync(roslynDocument); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "CSharpFileContentOnChange.HandleChange"); OutputWindowLogger.WriteLn($"Exception occured during handling csharp file change: {ex.Message}"); } }
private MapProcessingResult HandleMaps(ConfigProcessingResult configProcessingResult) { var xmlFiles = DocumentHelper.GetXmlFiles(_projectItems); var configs = GotoAsyncPackage.Storage.SqlMapConfigProvider.GetAll(); if (_options.MapsOptions.IndexAllMaps) { return(HandleCorrectMapFiles(xmlFiles, configs)); } if (_options.MapsOptions.IndexOnlyMapsInConfig) { var fileNames = configs.SelectMany(e => e.Maps).Select(e => e.Value); var filteredXmlFiles = GetExistingInMaps(xmlFiles, fileNames); if (fileNames.Any(e => e.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0)) { //Fallback scenario, when path/filename is invaild than just index all maps in solution, //maps that are are not referenced in config, will be assigned to default config. OutputWindowLogger.WriteLn("Found invaild character for file. Parsing all maps found in solution."); return(HandleAllMapFiles(xmlFiles, configs)); } return(HandleCorrectMapFiles(filteredXmlFiles, configs)); } return(new MapProcessingResult()); }
private IEnumerable <SqlMapConfig> GetConfigs(IEnumerable <ProjectItem> projectItems) { var configs = GetConfigsFiles(projectItems); OutputWindowLogger.WriteLn($"Found config candidates: {string.Join(" ", configs.Select(e=>e.FilePath))}"); var parsedConfigs = configs.Select(config => _xmlIndexer.ParseSingleConfigFile(config)).Where(e => e.ParsedSuccessfully); OutputWindowLogger.WriteLn($"Parsed configs: {string.Join(" ", parsedConfigs.Select(e=>e.Name))}"); return(parsedConfigs); }
public void ItemRenamed(ProjectItem ProjectItem, string OldName) { try { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); GotoAsyncPackage.Storage.CodeQueries.RenameStatmentsForFile(OldName, ProjectItem.Name); GotoAsyncPackage.Storage.XmlQueries.RenameStatmentsForFile(OldName, ProjectItem.Name); } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "ProjectItemEventsEx.ItemRenamed"); OutputWindowLogger.WriteLn($"Exception occured during ProjectItemEventsEx.ItemRenamed: { ex.Message}"); } }
public void ValidateAllSpans() { try { foreach (var validator in _validators) { (validator as IBufferValidator).ValidateAllSpans(); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "XmlValidatorsAggregator.ValidateAllSpans"); OutputWindowLogger.WriteLn($"Exception occured during XmlValidatorsAggregator.ValidateAllSpans: { ex.Message}"); } }
public override void MenuItemCallback(object sender, EventArgs e) { try { _documentProcessor.TryResolveQueryValueAtCurrentSelectedLine(out ExpressionResult expressionResult, out string queryValue); _finalActionFactory .GetFinalRenameQueryActionsExecutor(StatusBar, _commandWindow, GotoAsyncPackage.EnvDTE, Package.Workspace) .Execute(queryValue, expressionResult); } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "QueryRenameActions.MenuItemCallback"); OutputWindowLogger.WriteLn($"Exception occured during QueryRenameActionsMenuCallback: {ex.Message}"); } }
public int OnAfterBackgroundSolutionLoadComplete() { Debug.WriteLine("OnAfterBackgroundSolutionLoadComplete()"); try { //Load Xml files from indexer _actions.OnSolutionLoadComplete(); } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "SolutionEventsHandler.OnAfterBackgroundSolutionLoadComplete"); OutputWindowLogger.WriteLn($"Exception occured during SolutionEventsHandler.OnAfterBackgroundSolutionLoadComplete: { ex.Message}"); } return(VSConstants.S_OK); }
public int OnQueryCloseSolution(object pUnkReserved, ref int pfCancel) { try { //Remove everything from indexer instance _actions.SolutionOnClose(); //Remove Errors TableDataSource.Instance.CleanAllErrors(); } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "SolutionEventsHandler.OnQueryCloseSolution"); OutputWindowLogger.WriteLn($"Exception occured during SolutionEventsHandler.OnQueryCloseSolution: { ex.Message}"); } return(1); }
public override void MenuItemCallback(object sender, EventArgs e) { try { var profiler = MiniProfiler.StartNew($"{nameof(GoToQueryActions2)}.{nameof(MenuItemCallback)}"); profiler.Storage = new NLogStorage(LogManager.GetLogger("profiler")); using (profiler.Step("Event start")) { _documentProcessor.TryResolveQueryValueAtCurrentSelectedLine(out ExpressionResult expressionResult, out string queryValue); _finalActionFactory .GetFinalGoToQueryActionsExecutor(StatusBar, _commandWindow, MapNamespaceHelper.IsQueryWithNamespace(queryValue)) .Execute(queryValue, expressionResult); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "GoToQuery.MenuItemCallback"); OutputWindowLogger.WriteLn($"Exception occured during GoToActionMenuCallback: {ex.Message}"); } }
public async Task <List <CSharpIndexerResult> > BuildIndexerAsync(List <Document> documents) { var results = new List <CSharpIndexerResult>(); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var document in documents) { if (!Regex.IsMatch(document.FilePath, @"(\\service|\\TemporaryGeneratedFile_.*|\\assemblyinfo|\\assemblyattributes|\.(g\.i|g|designer|generated|assemblyattributes))\.(cs|vb)$")) { results.Add(await BuildFromDocumentAsync(document)); } } sw.Stop(); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); OutputWindowLogger.WriteLn($"Building Queries db from code ended in {sw.ElapsedMilliseconds} ms. Found {results.Count} queries. In {documents.Count} documents."); return(results); }
public void OnBuildBegin(vsBuildScope Scope, vsBuildAction Action) { try { ThreadHelper.ThrowIfNotOnUIThread(); var projectItemHelper = new ProjectItemRetreiver(GotoAsyncPackage.EnvDTE); var projectItems = projectItemHelper.GetProjectItemsFromSolutionProjects(); foreach (var xmlFile in DocumentHelper.GetXmlFiles(projectItems)) { var validator = XmlValidatorsAggregator.Create.AllValidatorsForBuild(xmlFile.FilePath); validator.ValidateBuildDocument(); validator.AddToErrorList(); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "BuildEvents.OnBuildBegin"); OutputWindowLogger.WriteLn($"Exception occured during BuildEvents.OnBuildBegin: { ex.Message}"); } }
public void ItemAdded(ProjectItem ProjectItem) { try { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); string projectItemExtension = Path.GetExtension(ProjectItem.Name); if (projectItemExtension == ".xml") { GotoAsyncPackage.Storage.AnalyzeAndStoreSingle(new XmlFileInfo { FilePath = ProjectItem.FileNames[0], ProjectName = ProjectItem.ContainingProject.Name }); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "ProjectItemEventsEx.ItemAdded"); OutputWindowLogger.WriteLn($"Exception occured during ProjectItemEventsEx.ItemAdded: { ex.Message}"); } }
public async System.Threading.Tasks.Task HandleChangeAsync(IWpfTextView textView) { try { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); var profiler = MiniProfiler.StartNew(nameof(HandleChangeAsync)); profiler.Storage = new NLogStorage(LogManager.GetLogger("profiler")); using (profiler.Step("HandleChangeXml")) { var snapshot = textView.Caret.Position.BufferPosition.Snapshot; ITextDocument textDoc; textView.TextBuffer.Properties.TryGetProperty(typeof(ITextDocument), out textDoc); using (var stringReader = new StringReader(snapshot.GetText())) { var project = GotoAsyncPackage.EnvDTE.Solution.FindProjectItem(textDoc.FilePath)?.ContainingProject?.Name; XmlParser baseParser = new XmlParser(stringReader).Load(); if (baseParser.BatisXmlFileType == BatisXmlFileTypeEnum.SqlMap) { BatisXmlMapParser parser = new BatisXmlMapParser(baseParser).WithFileInfo(textDoc.FilePath, project); var newStatments = parser.GetMapFileStatments(); GotoAsyncPackage.Storage.XmlQueries.UpdateStatmentForFileWihoutKey(newStatments); } if (baseParser.BatisXmlFileType == BatisXmlFileTypeEnum.SqlMapConfig) { BatisXmlConfigParser parser = new BatisXmlConfigParser(baseParser).WithFileInfo(textDoc.FilePath, project); GotoAsyncPackage.Storage.SqlMapConfigProvider.UpdateOrAddConfig(parser.Result); } } } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "XmlFileContentOnChange.HandleChange"); OutputWindowLogger.WriteLn($"Exception occured during handling xml file change: {ex.Message}"); } }
public List <Statement> BuildIndexer(IDictionary <SqlMapConfig, IEnumerable <XmlFileInfo> > configFileInfosPairs) { var result = new List <Statement>(); Stopwatch sw = new Stopwatch(); sw.Start(); foreach (var configFilesPair in configFileInfosPairs) { foreach (var xmlSolutionDocument in configFilesPair.Value) { BatisXmlMapParser parser = new BatisXmlMapParser().WithFileInfo(xmlSolutionDocument.FilePath, xmlSolutionDocument.ProjectName).Load(); bool isBatisQueryXmlFile = parser.XmlNamespace == XmlMapConstants.XmlNamespace; if (isBatisQueryXmlFile) { result.AddRange(parser.GetMapFileStatments()); } } } sw.Stop(); OutputWindowLogger.WriteLn($"Building Queries db from xml ended in {sw.ElapsedMilliseconds} ms. Found {result.Count} queries."); return(result); }
public async System.Threading.Tasks.Task WorkspaceChangedAsync(object sender, WorkspaceChangeEventArgs e) { var profiler = MiniProfiler.StartNew(nameof(WorkspaceChangedAsync)); profiler.Storage = new NLogStorage(LogManager.GetLogger("profiler")); var workspace = sender as VisualStudioWorkspace; switch (e.Kind) { case WorkspaceChangeKind.SolutionAdded: try { using (profiler.Step(WorkspaceChangeKind.SolutionAdded.ToString())) { await _indexingQueue.EnqueueMultipleAsync(workspace.CurrentSolution.Projects); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "WorkspaceChangeKind.SolutionAdded"); await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); OutputWindowLogger.WriteLn($"Exception occured during adding solution: {ex.Message}"); } break; case WorkspaceChangeKind.SolutionChanged: break; case WorkspaceChangeKind.SolutionRemoved: break; case WorkspaceChangeKind.SolutionCleared: break; case WorkspaceChangeKind.SolutionReloaded: break; case WorkspaceChangeKind.ProjectAdded: try { using (profiler.Step(WorkspaceChangeKind.SolutionAdded.ToString())) { await _indexingQueue.EnqueueMultipleAsync(workspace.CurrentSolution.Projects); } } catch (Exception ex) { LogManager.GetLogger("error").Error(ex, "WorkspaceChangeKind.ProjectAdded"); OutputWindowLogger.WriteLn($"Exception occured during adding projects: {ex.Message}"); } break; case WorkspaceChangeKind.ProjectRemoved: break; case WorkspaceChangeKind.ProjectChanged: break; case WorkspaceChangeKind.ProjectReloaded: break; case WorkspaceChangeKind.DocumentAdded: var documentAddedChanges = e.NewSolution.GetChanges(e.OldSolution); var addedDocuments = documentAddedChanges.GetProjectChanges() .SelectMany(x => x.GetAddedDocuments()) .Select(x => workspace.CurrentSolution.GetDocument(x)); await DocumentsAddedActionAsync(addedDocuments); break; case WorkspaceChangeKind.DocumentRemoved: var documentRemovedChanges = e.NewSolution.GetChanges(e.OldSolution); var removedDocuments = documentRemovedChanges.GetProjectChanges() .SelectMany(x => x.GetRemovedDocuments()); await DocumentRemovedActionAsync(removedDocuments); break; case WorkspaceChangeKind.DocumentReloaded: break; case WorkspaceChangeKind.DocumentChanged: break; case WorkspaceChangeKind.AdditionalDocumentAdded: break; case WorkspaceChangeKind.AdditionalDocumentRemoved: break; case WorkspaceChangeKind.AdditionalDocumentReloaded: break; case WorkspaceChangeKind.AdditionalDocumentChanged: break; default: break; } await profiler.StopAsync(); }