<commit_before>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security;

namespace LinqToDB.Configuration
{
	/// <summary>
	/// Implementation of custom configuration section.
	/// </summary>
	public class LinqToDBSection : ConfigurationSection, ILinqToDBSettings
	{
		static readonly ConfigurationPropertyCollection _properties               = new ConfigurationPropertyCollection();
		static readonly ConfigurationProperty           _propDataProviders        = new ConfigurationProperty("dataProviders",        typeof(DataProviderElementCollection), new DataProviderElementCollection(), ConfigurationPropertyOptions.None);
		static readonly ConfigurationProperty           _propDefaultConfiguration = new ConfigurationProperty("defaultConfiguration", typeof(string),                        null,                                ConfigurationPropertyOptions.None);
		static readonly ConfigurationProperty           _propDefaultDataProvider  = new ConfigurationProperty("defaultDataProvider",  typeof(string),                        null,                                ConfigurationPropertyOptions.None);

		static LinqToDBSection()
		{
			_properties.Add(_propDataProviders);
			_properties.Add(_propDefaultConfiguration);
			_properties.Add(_propDefaultDataProvider);
		}

		private static LinqToDBSection _instance;
		public  static LinqToDBSection  Instance
		{
			get
			{
				if (_instance == null)
				{
					try
					{
						_instance = (LinqToDBSection)ConfigurationManager.GetSection("linq2db");
					}
					catch (SecurityException)
					{
						return null;
					}
				}

				return _instance;
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			get { return _properties; }
		}

		public DataProviderElementCollection DataProviders
		{
			get { return (DataProviderElementCollection) base[_propDataProviders]; }
		}

		public string DefaultConfiguration { get { return (string)base[_propDefaultConfiguration]; } }
		public string DefaultDataProvider  { get { return (string)base[_propDefaultDataProvider];  } }

		IEnumerable<IConnectionStringSettings> ILinqToDBSettings.ConnectionStrings
		{
			get
			{
				foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings)
					yield return new ConnectionStringEx(css);
			}
		}

		IEnumerable<IDataProviderSettings> ILinqToDBSettings.DataProviders
		{
			get { return DataProviders.OfType<DataProviderElement>(); }
		}

		class ConnectionStringEx : IConnectionStringSettings
		{
			private readonly ConnectionStringSettings _css;

			public ConnectionStringEx(ConnectionStringSettings css)
			{
				_css = css;
			}

			public string ConnectionString { get { return _css.ConnectionString; } }
			public string Name { get { return _css.Name; } }
			public string ProviderName { get { return _css.ProviderName; } }
			public bool IsGlobal { get { return IsMachineConfig(_css); } }
		}

		internal static bool IsMachineConfig(ConnectionStringSettings css)
		{
			string source;

			try
			{
				source = css.ElementInformation.Source;
			}
			catch (Exception)
			{
				source = "";
			}

			return source == null || source.EndsWith("machine.config", StringComparison.OrdinalIgnoreCase);
		}
	}
}
<commit_msg>fix #480<commit_after>﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Security;

namespace LinqToDB.Configuration
{
	/// <summary>
	/// Implementation of custom configuration section.
	/// </summary>
	public class LinqToDBSection : ConfigurationSection, ILinqToDBSettings
	{
		static readonly ConfigurationPropertyCollection _properties               = new ConfigurationPropertyCollection();
		static readonly ConfigurationProperty           _propDataProviders        = new ConfigurationProperty("dataProviders",        typeof(DataProviderElementCollection), new DataProviderElementCollection(), ConfigurationPropertyOptions.None);
		static readonly ConfigurationProperty           _propDefaultConfiguration = new ConfigurationProperty("defaultConfiguration", typeof(string),                        null,                                ConfigurationPropertyOptions.None);
		static readonly ConfigurationProperty           _propDefaultDataProvider  = new ConfigurationProperty("defaultDataProvider",  typeof(string),                        null,                                ConfigurationPropertyOptions.None);

		static LinqToDBSection()
		{
			_properties.Add(_propDataProviders);
			_properties.Add(_propDefaultConfiguration);
			_properties.Add(_propDefaultDataProvider);
		}

		private static LinqToDBSection _instance;
		public  static LinqToDBSection  Instance
		{
			get
			{
				if (_instance == null)
				{
					try
					{
						_instance = (LinqToDBSection)ConfigurationManager.GetSection("linq2db")
							?? new LinqToDBSection();
					}
					catch (SecurityException)
					{
						return null;
					}
				}

				return _instance;
			}
		}

		protected override ConfigurationPropertyCollection Properties
		{
			get { return _properties; }
		}

		public DataProviderElementCollection DataProviders
		{
			get { return (DataProviderElementCollection) base[_propDataProviders]; }
		}

		public string DefaultConfiguration { get { return (string)base[_propDefaultConfiguration]; } }
		public string DefaultDataProvider  { get { return (string)base[_propDefaultDataProvider];  } }

		IEnumerable<IConnectionStringSettings> ILinqToDBSettings.ConnectionStrings
		{
			get
			{
				foreach (ConnectionStringSettings css in ConfigurationManager.ConnectionStrings)
					yield return new ConnectionStringEx(css);
			}
		}

		IEnumerable<IDataProviderSettings> ILinqToDBSettings.DataProviders
		{
			get { return DataProviders.OfType<DataProviderElement>(); }
		}

		class ConnectionStringEx : IConnectionStringSettings
		{
			private readonly ConnectionStringSettings _css;

			public ConnectionStringEx(ConnectionStringSettings css)
			{
				_css = css;
			}

			public string ConnectionString { get { return _css.ConnectionString; } }
			public string Name { get { return _css.Name; } }
			public string ProviderName { get { return _css.ProviderName; } }
			public bool IsGlobal { get { return IsMachineConfig(_css); } }
		}

		internal static bool IsMachineConfig(ConnectionStringSettings css)
		{
			string source;

			try
			{
				source = css.ElementInformation.Source;
			}
			catch (Exception)
			{
				source = "";
			}

			return source == null || source.EndsWith("machine.config", StringComparison.OrdinalIgnoreCase);
		}
	}
}

{'fraction_non_alphanumeric': 0.07349042709867452, 'fraction_numerical': 0.0007363770250368188, 'mean_word_length': 3.0934297769740806, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4924506', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1661, 'n_words': 365}