Commit 0c04b58b authored by Andy James's avatar Andy James

Migrate out NChronicle.Console, NChronicle.File and NChronicle.SMTP

NChronicle.Console is now at https://git.ikimi.co/NChronicle/NChronicle.Core
NChronicle.File is now at https://git.ikimi.co/NChronicle/NChronicle.File
NChronicle.SMTP is now at https://git.ikimi.co/NChronicle/NChronicle.SMTP
parent 0a926e14
Pipeline #16 passed with stage
......@@ -5,5 +5,5 @@ packages/
*.csproj.user
*.nupkg
*.log
*/bin/
*/obj/
**/bin/
**/obj/
......@@ -4,4 +4,4 @@ stages:
Build Solution:
stage: Build
script: "powershell .\\Build.ps1"
\ No newline at end of file
script: "powershell .\\Build.ps1 NChronicle.Core.sln"
\ No newline at end of file
[submodule "NChronicle.Core.Wiki"]
path = _Wiki
url = [email protected]:NChronicle/NChronicle.Core.wiki
Param([string] $msbuild)
Param([string] $target, [string] $msbuild)
$PROGRAM_FILES_32 = ${env:ProgramFiles(x86)}
$DEFAULT_LOCATION_FOR_BUILDTOOLS = "$PROGRAM_FILES_32\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe"
......@@ -26,4 +26,4 @@ if (![String]::IsNullOrEmpty($msbuild)) {
}
}
&$msbuild
\ No newline at end of file
&$msbuild $target
\ No newline at end of file
Param([string] $sourcePath, [string] $buildPath)
$files = get-childitem "$sourcePath*.md";
$regex = [System.Text.RegularExpressions.Regex]::new("\<a href\=\`".*?\`"\>.*?\<\/a\>");
$targetRegex = [System.Text.RegularExpressions.Regex]::new("(?<=(href\=\`")).*?(?=\`")");
$titleRegex = [System.Text.RegularExpressions.Regex]::new("(?<=(\`"\>)).*?(?=(\<\/a\>))");
foreach ($file in $files) {
set-content $file $regex.Replace(([IO.File]::ReadAllText($file)), {
param($match);
$target = $targetRegex.Match($match).Value;
if ([String]::IsNullOrEmpty($target) -or $target.ToString().StartsWith('#') -or !(Test-Path "$sourcePath$target.md")) {
return $match;
}
Write-Host("Found link $match");
$title = $titleRegex.Match($match).Value;
if ([String]::IsNullOrEmpty($title)) {
$title = $target
}
Write-Host("Rewritten to [$title]($target)")
return "[$title]($target)"
});
}
Write-Host("Removing markdown files in $buildPath")
Remove-Item $buildPath\*.md
Write-Host("Removing media files in $buildPath")
Remove-Item -Force -Recurse $buildPath\media\
Write-Host("Copying markdown files from $sourcePath to $buildPath")
Copy-Item $sourcePath\*.md $buildPath\
Write-Host("Copying media files from $sourcePath to $buildPath")
Copy-Item -Force -Recurse $sourcePath\media $buildPath\
\ No newline at end of file
This diff is collapsed.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Xml;
using System.Xml.Schema;
using NChronicle.Console.Configuration;
using NChronicle.Console.Delegates;
using NChronicle.Core.Interfaces;
using NChronicle.Core.Model;
namespace NChronicle.Console {
/// <summary>
/// A <see cref="IChronicleLibrary"/> writing <see cref="ChronicleRecord"/>s to the Console.
/// </summary>
public class ConsoleChronicleLibrary : IChronicleLibrary {
private readonly ConsoleChronicleLibraryConfiguration _configuration;
private readonly Dictionary<string, MethodHandler> _methods;
private readonly Dictionary<string, KeyHandler> _keys;
/// <summary>
/// Create a new <see cref="ConsoleChronicleLibrary"/> instance with the default configuration.
/// </summary>
public ConsoleChronicleLibrary () {
this._configuration = new ConsoleChronicleLibraryConfiguration ();
this._methods = new Dictionary<string, MethodHandler> {
{"TAGS", this.TagsMethodHandler}
};
this._keys = new Dictionary<string, KeyHandler> {
{"MSG", this.MessageKeyHandler},
{"EXC", this.ExceptionKeyHandler},
{"EMSG", this.ExceptionMessageKeyHandler},
{"TH", this.ThreadKeyHandler},
{"TAGS", this.TagsKeyHandler},
{"LVL", this.LevelKeyHandler}
};
}
/// <summary>
/// Render the record to the console (if not filtered by <see cref="ChronicleLevel"/> or tag ignorance).
/// </summary>
/// <param name="record">The <see cref="ChronicleRecord"/> to render.</param>
public void Store (ChronicleRecord record) {
if (!this.ListenTo (record))
return;
var pattern = this._configuration.OutputPattern;
var output = this.FormulateOutput (record, pattern);
this.SendToConsole (output, record.Level);
}
private bool ListenTo (ChronicleRecord record) {
return (this._configuration.Levels.Any () && this._configuration.Levels.ContainsKey (record.Level))
&& (!this._configuration.Tags.Any () || this._configuration.Tags.Keys.Any (record.Tags.Contains))
&& !this._configuration.IgnoredTags.Keys.Any (record.Tags.Contains);
}
private string FormulateOutput (ChronicleRecord record, string pattern) {
var output = pattern;
var currentTime = TimeZoneInfo.ConvertTimeFromUtc (DateTime.UtcNow, this._configuration.TimeZone);
foreach (var token in this.FindTokens (pattern)) {
var tokenBody = token.Substring (1, token.Length - 2);
var tokenIsDate = tokenBody.StartsWith ("%");
if (tokenIsDate) {
var dateFormatting = tokenBody.Remove (0, 1);
output = output.Replace (token, currentTime.ToString (dateFormatting));
continue;
}
var tokenIsQuery = tokenBody.Contains ("?");
if (tokenIsQuery) {
var queryKey = tokenBody.Split ('?') [0];
var tokenIsInverseQuery = false;
if (queryKey.EndsWith ("!")) {
queryKey = queryKey.Remove (queryKey.Length - 1);
tokenIsInverseQuery = true;
}
var hasMeaning = this._keys.ContainsKey (queryKey)
&& !string.IsNullOrEmpty (this._keys [queryKey] (record));
if (tokenIsInverseQuery == hasMeaning) {
output = output.Replace (token, string.Empty);
continue;
}
var queryBody = tokenBody.Substring (queryKey.Length + (tokenIsInverseQuery ? 2 : 1));
var queryOutput = this.FormulateOutput (record, queryBody);
output = output.Replace (token, queryOutput);
continue;
}
var tokenIsMethodInvokation = tokenBody.Contains ("|");
if (tokenIsMethodInvokation) {
var methodKey = tokenBody.Split ('|') [0];
var invokationArguments = tokenBody.Substring (methodKey.Length + 1).Split ('|');
if (this._methods.ContainsKey (methodKey)) {
output = output.Replace (token, this._methods [methodKey] (record, invokationArguments));
continue;
}
}
if (this._keys.ContainsKey (tokenBody)) {
output = output.Replace (token, this._keys [tokenBody] (record));
}
}
return output;
}
private IEnumerable<string> FindTokens (string input) {
var output = new List<string> ();
var nest = 0;
var position = -1;
var token = new StringBuilder ();
while (++position < input.Length) {
if (input [position] == '{') {
nest++;
}
if (nest > 0) {
token.Append (input [position]);
}
if (input [position] == '}') {
nest--;
if (nest == 0) {
output.Add (token.ToString ());
token.Clear ();
}
}
}
return output;
}
private string TagsMethodHandler (ChronicleRecord record, params string [] parameters) {
return parameters.Length < 1 ? string.Empty : string.Join (parameters [0], record.Tags);
}
private string MessageKeyHandler (ChronicleRecord record) {
return record.Message != record.Exception?.Message ? record.Message : string.Empty;
}
private string ExceptionKeyHandler (ChronicleRecord record) {
return record.Exception?.ToString ();
}
private string ExceptionMessageKeyHandler (ChronicleRecord record) {
return record.Exception?.Message;
}
private string ThreadKeyHandler (ChronicleRecord record) {
return Thread.CurrentThread.ManagedThreadId.ToString ();
}
private string TagsKeyHandler (ChronicleRecord record) {
return this.TagsMethodHandler (record, ", ");
}
private string LevelKeyHandler (ChronicleRecord record) {
return record.Level.ToString ();
}
private void SendToConsole (string output, ChronicleLevel level) {
lock (System.Console.Out) {
var prevBackgroundColor = System.Console.BackgroundColor;
var prevForegroundColor = System.Console.ForegroundColor;
System.Console.BackgroundColor = this._configuration.BackgroundColors [level];
System.Console.ForegroundColor = this._configuration.ForegroundColors [level];
System.Console.WriteLine (output);
System.Console.BackgroundColor = prevBackgroundColor;
System.Console.ForegroundColor = prevForegroundColor;
}
}
/// <summary>
/// Configure this <see cref="ConsoleChronicleLibrary"/> with the specified options.
/// </summary>
/// <param name="configurationDelegate">A function to set <see cref="ConsoleChronicleLibrary"/> configuration.</param>
/// <returns>This <see cref="ConsoleChronicleLibrary"/> instance.</returns>
public ConsoleChronicleLibrary Configure (ConsoleChronicleLibraryConfigurationDelegate configurationDelegate) {
configurationDelegate.Invoke (this._configuration);
return this;
}
private delegate string MethodHandler (ChronicleRecord record, params string [] parameters);
private delegate string KeyHandler (ChronicleRecord record);
#region Xml Serialization
/// <summary>
/// Required for XML serialization, this method offers no functionality.
/// </summary>
/// <returns>A null <see cref="XmlSchema"/>.</returns>
public XmlSchema GetSchema () => null;
/// <summary>
/// Populate configuration from XML via the specified <see cref="XmlReader" />.
/// </summary>
/// <param name="reader"><see cref="XmlReader" /> stream from the configuration file.</param>
/// <seealso cref="Core.NChronicle.ConfigureFrom(string, bool, int)"/>
public void ReadXml (XmlReader reader) => this._configuration.ReadXml (reader);
/// <summary>
/// Write configuration to XML via the specified <see cref="XmlWriter" />.
/// </summary>
/// <param name="writer"><see cref="XmlWriter" /> stream to the configuration file.</param>
/// <seealso cref="Core.NChronicle.SaveConfigurationTo(string)"/>
public void WriteXml (XmlWriter writer) => this._configuration.WriteXml (writer);
#endregion
}
}
\ No newline at end of file
using NChronicle.Console.Configuration;
namespace NChronicle.Console.Delegates {
/// <summary>
/// A function to set <see cref="ConsoleChronicleLibrary"/>.
/// </summary>
/// <param name="configuration">The <see cref="ConsoleChronicleLibrary"/> to configure.</param>
public delegate void ConsoleChronicleLibraryConfigurationDelegate (ConsoleChronicleLibraryConfiguration configuration);
}
\ No newline at end of file
# Namespaces
## Namespaces
&nbsp;<table><tr><th>Namespace</th><th>Description</th></tr><tr><td><a href="N_NChronicle_Console.md">NChronicle.Console</a></td><td></td></tr><tr><td><a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration</a></td><td></td></tr><tr><td><a href="N_NChronicle_Console_Delegates.md">NChronicle.Console.Delegates</a></td><td></td></tr><tr><td><a href="N_NChronicle_Console_Extensions.md">NChronicle.Console.Extensions</a></td><td></td></tr></table>&nbsp;
# ConsoleChronicleLibraryConfiguration.GetSchema Method
Required for XML serialization, this method offers no functionality.
**Namespace:**&nbsp;<a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration</a><br />**Assembly:**&nbsp;NChronicle.Console (in NChronicle.Console.dll) Version: 1.0.2.0 (1.0.2.0)
## Syntax
**C#**<br />
``` C#
public XmlSchema GetSchema()
```
**VB**<br />
``` VB
Public Function GetSchema As XmlSchema
```
**F#**<br />
``` F#
abstract GetSchema : unit -> XmlSchema
override GetSchema : unit -> XmlSchema
```
#### Return Value
Type: <a href="http://msdn2.microsoft.com/en-us/library/9ta3w88s" target="_blank">XmlSchema</a><br />A null <a href="http://msdn2.microsoft.com/en-us/library/9ta3w88s" target="_blank">XmlSchema</a>.
#### Implements
<a href="http://msdn2.microsoft.com/en-us/library/6f7z1347" target="_blank">IXmlSerializable.GetSchema()</a><br />
## See Also
#### Reference
<a href="T_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration.md">ConsoleChronicleLibraryConfiguration Class</a><br /><a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration Namespace</a><br />
# ConsoleChronicleLibraryConfiguration.Ignoring Method (ChronicleLevel[])
Ignore records of the specified *levels*.
**Namespace:**&nbsp;<a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration</a><br />**Assembly:**&nbsp;NChronicle.Console (in NChronicle.Console.dll) Version: 1.0.2.0 (1.0.2.0)
## Syntax
**C#**<br />
``` C#
public void Ignoring(
params ChronicleLevel[] levels
)
```
**VB**<br />
``` VB
Public Sub Ignoring (
ParamArray levels As ChronicleLevel()
)
```
**F#**<br />
``` F#
member Ignoring :
levels : ChronicleLevel[] -> unit
```
#### Parameters
&nbsp;<dl><dt>levels</dt><dd>Type: NChronicle.Core.Model.ChronicleLevel[]<br />ChronicleLevels to ignore records of.</dd></dl>
## Remarks
This can be invoked multiple times with further *levels* to ignore, therefore invoking Ignoring(ChronicleLevel[]) once with 3 ChronicleLevels and invoking Ignoring(ChronicleLevel[]) 3 times with each of the same ChronicleLevels is semantically synonymous. As an exception, as the default collection of record levels listened to are volatile, if the levels listened to are still their default, invoking Ignoring(ChronicleLevel[]) will clear these levels and ignore records only of those *levels* specified in that and future invocations. The default listened to levels are: CriticalWarningSuccessInfo
## See Also
#### Reference
<a href="T_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration.md">ConsoleChronicleLibraryConfiguration Class</a><br /><a href="Overload_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration_Ignoring.md">Ignoring Overload</a><br /><a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration Namespace</a><br /><a href="M_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration_ListeningTo.md">ConsoleChronicleLibraryConfiguration.ListeningTo(ChronicleLevel[])</a><br /><a href="M_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration_ListeningToAllLevels.md">ConsoleChronicleLibraryConfiguration.ListeningToAllLevels()</a><br /><a href="M_NChronicle_Console_Configuration_ConsoleChronicleLibraryConfiguration_NotListening.md">ConsoleChronicleLibraryConfiguration.NotListening()</a><br />
# ConsoleChronicleLibraryConfiguration.Ignoring Method (String[])
Ignore records with at least one of the specified *tags*.
**Namespace:**&nbsp;<a href="N_NChronicle_Console_Configuration.md">NChronicle.Console.Configuration</a><br />**Assembly:**&nbsp;NChronicle.Console (in NChronicle.Console.dll) Version: 1.0.2.0 (1.0.2.0)
## Syntax
**C#**<br />
``` C#
public void Ignoring(
params string[] tags
)
```
**VB**<br />
``` VB
Public Sub Ignoring (
ParamArray tags As String()
)
```
**F#**<br />
``` F#
member Ignoring :
tags : string[] -> unit
```
#### Parameters
&nbsp;<dl><dt>tags</dt><dd>Type: <a href="http://msdn2.microsoft.com/en-us/library/s1wwdcbf" target="_blank">System.String</a>[]<br />Tags to ignore records with.</dd></dl>
## Remarks
This can be invoked multiple times with further *tags* to ignore, therefore invoking Ignoring(String[]) once with 3 tags and invoking Ignoring(String[]) 3 times with each of the same tags is semantically synonymous.
## See Also