lucenenet-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nightowl...@apache.org
Subject [40/50] [abbrv] lucenenet git commit: Revert "Lucene.Net.Support: Removed Configuration namespace and AppSettings - now using environment variables exclusively"
Date Sun, 05 Mar 2017 11:49:19 GMT
Revert "Lucene.Net.Support: Removed Configuration namespace and AppSettings - now using environment
variables exclusively"

This reverts commit 3d524a9af2fe66a110be19fd80933566843065e7.


Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/2a99f9e0
Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/2a99f9e0
Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/2a99f9e0

Branch: refs/heads/api-work
Commit: 2a99f9e09ca68b14ae4406dc3adaa641f9eb98df
Parents: cce0f08
Author: Shad Storhaug <shad@shadstorhaug.com>
Authored: Sun Mar 5 10:06:48 2017 +0700
Committer: Shad Storhaug <shad@shadstorhaug.com>
Committed: Sun Mar 5 17:08:49 2017 +0700

----------------------------------------------------------------------
 src/Lucene.Net.Core/Lucene.Net.csproj           |   2 +
 src/Lucene.Net.Core/Support/AppSettings.cs      | 162 +++++++++++++++++++
 .../ConfigFileConfigurationExtensions.cs        |  61 +++++++
 .../ConfigFileConfigurationProvider.cs          |  67 ++++++++
 .../ConfigFileConfigurationSource.cs            |  34 ++++
 .../Support/Configuration/Configuration.cs      |  69 ++++++++
 .../Configuration/ConfigurationExtensions.cs    |  44 +++++
 .../Configuration/IConfigurationParser.cs       |  18 +++
 .../Support/Configuration/KeyValueParser.cs     | 121 ++++++++++++++
 .../SettingsConfigurationParser.cs              |  64 ++++++++
 .../Support/RandomizedTest.cs                   |   3 +-
 .../Util/LuceneTestCase.cs                      |   1 +
 12 files changed, 645 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Lucene.Net.csproj
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Lucene.Net.csproj b/src/Lucene.Net.Core/Lucene.Net.csproj
index 3ed5c88..40006b3 100644
--- a/src/Lucene.Net.Core/Lucene.Net.csproj
+++ b/src/Lucene.Net.Core/Lucene.Net.csproj
@@ -596,6 +596,7 @@
     <Compile Include="Store\SingleInstanceLockFactory.cs" />
     <Compile Include="Store\TrackingDirectoryWrapper.cs" />
     <Compile Include="Store\VerifyingLockFactory.cs" />
+    <Compile Include="Support\AppSettings.cs" />
     <Compile Include="Support\AtomicBoolean.cs" />
     <Compile Include="Support\AtomicInteger.cs" />
     <Compile Include="Support\AtomicLong.cs" />
@@ -630,6 +631,7 @@
     <Compile Include="Support\Compatibility\Collections.cs" />
     <Compile Include="Support\ConcurrentHashMapWrapper.cs" />
     <Compile Include="Support\ConcurrentHashSet.cs" />
