/// <summary> /// Update the project in-memory state. /// </summary> /// <param name="xml"> /// The project XML. /// </param> public virtual void Update(string xml) { if (xml == null) { throw new ArgumentNullException(nameof(xml)); } ClearDiagnostics(); Xml = Parser.ParseText(xml); XmlPositions = new TextPositions(xml); XmlLocator = new XmlLocator(Xml, XmlPositions); IsDirty = true; bool loaded = TryLoadMSBuildProject(); if (loaded) { MSBuildLocator = new MSBuildLocator(MSBuildProject, XmlLocator, XmlPositions); } else { MSBuildLocator = null; } IsMSBuildProjectCached = !loaded; }
public void InEmptyElementName(string testFileName, int line, int column, string expectedElementName) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation result = locator.Inspect(testPosition); Assert.NotNull(result); Assert.Equal(XSNodeKind.Element, result.Node.Kind); Assert.True(result.IsElement(), "IsElement"); XSElement element = (XSElement)result.Node; Assert.Equal(expectedElementName, element.Name); Assert.True(result.IsEmptyElement(), "IsEmptyElement"); Assert.True(result.IsName(), "IsName"); Assert.False(result.IsElementContent(), "IsElementContent"); // TODO: Verify Parent, PreviousSibling, and NextSibling. }
/// <summary> /// Load and parse the project. /// </summary> /// <param name="cancellationToken"> /// An optional <see cref="CancellationToken"/> that can be used to cancel the operation. /// </param> /// <returns> /// A task representing the load operation. /// </returns> public virtual async Task Load(CancellationToken cancellationToken = default(CancellationToken)) { ClearDiagnostics(); Xml = null; XmlPositions = null; XmlLocator = null; string xml; using (StreamReader reader = ProjectFile.OpenText()) { xml = await reader.ReadToEndAsync(); } Xml = Parser.ParseText(xml); XmlPositions = new TextPositions(xml); XmlLocator = new XmlLocator(Xml, XmlPositions); IsDirty = false; await ConfigurePackageSources(cancellationToken); bool loaded = TryLoadMSBuildProject(); if (loaded) { MSBuildLocator = new MSBuildLocator(MSBuildProject, XmlLocator, XmlPositions); } else { MSBuildLocator = null; } IsMSBuildProjectCached = !loaded; }
public void CanCompleteAttribute(string testFileName, int line, int column, string expectedElementName, PaddingType expectedPadding) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation location = locator.Inspect(testPosition); Assert.NotNull(location); XSPath elementPath = XSPath.Parse(expectedElementName); XSElement element; XSAttribute replaceAttribute; PaddingType needsPadding; Assert.True( location.CanCompleteAttribute(out element, out replaceAttribute, out needsPadding, onElementWithPath: elementPath), "CanCompleteAttribute" ); Assert.NotNull(element); Assert.Null(replaceAttribute); Assert.Equal(expectedPadding, needsPadding); }
/// <summary> /// Update the project in-memory state. /// </summary> /// <param name="xml"> /// The project XML. /// </param> /// <param name="cancellationToken"> /// An optional <see cref="CancellationToken"/> that can be used to cancel the operation. /// </param> /// <returns> /// A task representing the update operation. /// </returns> public virtual async Task Update(string xml, CancellationToken cancellationToken = default) { if (xml == null) { throw new ArgumentNullException(nameof(xml)); } ClearDiagnostics(); Xml = Parser.ParseText(xml); XmlPositions = new TextPositions(xml); XmlLocator = new XmlLocator(Xml, XmlPositions); IsDirty = true; bool loaded = TryLoadMSBuildProject(); if (loaded) { MSBuildLocator = new MSBuildObjectLocator(MSBuildProject, XmlLocator, XmlPositions); } else { MSBuildLocator = null; } IsMSBuildProjectCached = !loaded; await UpdatePackageReferences(cancellationToken); }
/// <summary> /// Inspect the specified location in the XML. /// </summary> /// <param name="position"> /// The location's position. /// </param> /// <returns> /// An <see cref="XmlLocation"/> representing the result of the inspection. /// </returns> public XmlLocation InspectXml(Position position) { if (!HasXml) { throw new InvalidOperationException($"XML for project '{ProjectFile.FullName}' is not loaded."); } return(XmlLocator.Inspect(position)); }
private void SearchLayer(ILayer pSubLayer, XmlLocator locator, string searchKey) { if (_searchCount > _context.Config.LocatorMaxCount) { return; } IQueryFilter queryFilter = new QueryFilter(); IFeatureClass pClass = ((IFeatureLayer)pSubLayer).FeatureClass; string likeStr = WorkspaceHelper.GetSpecialCharacter(pClass as IDataset, esriSQLSpecialCharacters.esriSQL_WildcardManyMatch); if (!string.IsNullOrEmpty(searchKey)) { queryFilter.WhereClause = BuildWhereClause(locator.SearchFields, searchKey, likeStr); } IFeatureCursor cursor = pClass.Search(queryFilter, false); IFeature pFeature = cursor.NextFeature(); int nameIdx = GetFieldIdx(cursor, locator.NameField); int addIdx = GetFieldIdx(cursor, locator.AddressField); int descIdx = GetFieldIdx(cursor, locator.DescriptionField); int telIdx = GetFieldIdx(cursor, locator.TelephoneField); int emailIdx = GetFieldIdx(cursor, locator.EmailField); int phoIdx = GetFieldIdx(cursor, locator.PhotoField); while (pFeature != null) { IGeometry pGeometry = pFeature.Shape; if (pGeometry.IsEmpty) { pFeature = cursor.NextFeature(); continue; } DataRow row = _dataTable.NewRow(); row["图层"] = pSubLayer.Name; row["序号"] = pFeature.OID; row["名称"] = nameIdx < 0 ? "" : pFeature.get_Value(nameIdx); row["地址"] = addIdx < 0 ? "" : pFeature.get_Value(addIdx); row["说明"] = descIdx < 0 ? "" : pFeature.get_Value(descIdx); row["电话"] = telIdx < 0 ? "" : pFeature.get_Value(telIdx); row["邮箱"] = emailIdx < 0 ? "" : pFeature.get_Value(emailIdx); row["要素"] = pFeature.Shape; row["照片"] = phoIdx < 0 ? null : pFeature.get_Value(phoIdx); _dataTable.Rows.Add(row); _searchCount++; if (_searchCount > _context.Config.LocatorMaxCount) { break; } pFeature = cursor.NextFeature(); } OtherHelper.ReleaseObject(cursor); }
public void CanCompleteElement(string testFileName, int line, int column) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation location = locator.Inspect(testPosition); Assert.NotNull(location); XSElement replacingElement; Assert.True(location.CanCompleteElement(out replacingElement), "CanCompleteElement"); Assert.NotNull(replacingElement); }
public void TrySearch(bool allowKeyEmpty) { if (cmbLocators.SelectedIndex < 0) { return; } _dataTable.Rows.Clear(); _searchCount = 0; string searchKey = txtKey.Text.Trim(); if (allowKeyEmpty == false && string.IsNullOrEmpty(searchKey)) { return; } XmlLocator locator = FindLocatorByName(cmbLocators.SelectedItem.ToString()); if (locator == null) { return; } _map = _context.MapControl.Map as IMap; ILayer pLayer = LayerHelper.QueryLayerByDisplayName(_map, locator.Layer); if (pLayer == null) { MessageService.Current.Warn("找不到定位所需的图层" + locator.Layer); return; } if (pLayer is IGroupLayer && pLayer is ICompositeLayer) { ICompositeLayer pGroupLayer = pLayer as ICompositeLayer; for (int i = 0; i < pGroupLayer.Count; i++) { ILayer pSubLayer = pGroupLayer.Layer[i]; SearchLayer(pSubLayer, locator, searchKey); } } else if (pLayer is IFeatureLayer) { SearchLayer(pLayer, locator, searchKey); } this.grdResult.Update(); }
public void InAttributeValue(string testFileName, int line, int column, string expectedAttributeName) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation result = locator.Inspect(testPosition); Assert.NotNull(result); XSAttribute attribute; Assert.True(result.IsAttribute(out attribute), "IsAttribute"); Assert.True(result.IsAttributeValue(), "IsAttributeValue"); Assert.Equal(expectedAttributeName, attribute.Name); // TODO: Verify Parent, PreviousSibling, and NextSibling. }
public void IsExpression_Success(string testFileName, int line, int column, ExpressionKind expectedExpressionKind) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation location = locator.Inspect(testPosition); Assert.NotNull(location); ExpressionNode actualExpression; Range actualExpressionRange; Assert.True( location.IsExpression(out actualExpression, out actualExpressionRange), "IsExpression" ); Assert.NotNull(actualExpression); Assert.Equal(expectedExpressionKind, actualExpression.Kind); }
public void CanCompleteElementInParentWithRelativePath(string testFileName, int line, int column, string expectedParent) { Position testPosition = new Position(line, column); string testXml = LoadTestFile("TestFiles", testFileName + ".xml"); TextPositions positions = new TextPositions(testXml); XmlDocumentSyntax document = Parser.ParseText(testXml); XmlLocator locator = new XmlLocator(document, positions); XmlLocation location = locator.Inspect(testPosition); Assert.NotNull(location); XSPath expectedParentPath = XSPath.Parse(expectedParent); XSElement replaceElement; Assert.True( location.CanCompleteElement(out replaceElement, parentPath: expectedParentPath), "CanCompleteElement" ); Assert.NotNull(replaceElement); Assert.Equal(expectedParent, replaceElement.ParentElement?.Name); }