Skip to content

Commit

Permalink
Added hosting configuration json and ini file support
Browse files Browse the repository at this point in the history
  • Loading branch information
bytewizer committed Aug 29, 2022
1 parent d753739 commit fa767e5
Show file tree
Hide file tree
Showing 20 changed files with 752 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/actions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
-p:PackageOutputPath=\builds\artifacts
-p:BuildNumber="${{ steps.info.outputs.build }}"
-p:Copyright="${{ steps.info.outputs.copyright }}"
-p:VersionPrefix="2.1.12"
-p:VersionPrefix="2.1.13"
-p:VersionSuffix=preview.${{ steps.info.outputs.build }}
-p:Configuration=${env:CONFIGURATION}
-p:ContinuousIntegrationBuild=true
Expand All @@ -78,7 +78,7 @@ jobs:
-p:PackageOutputPath=\builds\artifacts
-p:BuildNumber="${{ steps.info.outputs.build }}"
-p:Copyright="${{ steps.info.outputs.copyright }}"
-p:VersionPrefix="2.1.12"
-p:VersionPrefix="2.1.13"
-p:VersionSuffix=preview.${{ steps.info.outputs.build }}
-p:Configuration=${env:CONFIGURATION}
-p:ContinuousIntegrationBuild=true
Expand Down
12 changes: 12 additions & 0 deletions src/Bytewizer.TinyCLR.Runtime.sln
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TinyCLR.Hosting",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TinyCLR.Hosting.Configuration", "hosting\Bytewizer.TinyCLR.Hosting.Configuration\Bytewizer.TinyCLR.Hosting.Configuration.csproj", "{71492D2D-6B78-46C8-9531-C02915742A46}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TinyCLR.Hosting.Configuration.Ini", "hosting\Bytewizer.TinyCLR.Hosting.Configuration.Ini\Bytewizer.TinyCLR.Hosting.Configuration.Ini.csproj", "{72592D2D-6B78-46C8-9531-C02915742A46}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bytewizer.TinyCLR.Hosting.Configuration.Json", "hosting\Bytewizer.TinyCLR.Hosting.Configuration.Json\Bytewizer.TinyCLR.Hosting.Configuration.Json.csproj", "{72492D2D-6B78-46C8-9531-C02915742A46}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -141,6 +145,14 @@ Global
{71492D2D-6B78-46C8-9531-C02915742A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71492D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71492D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.Build.0 = Release|Any CPU
{72592D2D-6B78-46C8-9531-C02915742A46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72592D2D-6B78-46C8-9531-C02915742A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72592D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72592D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.Build.0 = Release|Any CPU
{72492D2D-6B78-46C8-9531-C02915742A46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72492D2D-6B78-46C8-9531-C02915742A46}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72492D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72492D2D-6B78-46C8-9531-C02915742A46}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
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>
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 });
}
}
}

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);
}
}
}
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);
}
}

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")]
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>
Loading

0 comments on commit fa767e5

Please sign in to comment.