Example #1
0
        private IDictionary <string, string> GetLabels()
        {
            var xml =
                @"<?xml version=""1.0"" encoding=""utf-8""?>" +
                @"<Service enableDynamicOverrides=""false"">" +
                @"  <Endpoints>" +
                @"    <Endpoint id=""WebStatelessEndpoint"" enable=""true"">" +
                @"      <Routes>" +
                @"        <Route routeId=""RouteApi"" order=""1"">" +
                @"          <Match path=""/WebStateless/api/{**catch-all}"" />" +
                @"        </Route>" +
                @"        <Route routeId=""RouteUi"" order=""1"">" +
                @"          <Match path=""/WebStateless/ui/{**catch-all}"" />" +
                @"        </Route>" +
                @"      </Routes>" +
                @"    </Endpoint>" +
                @"  </Endpoints>" +
                @"</Service>";

            using (var xStream = new MemoryStream(Encoding.ASCII.GetBytes(xml)))
            {
                var dictionary = XmlStreamToDictionaryParser.Parse(xStream, options =>
                {
                    options.KeyDelimiter = ".";
                    options.Parents      = new List <string> {
                        "MyApp", "MyService"
                    };
                    options.IsIndexAttribute = (attribute, stack) =>
                    {
                        switch (stack.FirstOrDefault())
                        {
                        case "Endpoint": return(string.Equals(attribute, "Id", StringComparison.OrdinalIgnoreCase));

                        case "Route": return(string.Equals(attribute, "RouteId", StringComparison.OrdinalIgnoreCase));
                        }
                        return(false);
                    };
                });
                foreach (var pair in dictionary)
                {
                    _output.WriteLine($"{pair.Key} = {pair.Value}");
                }

                return(dictionary);
            }
        }
Example #2
0
 /// <summary>
 /// Loads the XML data from a stream.
 /// </summary>
 /// <param name="stream">The stream to read.</param>
 public override void Load(Stream stream)
 {
     try
     {
         Data = XmlStreamToDictionaryParser.ParseStream(
             stream,
             new IO.ParseToDictionaryOptions
         {
             KeyDelimiter = ConfigurationPath.KeyDelimiter,
             Parents      = _source.Parents,
             IsIdentifier = _source.IsIdentifier
         }
             );
     }
     catch (Exception e)
     {
         throw new FormatException("Could not parse the XML file.", e);
     }
 }