-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added hosting configuration json and ini file support
- Loading branch information
Showing
20 changed files
with
752 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...izer.TinyCLR.Hosting.Configuration.Ini/Bytewizer.TinyCLR.Hosting.Configuration.Ini.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?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>{72592D2D-6B78-46C8-9531-C02915742A46}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Bytewizer.TinyCLR.Hosting.Configuration.Ini</RootNamespace> | ||
<AssemblyName>Bytewizer.TinyCLR.Hosting.Configuration.Ini</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<LangVersion>9</LangVersion> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Description>Generic Host extention library supporting ini files built for TinyCLR IoT devices.</Description> | ||
<PackageTags>ghi tinyclr tinyclros sitcore iot generic host hosting</PackageTags> | ||
<AssemblyProduct>TinyCLR</AssemblyProduct> | ||
</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> | ||
<DocumentationFile>bin\Debug\Bytewizer.TinyCLR.Hosting.Configuration.Ini.xml</DocumentationFile> | ||
</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> | ||
<DocumentationFile>bin\Release\Bytewizer.TinyCLR.Hosting.Configuration.Ini.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Configuration\IniConfigurationExtensions.cs" /> | ||
<Compile Include="Configuration\IniStreamConfigurationProvider.cs" /> | ||
<Compile Include="Configuration\IniStreamConfigurationSource.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="GHIElectronics.TinyCLR.Core"> | ||
<Version>2.2.0.4200</Version> | ||
</PackageReference> | ||
<PackageReference Include="GHIElectronics.TinyCLR.IO"> | ||
<Version>2.2.0.4200</Version> | ||
</PackageReference> | ||
<PackageReference Include="NuGet.Build.Tasks.Pack"> | ||
<Version>6.3.0</Version> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Bytewizer.TinyCLR.Hosting.Configuration\Bytewizer.TinyCLR.Hosting.Configuration.csproj"> | ||
<Project>{71492D2D-6B78-46C8-9531-C02915742A46}</Project> | ||
<Name>Bytewizer.TinyCLR.Hosting.Configuration</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
33 changes: 33 additions & 0 deletions
33
...g/Bytewizer.TinyCLR.Hosting.Configuration.Ini/Configuration/IniConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.IO; | ||
|
||
namespace Bytewizer.TinyCLR.Hosting.Configuration.Ini | ||
{ | ||
/// <summary> | ||
/// Extension methods for adding <see cref="IniStreamConfigurationProvider"/>. | ||
/// </summary> | ||
public static class IniConfigurationExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a INI configuration source to <paramref name="builder"/>. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IConfigurationBuilder"/> to add to.</param> | ||
/// <param name="stream">The <see cref="Stream"/> to read the ini configuration data from.</param> | ||
/// <returns>The <see cref="IConfigurationBuilder"/>.</returns> | ||
public static IConfigurationBuilder AddIniStream(this IConfigurationBuilder builder, Stream stream) | ||
{ | ||
if (stream == null) | ||
{ | ||
throw new ArgumentNullException(); | ||
} | ||
|
||
return builder.Add(new IniStreamConfigurationSource() { Stream = stream }); | ||
} | ||
} | ||
} | ||
|
97 changes: 97 additions & 0 deletions
97
...tewizer.TinyCLR.Hosting.Configuration.Ini/Configuration/IniStreamConfigurationProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
using System; | ||
using System.IO; | ||
using System.Collections; | ||
|
||
namespace Bytewizer.TinyCLR.Hosting.Configuration.Ini | ||
{ | ||
/// <summary> | ||
/// An INI file based <see cref="StreamConfigurationProvider"/>. | ||
/// </summary> | ||
public class IniStreamConfigurationProvider : StreamConfigurationProvider | ||
{ | ||
/// <summary> | ||
/// Constructor. | ||
/// </summary> | ||
/// <param name="source">The <see cref="IniStreamConfigurationSource"/>.</param> | ||
public IniStreamConfigurationProvider(IniStreamConfigurationSource source) : base(source) { } | ||
|
||
/// <summary> | ||
/// Read a stream of INI values into a key/value dictionary. | ||
/// </summary> | ||
/// <param name="stream">The stream of INI data.</param> | ||
/// <returns>The <see cref="Hashtable"/> which was read from the stream.</returns> | ||
public static Hashtable Read(Stream stream) | ||
{ | ||
var data = new Hashtable(); | ||
|
||
using (var reader = new StreamReader(stream)) | ||
{ | ||
string sectionPrefix = string.Empty; | ||
|
||
while (reader.Peek() != -1) | ||
{ | ||
string rawLine = reader.ReadLine()!; // Since Peak didn't return -1, stream hasn't ended. | ||
string line = rawLine.Trim(); | ||
|
||
// Ignore blank lines | ||
//if (string.IsNullOrWhiteSpace(line)) | ||
if (string.IsNullOrEmpty(line)) | ||
{ | ||
continue; | ||
} | ||
// Ignore comments | ||
if (line[0] is ';' or '#' or '/') | ||
{ | ||
continue; | ||
} | ||
// [Section:header] | ||
if (line[0] == '[' && line[line.Length - 1] == ']') | ||
{ | ||
// remove the brackets | ||
sectionPrefix = line.Substring(1, line.Length - 2).Trim() + ":"; | ||
|
||
continue; | ||
} | ||
|
||
// key = value OR "value" | ||
int separator = line.IndexOf('='); | ||
if (separator < 0) | ||
{ | ||
throw new FormatException(rawLine); | ||
} | ||
|
||
string key = sectionPrefix + line.Substring(0, separator).Trim(); | ||
string value = line.Substring(separator + 1).Trim(); | ||
|
||
// Remove quotes | ||
if (value.Length > 1 && value[0] == '"' && value[value.Length - 1] == '"') | ||
{ | ||
value = value.Substring(1, value.Length - 2); | ||
} | ||
|
||
if (data.Contains(key)) | ||
{ | ||
throw new FormatException(key); | ||
} | ||
|
||
data[key.ToLower()] = value; | ||
} | ||
} | ||
return data; | ||
} | ||
|
||
/// <summary> | ||
/// Loads INI configuration key/values from a stream into a provider. | ||
/// </summary> | ||
/// <param name="stream">The <see cref="Stream"/> to load ini configuration data from.</param> | ||
public override void Load(Stream stream) | ||
{ | ||
Data = Read(stream); | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...Bytewizer.TinyCLR.Hosting.Configuration.Ini/Configuration/IniStreamConfigurationSource.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Copyright (c) .NET Foundation and Contributors | ||
// See LICENSE file in the project root for full license information. | ||
// | ||
|
||
namespace Bytewizer.TinyCLR.Hosting.Configuration.Ini | ||
{ | ||
/// <summary> | ||
/// Represents an INI file as an <see cref="IConfigurationSource"/>. | ||
/// Files are simple line structures (<a href="https://en.wikipedia.org/wiki/INI_file">INI Files on Wikipedia</a>) | ||
/// </summary> | ||
/// <examples> | ||
/// [Section:Header] | ||
/// key1=value1 | ||
/// key2 = " value2 " | ||
/// ; comment | ||
/// # comment | ||
/// / comment | ||
/// </examples> | ||
public class IniStreamConfigurationSource : StreamConfigurationSource | ||
{ | ||
/// <summary> | ||
/// Builds the <see cref="IniStreamConfigurationProvider"/> for this source. | ||
/// </summary> | ||
/// <param name="builder">The <see cref="IConfigurationBuilder"/>.</param> | ||
/// <returns>An <see cref="IniStreamConfigurationProvider"/></returns> | ||
public override IConfigurationProvider Build(IConfigurationBuilder builder) | ||
=> new IniStreamConfigurationProvider(this); | ||
} | ||
} | ||
|
4 changes: 4 additions & 0 deletions
4
src/hosting/Bytewizer.TinyCLR.Hosting.Configuration.Ini/Properties/AssemblyInfo.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
using System.Runtime.InteropServices; | ||
|
||
[assembly: ComVisible(false)] | ||
[assembly: Guid("9e368003-1168-49f2-863e-8799a9436bea")] |
79 changes: 79 additions & 0 deletions
79
...er.TinyCLR.Hosting.Configuration.Json/Bytewizer.TinyCLR.Hosting.Configuration.Json.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?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>{72492D2D-6B78-46C8-9531-C02915742A46}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>Bytewizer.TinyCLR.Hosting.Configuration.Json</RootNamespace> | ||
<AssemblyName>Bytewizer.TinyCLR.Hosting.Configuration.Json</AssemblyName> | ||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion> | ||
<FileAlignment>512</FileAlignment> | ||
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> | ||
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder> | ||
<LangVersion>9</LangVersion> | ||
<NuGetPackageImportStamp> | ||
</NuGetPackageImportStamp> | ||
<TargetFrameworkProfile /> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<Description>Generic Host extention library supporting json files built for TinyCLR IoT devices.</Description> | ||
<PackageTags>ghi tinyclr tinyclros sitcore iot generic host hosting</PackageTags> | ||
<AssemblyProduct>TinyCLR</AssemblyProduct> | ||
</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> | ||
<DocumentationFile>bin\Debug\Bytewizer.TinyCLR.Hosting.Configuration.Json.xml</DocumentationFile> | ||
</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> | ||
<DocumentationFile>bin\Release\Bytewizer.TinyCLR.Hosting.Configuration.Json.xml</DocumentationFile> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Configuration\JsonConfigurationExtensions.cs" /> | ||
<Compile Include="Configuration\JsonConfigurationParser.cs" /> | ||
<Compile Include="Configuration\JsonFileConfigurationProvider.cs" /> | ||
<Compile Include="Configuration\JsonStreamConfigurationProvider.cs" /> | ||
<Compile Include="Configuration\JsonFileConfigurationSource.cs" /> | ||
<Compile Include="Configuration\JsonStreamConfigurationSource.cs" /> | ||
<Compile Include="Configuration\FileConfigurationSource.cs" /> | ||
<Compile Include="Configuration\FileConfigurationProvider.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<PackageReference Include="GHIElectronics.TinyCLR.Core"> | ||
<Version>2.2.0.4200</Version> | ||
</PackageReference> | ||
<PackageReference Include="GHIElectronics.TinyCLR.Data.Json"> | ||
<Version>2.2.0.4200</Version> | ||
</PackageReference> | ||
<PackageReference Include="GHIElectronics.TinyCLR.Devices.Storage"> | ||
<Version>2.2.0.4200</Version> | ||
</PackageReference> | ||
<PackageReference Include="NuGet.Build.Tasks.Pack"> | ||
<Version>6.3.0</Version> | ||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets> | ||
<PrivateAssets>all</PrivateAssets> | ||
</PackageReference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<ProjectReference Include="..\Bytewizer.TinyCLR.Hosting.Configuration\Bytewizer.TinyCLR.Hosting.Configuration.csproj"> | ||
<Project>{71492D2D-6B78-46C8-9531-C02915742A46}</Project> | ||
<Name>Bytewizer.TinyCLR.Hosting.Configuration</Name> | ||
</ProjectReference> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
Oops, something went wrong.