/// <summary> Get the endpoint configuration, based on the requested path </summary> /// <param name="Paths"> Requested URL paths </param> /// <returns> Matched endpoint configuration, otherwise NULL </returns> public Engine_Path_Endpoint Get_Endpoint(List <string> Paths) { // Ensure the dictionary is built ensure_dictionary_built(); // Find a match by path if (rootPathsDictionary.ContainsKey(Paths[0])) { Engine_Path_Endpoint path = rootPathsDictionary[Paths[0]]; Paths.RemoveAt(0); do { // Did we find an endpoint? if (path.IsEndpoint) { return(path); } // Look to the next part of the path if (Paths.Count > 0) { if (!path.ContainsChildKey(Paths[0])) { return(null); } path = path.GetChild(Paths[0]); Paths.RemoveAt(0); } else { return(null); } } while (true); } return(null); }
private static void read_microservices_details_mapping(XmlReader ReaderXml, Engine_Server_Configuration Config, Engine_Path_Endpoint ParentSegment ) { while (ReaderXml.Read()) { if (ReaderXml.NodeType == XmlNodeType.Element) { switch (ReaderXml.Name.ToLower()) { case "removeall": if (ParentSegment != null) { if (ParentSegment.Children != null) ParentSegment.Children.Clear(); } else { Config.RootPaths.Clear(); } break; case "path": if (ReaderXml.MoveToAttribute("Segment")) { Engine_Path_Endpoint path; string segment = ReaderXml.Value.Trim(); if (ParentSegment == null) { if (Config.ContainsRootKey(segment.ToLower())) path = Config.GetRoot(segment.ToLower()); else { path = new Engine_Path_Endpoint {Segment = segment}; Config.AddRoot(segment.ToLower(), path); } } else { if (ParentSegment.ContainsChildKey(segment.ToLower())) { path = ParentSegment.GetChild(segment.ToLower()); } else { path = new Engine_Path_Endpoint { Segment = segment }; ParentSegment.AddChild(path.Segment, path ); } } ReaderXml.MoveToElement(); XmlReader subTreeReader = ReaderXml.ReadSubtree(); subTreeReader.Read(); read_microservices_details_mapping(subTreeReader, Config, path); } break; case "complexendpoint": // Read the top-endpoint information, before getting to each verb mapping bool disabled_at_top = false; Engine_Path_Endpoint endpoint = new Engine_Path_Endpoint { IsEndpoint = true }; if (ReaderXml.MoveToAttribute("Segment")) endpoint.Segment = ReaderXml.Value.Trim(); if ((ReaderXml.MoveToAttribute("Enabled")) && (String.Compare(ReaderXml.Value.Trim(), "false", StringComparison.OrdinalIgnoreCase) == 0)) disabled_at_top = true; // Now, read what remains ReaderXml.MoveToElement(); XmlReader complexReader = ReaderXml.ReadSubtree(); complexReader.Read(); read_microservices_complex_endpoint_details(complexReader, endpoint, disabled_at_top); // If a verb was mapped and there was a valid segment, add this if ((!String.IsNullOrEmpty(endpoint.Segment)) && (endpoint.HasVerbMapping)) { if (ParentSegment != null) { // Add this endpoint ParentSegment.AddChild(endpoint.Segment, endpoint); } } break; case "endpoint": read_microservices_simple_endpoint_details(ReaderXml, ParentSegment); break; } } } }