public void ShouldCreateProperFullyQualifiedStatmentName() { var mapNamespace = "namespace"; var queryId = "Select"; Assert.Equal("namespace.Select", MapNamespaceHelper.CreateFullQueryString(mapNamespace, queryId)); }
public bool ExecuteRename(Statement query, RenameViewModel renameViewModel, DTE2 envDte) { try { Microsoft.VisualStudio.Shell.ThreadHelper.ThrowIfNotOnUIThread(); var projectItem = envDte.Solution.FindProjectItem(query.QueryFileName); var isProjectItemOpened = projectItem.IsOpen; if (!isProjectItemOpened) { projectItem.Open(); } var textSelection = projectItem.Document.Selection as TextSelection; textSelection.GotoLine(query.QueryLineNumber, true); var line = textSelection.GetText(); line = line.Replace(MapNamespaceHelper.GetQueryWithoutNamespace(query.QueryId), MapNamespaceHelper.GetQueryWithoutNamespace(renameViewModel.QueryText)); textSelection.Insert(line, (int)vsInsertFlags.vsInsertFlagsContainNewText); projectItem.Document.Save(); return(true); } catch (Exception) { return(false); } }
public void ShouldCreateProperFullyQualifiedStatmentNameWithNullNamespace() { string mapNamespace = null; string queryId = "Select"; Assert.Equal("Select", MapNamespaceHelper.CreateFullQueryString(mapNamespace, queryId)); }
public List <Statement> GetMapFileStatmentsWithIdAttributeColumnInfo() { var statementChildNodes = GetChildNodesOfParentByXPath(XmlMapConstants.StatementsRootElementXPath); return(statementChildNodes.Where(e => BatisConstantsHelper.IsBatisStatment(e.Name)).Select(e => new Statement { XmlLine = e.Attributes.FirstOrDefault(x => x.Name == "id")?.Line, XmlLineColumn = e.Attributes.FirstOrDefault(x => x.Name == "id")?.LinePosition, QueryFileName = FileName, QueryFilePath = FilePath, QueryId = e.Id, FullyQualifiedQuery = MapNamespaceHelper.CreateFullQueryString(MapNamespace, e.Id), QueryLineNumber = e.Line, QueryVsProjectName = FileProjectName, MapNamespace = MapNamespace, CacheModel = e.GetAttributeValue("cacheModel", null), ListClass = e.GetAttributeValue("listClass", null), ParameterClass = e.GetAttributeValue("parameterClass", null), ParameterMap = e.GetAttributeValue("parameterMap", null), ResultClass = e.GetAttributeValue("resultClass", null), ResultMap = e.GetAttributeValue("resultMap", null), //Type = e.GetAttributeValue("type", null), Content = e.InnerHtml, }).ToList()); }
public string GetQueryAtLineOrNull(int lineNumber, bool useNamespace) { var nodes = GetAllDescendantsNodes(); var lineNode = GetFirstStatmentNodeForLineOrNull(nodes, lineNumber); if (!useNamespace) { return(lineNode?.Id); } return(MapNamespaceHelper.CreateFullQueryString(MapNamespace, lineNode?.Id)); }
public void RemoveStatmentByValue(List <CSharpQuery> value) { IndexerKey key = new IndexerKey { StatmentName = MapNamespaceHelper.GetQueryWithoutNamespace(value.First().QueryId), VsProjectName = value.First().QueryFileName, StatmentFullyQualifiedName = value.First().QueryId, }; var codeStatmentsForKey = codeStatments[key]; codeStatmentsForKey.Remove(value.First()); codeStatments[key] = codeStatmentsForKey; }
public void RenameQuery(IndexerKey key, string newQueryId) { var statmentInfo = _xmlStatments[key]; var newKey = new IndexerKey { StatmentName = MapNamespaceHelper.GetQueryWithoutNamespace(newQueryId), VsProjectName = key.VsProjectName, StatmentFullyQualifiedName = newQueryId }; statmentInfo.QueryId = newQueryId; _xmlStatments.Remove(key); _xmlStatments.Add(newKey, statmentInfo); }
public List <ResultWindowViewModel> PrepareViewModels(List <ExpressionResult> genericResults, ExpressionResult expressionResult, List <CSharpQuery> nonGenericResults) { return(genericResults.Select(x => new ResultWindowViewModel { File = x.NodeInformation.FileName, Line = x.NodeInformation.LineNumber, FilePath = x.NodeInformation.FilePath, Query = x.TextResult, Namespace = MapNamespaceHelper.DetermineMapNamespaceQueryPairFromCodeInput(expressionResult.TextResult).Item1, }) .Concat(nonGenericResults.Select(x => new ResultWindowViewModel { File = x.QueryFileName, Line = x.QueryLineNumber, Query = x.QueryId, FilePath = x.QueryFilePath, Namespace = MapNamespaceHelper.DetermineMapNamespaceQueryPairFromCodeInput(x.QueryId).Item1, })).ToList()); }
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 override void Execute(string queryResult, ExpressionResult expressionResult) { var codeKeyValuePairs = _codeQueryDataService.GetKeyStatmentPairs(queryResult, UseNamespace); var xmlKeys = _xmlQueryDataService.GetStatmentKeys(queryResult, UseNamespace); var namespaceQueryPair = MapNamespaceHelper.DetermineMapNamespaceQueryPairFromCodeInput(queryResult); RenameModalWindowControl window = new RenameModalWindowControl( new RenameViewModel { QueryText = namespaceQueryPair.Item2, Namespace = string.IsNullOrEmpty(namespaceQueryPair.Item1) ? null : namespaceQueryPair.Item1, }); window.ShowModal(); var returnViewModel = window.DataContext as RenameViewModel; if (returnViewModel.WasInputCanceled || returnViewModel.QueryText == queryResult) { return; } foreach (var key in xmlKeys) { var query = _xmlQueryDataService.GetSingleStatmentFromKey(key); if (_xmlLogicHandler.ExecuteRename(query, returnViewModel, _envDte)) { _xmlQueryDataService.Rename(key, returnViewModel.QueryText); } } foreach (var keyQueryPair in codeKeyValuePairs) { if (_codeLogicHandler.ExecuteRename(keyQueryPair, returnViewModel, _workspace)) { _codeQueryDataService.Rename(keyQueryPair.Key, returnViewModel.QueryText); } } }
private Statement CovertNodeToStatement(HtmlNode node) { return(new Statement { XmlLine = node.Attributes.FirstOrDefault(x => x.Name == "id")?.Line, XmlLineColumn = node.Attributes.FirstOrDefault(x => x.Name == "id")?.LinePosition, QueryFileName = FileName, QueryFilePath = FilePath, QueryId = node.Id, FullyQualifiedQuery = MapNamespaceHelper.CreateFullQueryString(MapNamespace, node.Id), QueryLineNumber = node.Line, QueryVsProjectName = FileProjectName, MapNamespace = MapNamespace, CacheModel = node.GetAttributeValue("cacheModel", null), ListClass = node.GetAttributeValue("listClass", null), ParameterClass = node.GetAttributeValue("parameterClass", null), ParameterMap = node.GetAttributeValue("parameterMap", null), ResultClass = node.GetAttributeValue("resultClass", null), ResultMap = node.GetAttributeValue("resultMap", null), //Type = e.GetAttributeValue("type", null), Content = TrimRedundantNewLines(node.InnerHtml) }); }
public void RenameQuery(IndexerKey key, string newQueryId) { var statments = codeStatments[key]; foreach (var statment in statments) { statment.QueryId = newQueryId; } var newKey = new IndexerKey { StatmentName = MapNamespaceHelper.GetQueryWithoutNamespace(newQueryId), VsProjectName = key.VsProjectName, StatmentFullyQualifiedName = newQueryId, }; codeStatments.Remove(key); if (codeStatments.ContainsKey(newKey)) { codeStatments[newKey] = statments; } else { codeStatments.Add(newKey, statments); } }
private void AddSingleWithoutKey(CSharpQuery value) { IndexerKey key = new IndexerKey { StatmentName = MapNamespaceHelper.GetQueryWithoutNamespace(value.QueryId), VsProjectName = value.QueryVsProjectName, StatmentFullyQualifiedName = value.QueryId, }; if (codeStatments.ContainsKey(key)) { var codeStatmentsForKey = codeStatments[key]; codeStatmentsForKey.Add(value); codeStatments[key] = codeStatmentsForKey; } else { var codeStamentsForKey = new List <CSharpQuery> { value, }; codeStatments.Add(key, codeStamentsForKey); } }
public void ShouldGetQueryWithoutNamespaceForEmptyQueryId() { string queryId = ""; Assert.Equal("", MapNamespaceHelper.GetQueryWithoutNamespace(queryId)); }
public void ShouldGetQueryWithoutNamespace() { string queryId = "namespace.Select"; Assert.Equal("Select", MapNamespaceHelper.GetQueryWithoutNamespace(queryId)); }
public List <IndexerKey> GetStatmentKeysIgnoringNamespace(string query) { return(GotoAsyncPackage.Storage.XmlQueries.GetAllKeys().Where(e => e.StatmentName == MapNamespaceHelper.GetQueryWithoutNamespace(query)).ToList()); }
private void AnalyzeNode(SyntaxNodeAnalysisContext context) { NodeHelpers helper = new NodeHelpers(context.SemanticModel); if (helper.IsBatisMethod(context.Node as InvocationExpressionSyntax) && helper.TryGetArgumentNodeFromInvocation(context.Node as InvocationExpressionSyntax, 0, out ExpressionSyntax expressionSyntax)) { var resolverResult = new ExpressionResolver().GetStringValueOfExpression(expressionSyntax, context.SemanticModel); if (resolverResult.IsSolved) { var queryKeys = GotoAsyncPackage.Storage.XmlQueries.GetKeys(resolverResult.TextResult, MapNamespaceHelper.IsQueryWithNamespace(resolverResult.TextResult)); if (queryKeys.Count < 1) { context.ReportDiagnostic(Diagnostic.Create(QueryNotExistsRule, expressionSyntax.GetLocation(), resolverResult.TextResult)); } } } }