Lucene.Net.Support: Deleted unused Configuration namespace
Project: http://git-wip-us.apache.org/repos/asf/lucenenet/repo Commit: http://git-wip-us.apache.org/repos/asf/lucenenet/commit/94f21f7e Tree: http://git-wip-us.apache.org/repos/asf/lucenenet/tree/94f21f7e Diff: http://git-wip-us.apache.org/repos/asf/lucenenet/diff/94f21f7e Branch: refs/heads/api-work Commit: 94f21f7ed6c06acbe5e5f7903872466378152fff Parents: 47ad5af Author: Shad Storhaug <[email protected]> Authored: Thu Apr 13 03:40:06 2017 +0700 Committer: Shad Storhaug <[email protected]> Committed: Thu Apr 13 06:44:07 2017 +0700 ---------------------------------------------------------------------- .../ConfigFileConfigurationExtensions.cs | 61 ---------- .../ConfigFileConfigurationProvider.cs | 67 ---------- .../ConfigFileConfigurationSource.cs | 34 ------ .../Configuration/ConfigurationExtensions.cs | 45 ------- .../Configuration/IConfigurationParser.cs | 18 --- .../Support/Configuration/KeyValueParser.cs | 121 ------------------- .../SettingsConfigurationParser.cs | 64 ---------- src/Lucene.Net/project.json | 17 +-- 8 files changed, 2 insertions(+), 425 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/lucenenet/blob/94f21f7e/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationExtensions.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationExtensions.cs b/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationExtensions.cs deleted file mode 100644 index 905ac36..0000000 --- a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationExtensions.cs +++ /dev/null @@ -1,61 +0,0 @@ -// 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/94f21f7e/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationProvider.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationProvider.cs b/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationProvider.cs deleted file mode 100644 index 446ce9a..0000000 --- a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationProvider.cs +++ /dev/null @@ -1,67 +0,0 @@ -// 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/94f21f7e/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationSource.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationSource.cs b/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationSource.cs deleted file mode 100644 index 93624e1..0000000 --- a/src/Lucene.Net/Support/Configuration/ConfigFileConfigurationSource.cs +++ /dev/null @@ -1,34 +0,0 @@ -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/94f21f7e/src/Lucene.Net/Support/Configuration/ConfigurationExtensions.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/ConfigurationExtensions.cs b/src/Lucene.Net/Support/Configuration/ConfigurationExtensions.cs deleted file mode 100644 index 28f8fe2..0000000 --- a/src/Lucene.Net/Support/Configuration/ConfigurationExtensions.cs +++ /dev/null @@ -1,45 +0,0 @@ -// 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; - -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 IDictionary<string, IConfigurationSection> GetSection(this IConfiguration configuration, params string[] sectionNames) - { - if (sectionNames.Length == 0) - return Collections.UnmodifiableMap(new Dictionary<string, IConfigurationSection>()); - - var fullKey = string.Join(ConfigurationPath.KeyDelimiter, sectionNames); - - return Collections.UnmodifiableMap(configuration?.GetSection(fullKey).GetChildren()?.ToDictionary(k => k.Key, v => v)); - } - - 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/94f21f7e/src/Lucene.Net/Support/Configuration/IConfigurationParser.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/IConfigurationParser.cs b/src/Lucene.Net/Support/Configuration/IConfigurationParser.cs deleted file mode 100644 index d94086e..0000000 --- a/src/Lucene.Net/Support/Configuration/IConfigurationParser.cs +++ /dev/null @@ -1,18 +0,0 @@ -// 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/94f21f7e/src/Lucene.Net/Support/Configuration/KeyValueParser.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/KeyValueParser.cs b/src/Lucene.Net/Support/Configuration/KeyValueParser.cs deleted file mode 100644 index 27216b1..0000000 --- a/src/Lucene.Net/Support/Configuration/KeyValueParser.cs +++ /dev/null @@ -1,121 +0,0 @@ -// 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/94f21f7e/src/Lucene.Net/Support/Configuration/SettingsConfigurationParser.cs ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/Support/Configuration/SettingsConfigurationParser.cs b/src/Lucene.Net/Support/Configuration/SettingsConfigurationParser.cs deleted file mode 100644 index d5551e5..0000000 --- a/src/Lucene.Net/Support/Configuration/SettingsConfigurationParser.cs +++ /dev/null @@ -1,64 +0,0 @@ -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 SETTINGS_ELEMENT = "Settings"; - private const string SETTING_ELEMENT = "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(SETTINGS_ELEMENT)).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(SETTINGS_ELEMENT); - - XName settingElement = ns.GetName(SETTING_ELEMENT); - 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/94f21f7e/src/Lucene.Net/project.json ---------------------------------------------------------------------- diff --git a/src/Lucene.Net/project.json b/src/Lucene.Net/project.json index a019a71..0c6cd89 100644 --- a/src/Lucene.Net/project.json +++ b/src/Lucene.Net/project.json @@ -36,11 +36,9 @@ } }, "dependencies": { - "Microsoft.Extensions.Configuration": "1.0.0", - "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.DependencyModel": "1.0.0-rc2-final", - "Newtonsoft.Json": "9.0.1", "NETStandard.Library": "1.6.0", + "Newtonsoft.Json": "9.0.1", "System.Collections.NonGeneric": "4.0.1", "System.Collections.Specialized": "4.0.1", "System.Diagnostics.Process": "4.1.0", @@ -63,18 +61,7 @@ "FEATURE_CLONEABLE", "FEATURE_SERIALIZABLE", "FEATURE_THREADPOOL_UNSAFEQUEUEWORKITEM" - ], - "compile": { - "excludeFiles": [ - "Support/Configuration/ConfigFileConfigurationExtensions.cs", - "Support/Configuration/ConfigFileConfigurationProvider.cs", - "Support/Configuration/ConfigFileConfigurationSource.cs", - "Support/Configuration/ConfigurationExtensions.cs", - "Support/Configuration/IConfigurationParser.cs", - "Support/Configuration/KeyValueParser.cs", - "Support/Configuration/SettingsConfigurationParser.cs" - ] - } + ] } } }
