Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
Fixes #81
Browse files Browse the repository at this point in the history
  • Loading branch information
i4004 committed May 20, 2019
1 parent 44a2746 commit 5dc196d
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web example using Microsoft Katana server</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web example using Nowin server</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web.Examples.SelfHosted unit tests</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web self hosted example</Description>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web as windows service example</Description>
Expand Down
2 changes: 1 addition & 1 deletion src/Simplify.Web.Tests/Simplify.Web.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Simplify.Web unit tests</Description>
Expand Down
315 changes: 315 additions & 0 deletions src/Simplify.Web/Settings/ConfigurationBasedSimplifyWebSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,315 @@
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Simplify.Web.Settings
{
/// <summary>
/// Simplify.Web settings
/// </summary>
/// <seealso cref="ISimplifyWebSettings" />
public sealed class ConfigurationBasedSimplifyWebSettings : ISimplifyWebSettings
{
/// <summary>
/// Initializes a new instance of the <see cref="ConfigurationBasedSimplifyWebSettings"/> class.
/// </summary>
public ConfigurationBasedSimplifyWebSettings(IConfiguration configuration)
{
var config = configuration.GetSection("SimplifyWebSettings");

if (!config.GetChildren().Any())
return;

LoadLanguageManagerSettings(config);
LoadTemplatesSettings(config);
LoadDataCollectorSettings(config);
LoadStyleSettings(config);
LoadOtherSettings(config);
LoadEngineBehaviorSettings(config);
LoadCacheSettings(config);
LoadDiagnosticSettings(config);
}

/// <summary>
/// Default language, for example: "en", "ru", "de" etc., default value is "en"
/// </summary>
public string DefaultLanguage { get; private set; } = "en";

/// <summary>
/// Gets a value indicating whether browser language should be accepted
/// </summary>
/// <value>
/// <c>true</c> if browser language should be accepted; otherwise, <c>false</c>.
/// </value>
public bool AcceptBrowserLanguage { get; private set; }

/// <summary>
/// Default templates directory path, for example: Templates, default value is "Templates"
/// </summary>
public string DefaultTemplatesPath { get; private set; } = "Templates";

/// <summary>
/// Gets a value indicating whether all templates should be loaded from assembly
/// </summary>
/// <value>
/// <c>true</c> if all templates should be loaded from assembly; otherwise, <c>false</c>.
/// </value>
public bool LoadTemplatesFromAssembly { get; private set; }

/// <summary>
/// Gets or sets the master page template file name
/// </summary>
/// <value>
/// The name of the master page template file
/// </value>
public string DefaultMasterTemplateFileName { get; private set; } = "Master.tpl";

/// <summary>
/// Gets or sets the master template main content variable name.
/// </summary>
/// <value>
/// The master template main content variable name.
/// </value>
public string DefaultMainContentVariableName { get; private set; } = "MainContent";

/// <summary>
/// Gets or sets the master template title variable name.
/// </summary>
/// <value>
/// The title variable name.
/// </value>
public string DefaultTitleVariableName { get; private set; } = "Title";

/// <summary>
/// Default site style
/// </summary>
public string DefaultStyle { get; private set; } = "Main";

/// <summary>
/// Data directory path, default value is "App_Data"
/// </summary>
public string DataPath { get; private set; } = "App_Data";

/// <summary>
/// Gets a value indicating whether Simplify.Web static files processing is enabled or controllers requests should be processed only
/// </summary>
public bool StaticFilesEnabled { get; private set; } = true;

/// <summary>
/// Gets the static files paths.
/// </summary>
/// <value>
/// The static files paths.
/// </value>
public IList<string> StaticFilesPaths { get; }
= new List<string> { "styles", "scripts", "images", "content", "fonts" };

/// <summary>
/// Gets the string table files.
/// </summary>
/// <value>
/// The string table files.
/// </value>
public IList<string> StringTableFiles { get; }
= new List<string> { "StringTable.xml" };

/// <summary>
/// Gets or sets a value indicating whether site title postfix should be set automatically
/// </summary>
public bool DisableAutomaticSiteTitleSet { get; private set; }

/// <summary>
/// Gets a value indicating whether exception details should be hide when some unhandled exception occured.
/// </summary>
public bool HideExceptionDetails { get; private set; }

/// <summary>
/// Gets a value indicating whether templates memory cache enabled or disabled.
/// </summary>
/// <value>
/// <c>true</c> if templates memory cache enabled; otherwise, <c>false</c>.
/// </value>
public bool TemplatesMemoryCache { get; private set; }

/// <summary>
/// Gets a value indicating whether string table memory cache enabled or disabled.
/// </summary>
/// <value>
/// <c>true</c> if string table memory cache enabled; otherwise, <c>false</c>.
/// </value>
public bool StringTableMemoryCache { get; private set; }

/// <summary>
/// Gets a value indicating whether file reader caching should be disable.
/// </summary>
public bool DisableFileReaderCache { get; private set; }

/// <summary>
/// Gets a value indicating whether console tracing is enabled.
/// </summary>
/// <value>
/// <c>true</c> if console tracing is enabled; otherwise, <c>false</c>.
/// </value>
public bool ConsoleTracing { get; private set; }

private void LoadLanguageManagerSettings(IConfiguration config)
{
var defaultLanguage = config["DefaultLanguage"];

if (!string.IsNullOrEmpty(defaultLanguage))
DefaultLanguage = defaultLanguage;

var acceptBrowserLanguage = config["AcceptBrowserLanguage"];

if (string.IsNullOrEmpty(acceptBrowserLanguage))
return;

if (bool.TryParse(acceptBrowserLanguage, out var buffer))
AcceptBrowserLanguage = buffer;
}

private void LoadTemplatesSettings(IConfiguration config)
{
var defaultTemplatesPath = config["DefaultTemplatesPath"];

if (!string.IsNullOrEmpty(defaultTemplatesPath))
DefaultTemplatesPath = defaultTemplatesPath;

var loadTemplatesFromAssembly = config["LoadTemplatesFromAssembly"];

if (!string.IsNullOrEmpty(loadTemplatesFromAssembly))
{
if (bool.TryParse(loadTemplatesFromAssembly, out var buffer))
LoadTemplatesFromAssembly = buffer;
}

var defaultMasterTemplateFileName = config["DefaultMasterTemplateFileName"];

if (!string.IsNullOrEmpty(defaultMasterTemplateFileName))
DefaultMasterTemplateFileName = defaultMasterTemplateFileName;
}

private void LoadDataCollectorSettings(IConfiguration config)
{
var defaultMainContentVariableName = config["DefaultMainContentVariableName"];

if (!string.IsNullOrEmpty(defaultMainContentVariableName))
DefaultMainContentVariableName = defaultMainContentVariableName;

var defaultTitleVariableName = config["DefaultTitleVariableName"];

if (!string.IsNullOrEmpty(defaultTitleVariableName))
DefaultTitleVariableName = defaultTitleVariableName;
}

private void LoadStyleSettings(IConfiguration config)
{
var defaultStyle = config["DefaultStyle"];

if (!string.IsNullOrEmpty(defaultStyle))
DefaultStyle = defaultStyle;
}

private void LoadOtherSettings(IConfiguration config)
{
var dataPath = config["DataPath"];

if (!string.IsNullOrEmpty(dataPath))
DataPath = dataPath;

var staticFilesEnabled = config["StaticFilesEnabled"];

if (!string.IsNullOrEmpty(staticFilesEnabled))
{
if (bool.TryParse(staticFilesEnabled, out var buffer))
StaticFilesEnabled = buffer;
}

var staticFilesPaths = config["StaticFilesPaths"];

if (!string.IsNullOrEmpty(staticFilesPaths))
{
StaticFilesPaths.Clear();
var items = staticFilesPaths.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (var item in items)
StaticFilesPaths.Add(item);
}

var stringTableFiles = config["StringTableFiles"];

if (string.IsNullOrEmpty(stringTableFiles))
return;

{
StringTableFiles.Clear();
var items = stringTableFiles.Replace(" ", "").Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

foreach (var item in items)
StringTableFiles.Add(item);
}
}

private void LoadEngineBehaviorSettings(IConfiguration config)
{
var disableAutomaticSiteTitleSet = config["DisableAutomaticSiteTitleSet"];

if (!string.IsNullOrEmpty(disableAutomaticSiteTitleSet))
{
if (bool.TryParse(disableAutomaticSiteTitleSet, out var buffer))
DisableAutomaticSiteTitleSet = buffer;
}

var hideExceptionDetails = config["HideExceptionDetails"];

if (string.IsNullOrEmpty(hideExceptionDetails))
return;

{
if (bool.TryParse(hideExceptionDetails, out var buffer))
HideExceptionDetails = buffer;
}
}

private void LoadCacheSettings(IConfiguration config)
{
var templatesMemoryCache = config["TemplatesMemoryCache"];

if (!string.IsNullOrEmpty(templatesMemoryCache))
{
if (bool.TryParse(templatesMemoryCache, out var buffer))
TemplatesMemoryCache = buffer;
}

var stringTableMemoryCache = config["StringTableMemoryCache"];

if (!string.IsNullOrEmpty(stringTableMemoryCache))
{
if (bool.TryParse(stringTableMemoryCache, out var buffer))
StringTableMemoryCache = buffer;
}

var disableFileReaderCache = config["DisableFileReaderCache"];

if (string.IsNullOrEmpty(disableFileReaderCache))
return;

{
if (bool.TryParse(disableFileReaderCache, out var buffer))
DisableFileReaderCache = buffer;
}
}

private void LoadDiagnosticSettings(IConfiguration config)
{
var consoleTracing = config["ConsoleTracing"];

if (string.IsNullOrEmpty(consoleTracing))
return;

if (bool.TryParse(consoleTracing, out var buffer))
ConsoleTracing = buffer;
}
}
}
8 changes: 5 additions & 3 deletions src/Simplify.Web/Simplify.Web.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net452</TargetFrameworks>
<TargetFrameworks>net462</TargetFrameworks>
<Authors>Alexander Krylkov</Authors>
<Product>Simplify</Product>
<Description>Lightweight and fast .NET web-framework based on MVC and OWIN</Description>
Expand All @@ -12,7 +12,8 @@
<RepositoryType>GIT</RepositoryType>
<PackageTags>.NET web-framework MVC DI OWIN</PackageTags>
<PackageReleaseNotes>
* Upgrade to Simplify.DI 2.0.1, Simplify.Templates 1.5
* Upgrade to .NET Framwork 4.6.2
+ IConfiguration based settings implementation (ConfigurationBasedSimplifyWebSettings) for ISimplifyWebSettings added
</PackageReleaseNotes>
<OutputPath>bin\Any CPU\$(Configuration)\</OutputPath>
<DocumentationFile>bin\Any CPU\$(Configuration)\$(TargetFramework)\Simplify.Web.xml</DocumentationFile>
Expand All @@ -21,14 +22,15 @@
<EmbeddedResource Include="Diagnostics\ExceptionIDetails.html" />
<EmbeddedResource Include="Diagnostics\ExceptionInfoPage.html" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net452' ">
<ItemGroup Condition="'$(TargetFramework)' == 'net462' ">
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.2.0" />
<PackageReference Include="Microsoft.Owin" Version="4.0.0" />
<PackageReference Include="Owin" Version="1.0" />
<PackageReference Include="Simplify.DI" Version="2.0.1" />
Expand Down

0 comments on commit 5dc196d

Please sign in to comment.