init
This commit is contained in:
commit
e124a47765
19374 changed files with 9806149 additions and 0 deletions
|
@ -0,0 +1,50 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
|
||||
namespace Kreta.Naplo.Configuration
|
||||
{
|
||||
public class CorsConfiguration : ConfigurationSection, ICorsConfiguration
|
||||
{
|
||||
const string SectionName = "CorsConfiguration";
|
||||
|
||||
static Lazy<CorsConfiguration> instance;
|
||||
|
||||
public static CorsConfiguration Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance.Value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(nameof(IsEnabled), IsRequired = true)]
|
||||
public bool IsEnabled => (bool)this[nameof(IsEnabled)];
|
||||
|
||||
[ConfigurationProperty(nameof(Urls), IsRequired = true)]
|
||||
public string Urls => (string)this[nameof(Urls)];
|
||||
|
||||
[ConfigurationProperty(nameof(Headers), IsRequired = true)]
|
||||
public string Headers => (string)this[nameof(Headers)];
|
||||
|
||||
[ConfigurationProperty(nameof(Methods), IsRequired = true)]
|
||||
public string Methods => (string)this[nameof(Methods)];
|
||||
|
||||
[ConfigurationProperty(nameof(SupportsCredentials), IsRequired = true)]
|
||||
public bool SupportsCredentials => (bool)this[nameof(SupportsCredentials)];
|
||||
|
||||
static CorsConfiguration()
|
||||
{
|
||||
instance = new Lazy<CorsConfiguration>(() =>
|
||||
{
|
||||
var section = (CorsConfiguration)ConfigurationManager.GetSection(SectionName);
|
||||
|
||||
if (section == null)
|
||||
{
|
||||
throw new ConfigurationErrorsException($"{SectionName} configuration section was not found");
|
||||
}
|
||||
|
||||
return section;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
namespace Kreta.Naplo.Configuration
|
||||
{
|
||||
public interface ICorsConfiguration
|
||||
{
|
||||
bool IsEnabled { get; }
|
||||
string Urls { get; }
|
||||
string Headers { get; }
|
||||
string Methods { get; }
|
||||
bool SupportsCredentials { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{521A86F6-B3BE-47FF-9A91-7E21DC0CDB43}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Kreta.Naplo.Configuration</RootNamespace>
|
||||
<AssemblyName>Kreta.Naplo.Configuration</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Kreta.Core.Configuration, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\..\..\packages\Kreta.Core.Configuration.1.3.20119.1\lib\net452\Kreta.Core.Configuration.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="..\..\..\Tools\SharedAssemblyInfo.cs">
|
||||
<Link>Properties\SharedAssemblyInfo.cs</Link>
|
||||
</Compile>
|
||||
<Compile Include="ICorsConfiguration.cs" />
|
||||
<Compile Include="CorsConfiguration.cs" />
|
||||
<Compile Include="Kreta\IKretaNaploApiConfiguration.cs" />
|
||||
<Compile Include="Kreta\KretaNaploApiConfiguration.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
|
@ -0,0 +1,16 @@
|
|||
namespace Kreta.Naplo.Configuration.Kreta
|
||||
{
|
||||
/// <summary>
|
||||
/// Authorization configuration section interface
|
||||
/// </summary>
|
||||
public interface IKretaNaploApiConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the kreta API key.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The kreta API key.
|
||||
/// </value>
|
||||
string ApiKey { get; }
|
||||
}
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
using System;
|
||||
using System.Configuration;
|
||||
using Validators = Kreta.Core.Configuration.Validators;
|
||||
|
||||
namespace Kreta.Naplo.Configuration.Kreta
|
||||
{
|
||||
/// <summary>
|
||||
/// Authorization configuration section
|
||||
/// </summary>
|
||||
/// <seealso cref="System.Configuration.ConfigurationSection" />
|
||||
public class KretaNaploApiConfiguration : ConfigurationSection, IKretaNaploApiConfiguration
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of section
|
||||
/// </summary>
|
||||
const string SectionName = "KretaNaploApi";
|
||||
|
||||
/// <summary>
|
||||
/// The instance
|
||||
/// </summary>
|
||||
static Lazy<KretaNaploApiConfiguration> instance;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the instance.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The instance.
|
||||
/// </value>
|
||||
public static KretaNaploApiConfiguration Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
return instance.Value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the kreta API key.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The kreta API key.
|
||||
/// </value>
|
||||
/// <remarks>.NET ConfigurationProperty constructor is buggy: it sets the default value of string type to string.Empty (not null), then
|
||||
/// calls all validator for default value too. So in normal way you can't configure e.g. "MinLength" constaint, wihtout explicitly set "Default"
|
||||
/// to a string with length larger than "MinLength". The workaround is to write a custom valitor and set "DefaultValue" to a special
|
||||
/// string that theese validators knows, in order to skip validations when ConfigurationProperty calls them for default values.
|
||||
/// This is a known issue in .NET framework.</remarks>
|
||||
[ConfigurationProperty(nameof(ApiKey), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.StringValidator(false, MinLength = 36, MaxLength = 256)]
|
||||
public string ApiKey
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(ApiKey)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the base URL.
|
||||
/// </summary>
|
||||
/// <value>
|
||||
/// The base URL.
|
||||
/// </value>
|
||||
/// <remarks>.NET ConfigurationProperty constructor is buggy: it sets the default value of string type to string.Empty (not null), then
|
||||
/// calls all validator for default value too. So in normal way you can't configure e.g. "MinLength" constaint, wihtout explicitly set "Default"
|
||||
/// to a string with length larger than "MinLength". The workaround is to write a custom valitor and set "DefaultValue" to a special
|
||||
/// string that theese validators knows, in order to skip validations when ConfigurationProperty calls them for default values.
|
||||
/// This is a known issue in .NET framework.</remarks>
|
||||
[ConfigurationProperty(nameof(BaseUrl), IsRequired = true, DefaultValue = Validators.StringValidator.SkipValidationForDefaultValue)]
|
||||
[Validators.UrlValidator(Validators.UrlType.HttpBaseUrl)]
|
||||
public string BaseUrl
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)this[nameof(BaseUrl)];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="KretaNaploApiConfiguration"/> class.
|
||||
/// </summary>
|
||||
static KretaNaploApiConfiguration()
|
||||
{
|
||||
instance = new Lazy<KretaNaploApiConfiguration>(() =>
|
||||
{
|
||||
var section = (KretaNaploApiConfiguration)ConfigurationManager.GetSection(SectionName);
|
||||
|
||||
if (section == null)
|
||||
{
|
||||
throw new ConfigurationErrorsException($"{SectionName} configuration section was not found");
|
||||
}
|
||||
|
||||
return section;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
|
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="Kreta.Core.Configuration" version="1.3.20119.1" targetFramework="net48" />
|
||||
<package id="Meziantou.Analyzer" version="1.0.688" targetFramework="net48" developmentDependency="true" />
|
||||
</packages>
|
Loading…
Add table
Add a link
Reference in a new issue