public IList <Link> AnalyzeSchema(OpenApiSchema schema, PathParameter pathParameter) { IList <Link> links = new List <Link>(); AnalyzeSchema(schema, false, "$", new HashSet <OpenApiSchema>(), links, pathParameter); return(links); }
//distance f-ion should return distance between two adjacent nodes //estimate should return distance between any node and destination node public static Path FindPath(Tile start, Tile destination, PathParameter parameter = PathParameter.Walkable) { //set of already checked nodes List <Tile> closed = new List <Tile>(); //queued nodes in open set PriorityQueue <float, Path> queue = new PriorityQueue <float, Path>(); queue.Enqueue(0f, new Path(start)); while (!queue.IsEmpty) { var path = queue.Dequeue(); if (closed.Contains(path.LastStep)) { continue; } if (path.LastStep.Equals(destination)) { return(path); } List <Tile> neighbours = new List <Tile>(); closed.Add(path.LastStep); if (parameter == PathParameter.AnyTile) { neighbours = path.LastStep.GetNeighbourTiles(); } else if (parameter == PathParameter.Walkable) { neighbours = path.LastStep.GetWalkableNeighbours(); } else if (parameter == PathParameter.WalkableAndVisible) { neighbours = path.LastStep.GetWalkableAndVisibleNeighbours(); } if (neighbours.Count == 0) { Debug.Log("Could not find Neighbours for " + path.LastStep.gameObject.name); } foreach (Tile t in neighbours) { float d = 1f; //new step added without modifying current path Path newPath = path.AddStep(t, d); queue.Enqueue((float)(newPath.TotalCost + (start.gameObject.transform.localPosition - start.gameObject.transform.localPosition).magnitude), newPath); } } return(null); }
public IList <Link> AnalyzeResource(PathSegment pathSegment, PathParameter pathParameter) { IList <Link> links = new List <Link>(); //iterate over all operations foreach (Operation operation in pathSegment.Operations) { IList <Link> linksOfIteration = AnalyzeOperation((OApiOperation)operation, pathParameter); foreach (Link link in linksOfIteration) { links.Add(link); } } return(links); }
private void dataGridView1_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { //用户单击DataGridView“操作”列中的“查看”按钮。 if (DataGridViewOneButtonCell.IsButtonClick(sender, e)) { var pathIndex = Convert.ToInt32(dataGridView1["ColAction", e.RowIndex].Value); // 获取所要删除关联对象的主键。 if (_currentPath != null) { //恢复为黑色 dataGridView1.Rows[_currentPath.Index - 1].Cells[1].Style.ForeColor = Color.Black; dataGridView1.Rows[_currentPath.Index - 1].Cells[2].Style.ForeColor = Color.Black; } _currentPath = _pathParameters.FirstOrDefault(p => p.Index == pathIndex); //路径演示开始 PathShowStart(); } }
public IList <Link> AnalyzeOperation(OApiOperation operation, PathParameter pathParameter) { if (OperationTypesFilter.Count == 0 || OperationTypesFilter.Contains(operation.Method)) { IList <Link> links = new List <Link>(); //iterate over all response foreach (KeyValuePair <string, OpenApiResponse> openApiRespose in operation.OpenApiOperation.Responses) { IList <Link> linksOfIteration = AnalyzeResponse(openApiRespose.Key, openApiRespose.Value, pathParameter, operation.Method); foreach (Link link in linksOfIteration) { link.Operation = operation; links.Add(link); } } return(links); } return(new List <Link>()); }
/// <summary> /// Analyzes the passed <see cref="OpenApiSchema"/> for properties whose names match the passed <see cref="PathParameter"/> name. The results are stored as <see cref="Link"/> objects in the passed result list. /// Moreover, this method requires the current position in the schema, which is documented as XPath, a flag that indicates whether the result is within an array structure, and a set that contains all <see cref="OpenApiSchema"/>s that have already been analyzed in order to avoid loops. /// Note that this method is called recursively. /// </summary> /// <param name="pathParameterName"></param> /// <param name="schema"></param> /// <param name="isInArray"></param> /// <param name="xPath"></param> /// <param name="alreadyAnalyzedSchemas"></param> /// <param name="results"></param> private void AnalyzeSchema(OpenApiSchema schema, bool isInArray, string xPath, ISet <OpenApiSchema> alreadyAnalyzedSchemas, IList <Link> results, PathParameter pathParameter) { string pathParameterName = pathParameter.ParameterName; //Create a copy of the Set of already analyzed schemas. Thus, only current path within the structure is memorized: ISet <OpenApiSchema> alreadyAnalyzedSchemasCopy = new HashSet <OpenApiSchema>(alreadyAnalyzedSchemas); //ISet<OpenApiSchema> alreadyAnalyzedSchemasCopy = alreadyAnalyzedSchemas; if (alreadyAnalyzedSchemasCopy.Contains(schema) || schema == null) { return; } alreadyAnalyzedSchemasCopy.Add(schema); //analyze items if (schema.Items != null) { AnalyzeSchema(schema.Items, isInArray, xPath, alreadyAnalyzedSchemasCopy, results, pathParameter); } //analyze linked schemas type of 'AllOf' if (schema.AllOf != null) { foreach (OpenApiSchema linkedSchema in schema.AllOf) { AnalyzeSchema(linkedSchema, isInArray, xPath, alreadyAnalyzedSchemasCopy, results, pathParameter); } } //analyze linked schemas type of 'AnyOf' if (schema.AnyOf != null) { foreach (OpenApiSchema linkedSchema in schema.AnyOf) { AnalyzeSchema(linkedSchema, isInArray, xPath, alreadyAnalyzedSchemasCopy, results, pathParameter); } } //analyze linked schemas type of 'OneOf' if (schema.OneOf != null) { foreach (OpenApiSchema linkedSchema in schema.OneOf) { AnalyzeSchema(linkedSchema, isInArray, xPath, alreadyAnalyzedSchemasCopy, results, pathParameter); } } //analyze properties of schema if (schema.Properties != null) { foreach (KeyValuePair <string, OpenApiSchema> prop in schema.Properties) { string name = prop.Key; OpenApiSchema property = prop.Value; //filter type if (String.IsNullOrWhiteSpace(property.Type) || CompareTo(property.Type, new string[] { "string", "number", "integer", "boolean" })) { string modifiedPathParameterName = pathParameterName; if (IsNameCaseInvariant) { name = name.ToLower(); modifiedPathParameterName = pathParameterName.ToLower(); } //check for exact match (if enabled) if (AllowExactMatch && name.CompareTo(modifiedPathParameterName) == 0) { Link link = new Link(); link.MatchType = LinkMatchType.exactMatch; link.XPath = xPath + "." + prop.Key; link.ContainsMultipleValues = isInArray; link.PathParameter = pathParameter; results.Add(link); } //check whether property name contains parameter name (if enabled) else if (AllowPropertyNameContainsParameterName && name.Contains(modifiedPathParameterName)) { Link link = new Link(); link.MatchType = LinkMatchType.propertyNameContainsPathParameterName; link.XPath = xPath + "." + prop.Key; link.ContainsMultipleValues = isInArray; link.PathParameter = pathParameter; results.Add(link); } //check whether parameter name contains property name (if enabled) else if (AllowParameterNameContainsPropertyName && modifiedPathParameterName.Contains(name)) { Link link = new Link(); link.MatchType = LinkMatchType.pathParameterNameContainsPropertyName; link.XPath = xPath + "." + prop.Key; link.ContainsMultipleValues = isInArray; link.PathParameter = pathParameter; results.Add(link); } } else if (property.Type.CompareTo("array") == 0) { AnalyzeSchema(property, true, xPath + "." + name + "[*]", alreadyAnalyzedSchemasCopy, results, pathParameter); } else //property.Type == "object" { AnalyzeSchema(property, isInArray, xPath + "." + name, alreadyAnalyzedSchemasCopy, results, pathParameter); } } } }
public IList <Link> AnalyzeMediaType(string mediaTypeName, OpenApiMediaType mediaType, PathParameter pathParameter) { if (CheckMediaType(mediaTypeName)) { OpenApiSchema schema = mediaType.Schema; IList <Link> links = AnalyzeSchema(schema, pathParameter); foreach (Link link in links) { link.MediaType = mediaTypeName; } return(links); } return(new List <Link>()); }
public IList <Link> AnalyzeResponse(string statusCode, OpenApiResponse response, PathParameter pathParameter, HttpMethod method) { if (String.IsNullOrWhiteSpace(ResponseCodeFilter) || statusCode.StartsWith(ResponseCodeFilter)) { if (method == HttpMethod.GET && response.Content.Count == 0) { MissingMediaCounter++; } IList <Link> links = new List <Link>(); //iterate over all media types foreach (KeyValuePair <string, OpenApiMediaType> mediaType in response.Content) { IList <Link> linksOfIteration = AnalyzeMediaType(mediaType.Key, mediaType.Value, pathParameter); foreach (Link link in linksOfIteration) { link.StatusCode = statusCode; links.Add(link); } } return(links); } return(new List <Link>()); }