SobekCM.Core.Configuration.Engine.Engine_Path_Endpoint.AddChild C# (CSharp) Method

AddChild() public method

public AddChild ( string ChildSegment, Engine_Path_Endpoint Child ) : void
ChildSegment string
Child Engine_Path_Endpoint
return void
        public void AddChild(string ChildSegment, Engine_Path_Endpoint Child)
        {
            // Ensure the collection exists
            if (Children == null)
                Children = new List<Engine_Path_Endpoint>();

            // Ensure the dictionary is built correctly
            ensure_dictionary_built();

            // Does an endpoint already exist here?
            if (childDictionary.ContainsKey(ChildSegment))
            {
                Engine_Path_Endpoint matchingEndpoint = childDictionary[ChildSegment];
                Children.Remove(matchingEndpoint);
            }

            childDictionary[ChildSegment] = Child;
            Children.Add(Child);
        }

Usage Example

        private static void read_microservices_simple_endpoint_details(XmlReader ReaderXml, Engine_Path_Endpoint ParentSegment)
        {
            Engine_Path_Endpoint endpoint = new Engine_Path_Endpoint {IsEndpoint = true};

            string componentid = String.Empty;
            string restrictionid = String.Empty;
            string method = String.Empty;
            bool enabled = true;
            Microservice_Endpoint_Protocol_Enum protocol = Microservice_Endpoint_Protocol_Enum.JSON;

            if (ReaderXml.MoveToAttribute("Segment"))
                endpoint.Segment = ReaderXml.Value.Trim();
            if (ReaderXml.MoveToAttribute("ComponentID"))
                componentid = ReaderXml.Value.Trim();
            if (ReaderXml.MoveToAttribute("Method"))
                method = ReaderXml.Value.Trim();
            if (ReaderXml.MoveToAttribute("Enabled"))
            {
                if (String.Compare(ReaderXml.Value.Trim(), "false", StringComparison.OrdinalIgnoreCase) == 0)
                    enabled = false;
            }
            if (ReaderXml.MoveToAttribute("RestrictionRangeID"))
                restrictionid = ReaderXml.Value.Trim();
            if (ReaderXml.MoveToAttribute("Protocol"))
            {
                switch (ReaderXml.Value.Trim().ToUpper())
                {
                    case "JSON":
                        protocol = Microservice_Endpoint_Protocol_Enum.JSON;
                        break;

                    case "JSON-P":
                        protocol = Microservice_Endpoint_Protocol_Enum.JSON_P;
                        break;

                    case "PROTOBUF":
                        protocol = Microservice_Endpoint_Protocol_Enum.PROTOBUF;
                        break;

                    case "SOAP":
                        protocol = Microservice_Endpoint_Protocol_Enum.SOAP;
                        break;

                    case "XML":
                        protocol = Microservice_Endpoint_Protocol_Enum.XML;
                        break;

                    case "TEXT":
                        protocol = Microservice_Endpoint_Protocol_Enum.TEXT;
                        break;

                    default:
                        protocol = Microservice_Endpoint_Protocol_Enum.JSON;
                        break;
                }
            }

            ReaderXml.MoveToElement();

            if ((componentid.Length > 0) && (endpoint.Segment.Length > 0) && (method.Length > 0))
            {
                if (ParentSegment != null)
                {
                    // Add this endpoint
                    ParentSegment.AddChild(endpoint.Segment, endpoint);

                    // Add the verb mapping defaulted to GET
                    endpoint.GetMapping = new Engine_VerbMapping(method, enabled, protocol, Microservice_Endpoint_RequestType_Enum.GET, componentid, restrictionid);
                }
            }
        }
All Usage Examples Of SobekCM.Core.Configuration.Engine.Engine_Path_Endpoint::AddChild