Skip to content

Commit

Permalink
Draft versions Varhead and LSender projects (netstd2.0 + net40). Part…
Browse files Browse the repository at this point in the history
… of #55

Updated tests. Also PascalCasing due to crazy .net convention, ie. IDE1006
  • Loading branch information
3F committed Aug 21, 2019
1 parent 7904b38 commit d57b917
Show file tree
Hide file tree
Showing 64 changed files with 2,260 additions and 1,179 deletions.
86 changes: 86 additions & 0 deletions LSender/ISender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2019 Denis Kuzmin < x-3F@outlook.com > GitHub/3F
* Copyright (c) LSender contributors: https://github.com/3F/LSender/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace net.r_eg.Components
{
public interface ISender
{
/// <summary>
/// When message is raised.
/// </summary>
event EventHandler<Message> Raised;

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
void Raise(object sender, Message msg);

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
void Raise(object sender, string msg);

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
/// <param name="level"></param>
void Raise(object sender, string msg, MsgLevel level);

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
void Raise<T>(Message msg);

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
void Raise<T>(string msg);

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
/// <param name="level"></param>
void Raise<T>(string msg, MsgLevel level);

/// <summary>
/// Revokes subscription for all listeners.
/// </summary>
void Revoke();
}
}
162 changes: 162 additions & 0 deletions LSender/LSender.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2019 Denis Kuzmin < x-3F@outlook.com > GitHub/3F
* Copyright (c) LSender contributors: https://github.com/3F/LSender/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace net.r_eg.Components
{
/// <summary>
/// Ascetic aggregative repeater for loggers etc.
/// </summary>
public sealed class LSender: ISender
{
private static readonly Lazy<ISender> _lazy = new Lazy<ISender>(() => new LSender());

/// <summary>
/// Thread-safe getting the instance of the LSender class.
/// </summary>
public static ISender _ => _lazy.Value;

/// <summary>
/// When message is raised.
/// </summary>
public event EventHandler<Message> Raised;

/// <summary>
/// When the message was sent. Static alias.
/// </summary>
public static event EventHandler<Message> Sent
{
add => _.Raised += value;
remove => _.Raised -= value;
}

/// <summary>
/// Static alias for raising new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
public static void Send(object sender, Message msg) => _.Raise(sender, msg);

/// <summary>
/// Static alias for raising new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
public static void Send(object sender, string msg) => _.Raise(sender, msg);

/// <summary>
/// Static alias for raising new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
/// <param name="level"></param>
public static void Send(object sender, string msg, MsgLevel level)
=> _.Raise(sender, msg, level);

/// <summary>
/// To send new message with default sender as typeof(T).
/// Useful for static methods etc.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
public static void Send<T>(Message msg) => _.Raise<T>(msg);

/// <summary>
/// To send new message with default sender as typeof(T).
/// Useful for static methods etc.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
public static void Send<T>(string msg) => _.Raise<T>(msg);

/// <summary>
/// To send new message with default sender as typeof(T).
/// Useful for static methods etc.
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
/// <param name="level"></param>
public static void Send<T>(string msg, MsgLevel level) => _.Raise<T>(msg, level);

/// <summary>
/// Resets listeners. Static alias to revoke.
/// </summary>
public static void Reset() => _.Revoke();

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
public void Raise(object sender, Message msg) => Raised(sender ?? this, msg);

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
public void Raise(object sender, string msg)
=> Raise(sender, msg, MsgLevel.Debug);

/// <summary>
/// Raises new message.
/// </summary>
/// <param name="sender"></param>
/// <param name="msg"></param>
/// <param name="level"></param>
public void Raise(object sender, string msg, MsgLevel level)
=> Raise(sender, new Message(msg, level));

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
public void Raise<T>(Message msg) => Raise(typeof(T), msg);

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
public void Raise<T>(string msg) => Raise(typeof(T), msg);

/// <summary>
/// Raises new message with default sender as typeof(T).
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="msg"></param>
/// <param name="level"></param>
public void Raise<T>(string msg, MsgLevel level) => Raise(typeof(T), msg, level);

/// <summary>
/// Revokes subscription for all listeners.
/// </summary>
public void Revoke() => Raised = delegate (object sender, Message msg) { };

private LSender() => Revoke();
}
}
47 changes: 47 additions & 0 deletions LSender/LSender.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Version>0.0.1.0</Version>
<!-- <AssemblyVersion>0.0.1.0</AssemblyVersion> -->
<!-- <FileVersion>0.0.1.0</FileVersion> -->
</PropertyGroup>

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net40</TargetFrameworks>
<RootNamespace>net.r_eg.LSender</RootNamespace>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Copyright>Copyright (c) 2013-2019 Denis Kuzmin &lt; x-3F@outlook.com &gt; GitHub/3F</Copyright>
<PackageTitle>[ LSender ] Ascetic aggregative repeater for loggers etc.</PackageTitle>
<Title>[ LSender ] Ascetic aggregative repeater for loggers etc.</Title>
<Description>Ascetic aggregative repeater for loggers etc.</Description>
<PackageOwners>reg</PackageOwners>
<PackageProjectUrl>https://github.com/3F/LSender</PackageProjectUrl>
<RepositoryUrl>https://github.com/3F/LSender</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>repeater aggregation log logger SobaScript E-MSBuild vsSBE SBE-Scripts LSender</PackageTags>
<PackageReleaseNotes>https://github.com/3F/LSender/blob/master/changelog.txt</PackageReleaseNotes>
<Authors>github.com/3F/LSender</Authors>
<DocumentationFile>$(OutputPath)\$(AssemblyName).xml</DocumentationFile>
<PackageLicenseFile>License.txt</PackageLicenseFile>
<Configurations>DBG_SDK10;DBG_SDK15;REL_SDK10;REL_SDK15;DCI_SDK10;DCI_SDK15;RCI_SDK10;RCI_SDK15</Configurations>
<NoWarn>1701;1702;CS1591</NoWarn>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Debug' Or $(Configuration.Contains('DBG_')) Or $(Configuration.Contains('DCI_')) ">
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' Or $(Configuration.Contains('REL_')) Or $(Configuration.Contains('RCI_')) ">
<DefineConstants />
</PropertyGroup>

<ItemGroup>
<None Include="License.txt">
<Pack>True</Pack>
<PackagePath></PackagePath>
</None>
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions LSender/License.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2016-2019 Denis Kuzmin < x-3F@outlook.com > GitHub/3F
Copyright (c) LSender contributors: https://github.com/3F/LSender/graphs/contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
62 changes: 62 additions & 0 deletions LSender/Message.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2019 Denis Kuzmin < x-3F@outlook.com > GitHub/3F
* Copyright (c) LSender contributors: https://github.com/3F/LSender/graphs/contributors
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/

using System;

namespace net.r_eg.Components
{
[Serializable]
public class Message: EventArgs
{
public DateTime stamp;

public string content;

public Exception exception;

public object data;

public MsgLevel level;

public Message(string msg, MsgLevel level = MsgLevel.Debug)
{
content = msg;
this.level = level;
stamp = DateTime.Now;
}

public Message(string msg, Exception ex, MsgLevel type = MsgLevel.Error)
: this(msg, type)
{
exception = ex;
}

public Message(string msg, object data, MsgLevel type = MsgLevel.Debug)
: this(msg, type)
{
this.data = data;
}
}
}
Loading

0 comments on commit d57b917

Please sign in to comment.