+    <Compile Include="Support\Configuration\Configuration.cs" />
     <Compile Include="Support\CultureContext.cs" />
     <Compile Include="Support\DataInputStream.cs" />
     <Compile Include="Support\DataOutputStream.cs" />

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/AppSettings.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/AppSettings.cs b/src/Lucene.Net.Core/Support/AppSettings.cs
new file mode 100644
index 0000000..83ee7d6
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/AppSettings.cs
@@ -0,0 +1,162 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+using System;
+
+namespace Lucene.Net.Support
+{
+    /// <summary>
+    ///
+    /// </summary>
+    public class AppSettings
+    {
+        private static System.Collections.Specialized.ListDictionary settings = new System.Collections.Specialized.ListDictionary();
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        public static void Set(System.String key, int defValue)
+        {
+            settings[key] = defValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        public static void Set(System.String key, long defValue)
+        {
+            settings[key] = defValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        public static void Set(System.String key, System.String defValue)
+        {
+            settings[key] = defValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        public static void Set(System.String key, bool defValue)
+        {
+            settings[key] = defValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        /// <returns></returns>
+        public static int Get(System.String key, int defValue)
+        {
+            if (settings[key] != null)
+            {
+                return (int)settings[key];
+            }
+
+            var theValue = Configuration.Configuration.GetAppSetting(key);
+
+            if (theValue == null)
+            {
+                return defValue;
+            }
+            int retValue = Convert.ToInt32(theValue.Trim());
+            settings[key] = retValue;
+            return retValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        /// <returns></returns>
+        public static long Get(System.String key, long defValue)
+        {
+            if (settings[key] != null)
+            {
+                return (long)settings[key];
+            }
+
+            var theValue = Configuration.Configuration.GetAppSetting(key);
+
+            if (theValue == null)
+            {
+                return defValue;
+            }
+            long retValue = Convert.ToInt64(theValue.Trim());
+            settings[key] = retValue;
+            return retValue;
+        }
+
+        /// <summary>
+        ///
+        /// </summary>
+        /// <param name="key"></param>
+        /// <param name="defValue"></param>
+        /// <returns></returns>
+        public static System.String Get(System.String key, System.String defValue)
+        {
+            if (settings[key] != null)
+            {
+                return (System.String)settings[key];
+            }
+
+            System.String theValue = Configuration.Configuration.GetAppSetting(key);
+
+            if (theValue == null)
+            {
+                return defValue;
+            }
+            settings[key] = theValue;
+            return theValue;
+        }
+
+        public static bool Get(System.String key, bool defValue)
+        {
+            if (settings[key] != null)
+            {
+                return (bool)settings[key];
+            }
+
+            var theValue = Configuration.Configuration.GetAppSetting(key);
+
+            if (theValue == null)
+            {
+                return defValue;
+            }
+            bool retValue = Convert.ToBoolean(theValue.Trim());
+            settings[key] = retValue;
+            return retValue;
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationExtensions.cs
b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationExtensions.cs
new file mode 100644
index 0000000..905ac36
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationExtensions.cs
@@ -0,0 +1,61 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. 
+//See https://github.com/aspnet/Entropy/blob/dev/LICENSE.txt in the project root for license
information.
+
+//Code modified to work with latest version of framework.
+
+using System;
+using System.IO;
+using Microsoft.Extensions.Configuration;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public static class ConfigFileConfigurationExtensions
+    {
+        /// <summary>
+        /// Adds configuration values for a *.config file to the ConfigurationBuilder
+        /// </summary>
+        /// <param name="builder">Builder to add configuration values to</param>
+        /// <param name="path">Path to *.config file</param>
+        /// <param name="optional">true if file is optional; false otherwise</param>
+        /// <param name="parsers">Additional parsers to use to parse the config file</param>
+        public static IConfigurationBuilder AddConfigFile(this IConfigurationBuilder builder,
string path, bool optional, params IConfigurationParser[] parsers)
+        {
+            if (path == null)
+            {
+                throw new ArgumentNullException(nameof(path));
+            }
+            else if (string.IsNullOrEmpty(path))
+            {
+                throw new ArgumentException("Path for configuration cannot be null/empty.",
nameof(path));
+            }
+
+            if (!optional && !File.Exists(path))
+            {
+                throw new FileNotFoundException($"Could not find configuration file. File:
[{path}]", path);
+            }
+
+            return builder.Add(new ConfigFileConfigurationSource(path, true, optional, parsers));
+        }
+
+        /// <summary>
+        /// Adds configuration values for an XML configuration the ConfigurationBuilder
+        /// </summary>
+        /// <param name="builder">Builder to add configuration values to</param>
+        /// <param name="configurationContents">XML Contents of configuration</param>
+        /// <param name="parsers">Additional parsers to use to parse the config file</param>
+        public static IConfigurationBuilder AddConfigFile(this IConfigurationBuilder builder,
string configurationContents, params IConfigurationParser[] parsers)
+        {
+            if (configurationContents == null)
+            {
+                throw new ArgumentNullException(nameof(configurationContents));
+            }
+            else if (string.IsNullOrEmpty(configurationContents))
+            {
+                throw new ArgumentException("Path for configuration cannot be null/empty.",
nameof(configurationContents));
+            }
+
+            return builder.Add(new ConfigFileConfigurationSource(configurationContents, false,
false, parsers));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationProvider.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationProvider.cs
b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationProvider.cs
new file mode 100644
index 0000000..446ce9a
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationProvider.cs
@@ -0,0 +1,67 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. 
+//See https://github.com/aspnet/Entropy/blob/dev/LICENSE.txt in the project root for license
information.
+
+//Code modified to work with latest version of framework.
+
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Xml.Linq;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public class ConfigFileConfigurationProvider : ConfigurationProvider
+    {
+        private readonly string _configuration;
+        private readonly bool _loadFromFile;
+        private readonly bool _isOptional;
+
+        private readonly IEnumerable<IConfigurationParser> _parsers;
+
+        public ConfigFileConfigurationProvider(string configuration, bool loadFromFile, bool
optional, IEnumerable<IConfigurationParser> parsers)
+        {
+            _loadFromFile = loadFromFile;
+            _configuration = configuration;
+            _isOptional = optional;
+            _parsers = parsers;
+        }
+
+        public override void Load()
+        {
+            if (_loadFromFile && !_isOptional && !File.Exists(_configuration))
+            {
+                throw new FileNotFoundException("Could not find configuration file to load.",
_configuration);
+            }
+
+            var document = _loadFromFile ? XDocument.Load(_configuration) : XDocument.Parse(_configuration);
+
+            var context = new Stack<string>();
+            var dictionary = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
+
+            foreach (var child in document.Root.Elements())
+            {
+                ParseElement(child, context, dictionary);
+            }
+
+            Data = dictionary;
+        }
+
+        /// <summary>
+        /// Given an XElement tries to parse that element using any of the KeyValueParsers
+        /// and adds it to the results dictionary
+        /// </summary>
+        private void ParseElement(XElement element, Stack<string> context, SortedDictionary<string,
string> results)
+        {
+            foreach (var parser in _parsers)
+            {
+                if (parser.CanParseElement(element))
+                {
+                    parser.ParseElement(element, context, results);
+                    break;
+                }
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationSource.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationSource.cs b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationSource.cs
new file mode 100644
index 0000000..93624e1
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/ConfigFileConfigurationSource.cs
@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+using Microsoft.Extensions.Configuration;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public class ConfigFileConfigurationSource : IConfigurationSource
+    {
+        public string Configuration { get; set; }
+        public bool LoadFromFile { get; set; }
+        public bool Optional { get; set; }
+        public IEnumerable<IConfigurationParser> Parsers { get; set; }
+
+        public ConfigFileConfigurationSource(string configuration, bool loadFromFile, bool
optional, params IConfigurationParser[] parsers)
+        { 
+            LoadFromFile = loadFromFile;
+            Configuration = configuration;
+            Optional = optional;
+
+            var parsersToUse = new List<IConfigurationParser> {
+                new KeyValueParser(),
+                new KeyValueParser("name", "connectionString")
+            };
+
+            parsersToUse.AddRange(parsers);
+
+            Parsers = parsersToUse.ToArray();
+        }
+
+        public IConfigurationProvider Build(IConfigurationBuilder builder)
+        {
+            return new ConfigFileConfigurationProvider(Configuration, LoadFromFile, Optional,
Parsers);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/Configuration.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/Configuration.cs b/src/Lucene.Net.Core/Support/Configuration/Configuration.cs
new file mode 100644
index 0000000..ee9372d
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/Configuration.cs
@@ -0,0 +1,69 @@
+#if NETSTANDARD
+using Microsoft.Extensions.Configuration;
+using System.IO;
+using System.Reflection;
+#else
+using System.Configuration;
+#endif
+
+namespace Lucene.Net.Support.Configuration
+{
+    public static class Configuration
+    {
+#if NETSTANDARD
+        private static IConfigurationRoot _configuration;
+
+        static Configuration()
+        {
+            var builder = new ConfigurationBuilder();
+            var entryAssembly = Assembly.GetEntryAssembly();
+            var configurationFiles = new string[0];
+
+            if (entryAssembly != null)
+            {
+                var directory = Path.GetDirectoryName(entryAssembly.Location);
+                configurationFiles = Directory.GetFiles(directory, "*.config");
+            }
+
+            foreach (var config in configurationFiles)
+            {
+                builder.AddConfigFile(config, false, new KeyValueParser());
+            }
+
+            _configuration = builder.Build();
+        }
+#endif
+
+        public static string GetAppSetting(string key)
+        {
+#if NETSTANDARD
+
+            return _configuration.GetAppSetting(key);
+#else
+            return ConfigurationManager.AppSettings[key];
+#endif
+        }
+
+        public static string GetAppSetting(string key, string defaultValue)
+        {
+            string setting = GetAppSetting(key);
+            return string.IsNullOrEmpty(setting) ? defaultValue : setting;
+        }
+
+        /// <summary>
+        /// Gets the value for the AppSetting with specified key.  
+        /// If key is not present, default value is returned.
+        /// If key is present, value is converted to specified type based on the conversionFunction
specified.
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="key"></param>
+        /// <param name="conversionFunction"></param>
+        /// <param name="defaultValue"></param>
+        /// <returns></returns>
+        public static T GetProperty<T>(string key, T defaultValue, System.Func<string,
T> conversionFunction)
+        {
+            string setting = GetAppSetting(key);
+            return string.IsNullOrEmpty(setting) ? defaultValue : conversionFunction(setting);
+        }
+    }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/ConfigurationExtensions.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/ConfigurationExtensions.cs b/src/Lucene.Net.Core/Support/Configuration/ConfigurationExtensions.cs
new file mode 100644
index 0000000..8ec54ad
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/ConfigurationExtensions.cs
@@ -0,0 +1,44 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. 
+//See https://github.com/aspnet/Entropy/blob/dev/LICENSE.txt in the project root for license
information.
+
+//Code modified to work with latest version of framework.
+
+using System;
+using System.Collections.Immutable;
+using Microsoft.Extensions.Configuration;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public static class ConfigurationExtensions
+    {
+        public const string AppSettings = "appSettings";
+
+        public static string GetAppSetting(this IConfiguration configuration, string name)
+        {
+            return configuration?.GetSection(AppSettings)[name];
+        }
+        
+         public static ImmutableDictionary<string, IConfigurationSection> GetSection(this
IConfiguration configuration, params string[] sectionNames)
+        {
+            if (sectionNames.Length == 0)
+                return ImmutableDictionary<string, IConfigurationSection>.Empty;
+            
+            var fullKey = string.Join(ConfigurationPath.KeyDelimiter, sectionNames);
+
+            return configuration?.GetSection(fullKey).GetChildren()?.ToImmutableDictionary(x
=> x.Key, x => x);
+        }
+
+        public static string GetValue(this IConfiguration configuration, params string[]
keys)
+        {
+            if (keys.Length == 0)
+            {
+                throw new ArgumentException("Need to provide keys", nameof(keys));
+            }
+           
+            var fullKey = string.Join(ConfigurationPath.KeyDelimiter, keys);
+
+            return configuration?[fullKey];
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/IConfigurationParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/IConfigurationParser.cs b/src/Lucene.Net.Core/Support/Configuration/IConfigurationParser.cs
new file mode 100644
index 0000000..d94086e
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/IConfigurationParser.cs
@@ -0,0 +1,18 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. 
+//See https://github.com/aspnet/Entropy/blob/dev/LICENSE.txt in the project root for license
information.
+
+//Code modified to work with latest version of framework.
+
+using System.Collections.Generic;
+using System.Xml.Linq;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public interface IConfigurationParser
+    {
+        bool CanParseElement(XElement element);
+
+        void ParseElement(XElement element, Stack<string> context, SortedDictionary<string,
string> results);
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/KeyValueParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/KeyValueParser.cs b/src/Lucene.Net.Core/Support/Configuration/KeyValueParser.cs
new file mode 100644
index 0000000..27216b1
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/KeyValueParser.cs
@@ -0,0 +1,121 @@
+// Copyright (c) .NET Foundation. All rights reserved.
+// Licensed under the Apache License, Version 2.0. 
+//See https://github.com/aspnet/Entropy/blob/dev/LICENSE.txt in the project root for license
information.
+
+//Code modified to work with latest version of framework.
+
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Xml.Linq;
+
+namespace Lucene.Net.Support.Configuration
+{
+
+    internal enum ConfigurationAction
+    {
+        Add,
+        Remove,
+        Clear
+    }
+  
+    public class KeyValueParser : IConfigurationParser
+    {
+        private readonly string _keyName = "key";
+        private readonly string _valueName = "value";
+        private readonly string[] _supportedActions = Enum.GetNames(typeof(ConfigurationAction)).Select(x
=> x.ToLowerInvariant()).ToArray();
+
+        public KeyValueParser()
+            : this("key", "value")
+        { }
+
+        public KeyValueParser(string key, string value)
+        {
+            _keyName = key;
+            _valueName = value;
+         }
+
+        public bool CanParseElement(XElement element)
+        {
+            var hasKeyAttribute = element.DescendantsAndSelf().Any(x => x.Attribute(_keyName)
!= null);
+
+            return hasKeyAttribute;
+        }
+
+        public void ParseElement(XElement element, Stack<string> context, SortedDictionary<string,
string> results)
+        {
+            if (!CanParseElement(element))
+            {
+                return;
+            }
+
+            if (!element.Elements().Any())
+            {
+                AddToDictionary(element, context, results);
+            }
+
+            context.Push(element.Name.ToString());
+
+            foreach (var node in element.Elements())
+            {
+                var hasSupportedAction = node.DescendantsAndSelf().Any(x => _supportedActions.Contains(x.Name.ToString().ToLowerInvariant()));
+
+                if (!hasSupportedAction)
+                {
+                    continue;
+                }
+
+                ParseElement(node, context, results);
+            }
+
+            context.Pop();
+        }
+
+        private void AddToDictionary(XElement element, Stack<string> context, SortedDictionary<string,
string> results)
+        {
+            ConfigurationAction action;
+
+            if (!Enum.TryParse(element.Name.ToString(), true, out action))
+            {
+                return;
+            }
+
+            var key = element.Attribute(_keyName);
+            var value = element.Attribute(_valueName);
+
+            if (key == null)
+            {
+                return;
+            }
+
+            var fullkey = GetKey(context, key.Value);
+
+            switch (action)
+            {
+                case ConfigurationAction.Add:
+                    string valueToAdd = value.Value;
+
+                    if (results.ContainsKey(fullkey))
+                    {
+                        results[fullkey] = valueToAdd;
+                    }
+                    else
+                    {
+                        results.Add(fullkey, valueToAdd);
+                    }
+                    break;
+                case ConfigurationAction.Remove:
+                    results.Remove(fullkey);
+                    break;
+                default:
+                    throw new NotSupportedException($"Unsupported action: [{action}]");
+            }
+        }
+
+        private static string GetKey(Stack<string> context, string name)
+        {
+            return ConfigurationPath.Combine(context.Reverse().Concat(new[] { name }));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.Core/Support/Configuration/SettingsConfigurationParser.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.Core/Support/Configuration/SettingsConfigurationParser.cs b/src/Lucene.Net.Core/Support/Configuration/SettingsConfigurationParser.cs
new file mode 100644
index 0000000..0e747e6
--- /dev/null
+++ b/src/Lucene.Net.Core/Support/Configuration/SettingsConfigurationParser.cs
@@ -0,0 +1,64 @@
+using Microsoft.Extensions.Configuration;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using System.Xml.Linq;
+
+namespace Lucene.Net.Support.Configuration
+{
+    public class SettingsConfigurationParser : IConfigurationParser
+    {
+        public const string SettingsElement = "Settings";
+        private const string SettingElement = "Setting";
+        private const string Name = "Name";
+        private const string Value = "Value";
+        private const string Profile = "Profile";
+
+        public bool CanParseElement(XElement element)
+        {
+            var ns = element.GetDefaultNamespace() ?? XNamespace.None;
+            var matching = element.DescendantsAndSelf(ns.GetName(SettingsElement)).ToArray();
+            return matching.Any();
+        }
+
+        public void ParseElement(XElement element, Stack<string> context, SortedDictionary<string,
string> results)
+        {
+            var ns = element.GetDefaultNamespace() ?? XNamespace.None;
+
+            if (!CanParseElement(element))
+            {
+                return;
+            }
+
+            context.Push(SettingsElement);
+
+            XName settingElement = ns.GetName(SettingElement);
+            XName valueAttribute = ns.GetName(Value);
+
+            var allSettings = element.DescendantsAndSelf(settingElement).ToArray();
+
+            foreach (var setting in allSettings)
+            {
+                var nameElement = setting.Attribute(Name);
+
+                context.Push(nameElement.Value);
+
+                foreach (var valueElement in setting.Descendants(valueAttribute))
+                {
+                    var profileName = valueElement.Attribute(Profile).Value;
+                    results.Add(GetKey(context, profileName), valueElement.Value);
+                }
+
+                context.Pop();
+            }
+
+            context.Pop();
+        }
+
+        private static string GetKey(Stack<string> context, string name)
+        {
+            return ConfigurationPath.Combine(context.Reverse().Concat(new[] { name }));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.TestFramework/Support/RandomizedTest.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Support/RandomizedTest.cs b/src/Lucene.Net.TestFramework/Support/RandomizedTest.cs
index a24ee2f..71a826a 100644
--- a/src/Lucene.Net.TestFramework/Support/RandomizedTest.cs
+++ b/src/Lucene.Net.TestFramework/Support/RandomizedTest.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using Lucene.Net.Support.Configuration;
+using NUnit.Framework;
 
 
 namespace Lucene.Net.TestFramework.Support

http://git-wip-us.apache.org/repos/asf/lucenenet/blob/2a99f9e0/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
----------------------------------------------------------------------
diff --git a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
index ea824aa..a3f5fa9 100644
--- a/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
+++ b/src/Lucene.Net.TestFramework/Util/LuceneTestCase.cs
@@ -36,6 +36,7 @@ using System.Reflection;
 namespace Lucene.Net.Util
 {
     using Lucene.Net.TestFramework.Support;
+    using Support.Configuration;
     using System.IO;
     using System.Reflection;
     using AlcoholicMergePolicy = Lucene.Net.Index.AlcoholicMergePolicy;


Mime
View raw message