remove Logging.csproj

This commit is contained in:
ig 2023-02-23 16:01:35 +01:00
parent 95048e42d6
commit bce8d9486d
5 changed files with 0 additions and 200 deletions

View File

@ -1,24 +0,0 @@
using System.Text;
using InnovEnergy.Lib.Utils;
namespace InnovEnergy.Logging;
public static class Extensions
{
private const Char NewLine = '\n';
public static Byte[] Serialize(this Exception e)
{
return Encoding.UTF8.GetBytes(e.Message + NewLine + e);
}
public static (String title, String message) Deserialize(this IReadOnlyList<Byte> data)
{
var strData = data
.ToArray()
.Apply(Encoding.UTF8.GetString);
return (strData.UntilFirst(NewLine), strData.AfterFirst(NewLine));
}
}

View File

@ -1,39 +0,0 @@
using System.Net;
using System.Net.Sockets;
using InnovEnergy.Lib.Utils;
using InnovEnergy.Lib.Utils.Net;
namespace InnovEnergy.Logging;
public class Logger
{
private UdpClient UpdSocket { get; set; }
private IPEndPoint EndPoint { get; }
public Logger(IPEndPoint endPoint)
{
EndPoint = endPoint;
ResetUdpClient();
}
private void ResetUdpClient()
{
UpdSocket?.Dispose();
UpdSocket = new UdpClient();
}
public void Log<E>(E exception) where E : Exception
{
exception.Serialize()
.TryApply(SendDatagram)
.Catch(ErrorToStdOut);
}
private static Int32 ErrorToStdOut(Exception e)
{
Console.WriteLine(e.ToString());
return 0;
}
private Int32 SendDatagram(Byte[] bytes) => UpdSocket.SendDatagram(bytes, EndPoint);
}

View File

@ -1,13 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../InnovEnergy.app.props" />
<PropertyGroup>
<RootNamespace>InnovEnergy.Logging</RootNamespace>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="../../lib/Utils/Utils.csproj" />
</ItemGroup>
</Project>

View File

@ -1,108 +0,0 @@
using System.Net.Sockets;
using static InnovEnergy.Logging.Settings;
namespace InnovEnergy.Logging;
public static class Server
{
// TODO: notify about n skipped identical messages in last period
private static UdpClient _incomingSocket = new UdpClient(IncomingEndPoint); // TODO: directly use socket
public static void Main()
{
// Init();
//
// ImmediateScheduler.Instance
// .Repeat(ReceiveErrorMessage)
// .Do(LogReceived)
// .ThrottleDistinct(m => m.title, EmailSubjectThrottle)
// .Try(CreateMimeMessage)
// .ThenTry(SendMail)
// .Match(LogSent, LogError)
// .IgnoreErrors()
// .Subscribe();
//
// Console.WriteLine("Logging Server exited abnormally!");
}
// private static void Init()
// {
// "Logging Server started".Underline().Write();
//
// "Listening on " .Write(); IncomingEndPoint.WriteLine(Cyan);
// "Sending errors to " .Write(); Recipient.WriteLine(Cyan);
// "Throttling period is ".Write(); (EmailSubjectThrottle.TotalHours + "h").WriteLine(Cyan);
//
// TestMailServerConnection();
// }
//
// private static void TestMailServerConnection()
// {
// "Testing connection to mail server ".Write();
// SmtpServer.Host.Write(Cyan); ":".Write(Cyan); SmtpServer.Port.Write(Cyan);
// " ... ".Write();
//
// var errorMsg = Try(() => SendMail(null))
// .Catch(e => e.Message);
//
// if (errorMsg != null)
// {
// "FAILURE".WriteLine(Red);
// errorMsg.WriteLine(Red);
// "Logging Server stopped".WriteLine();
// Environment.Exit(2);
// }
//
// "success".WriteLine(Green);
// }
//
// private static void LogReceived((String title, String message) m) => Console.WriteLine("RECEIVED: " + m.title);
// private static void LogError(Exception ex) => Console.WriteLine("ERROR : " + ex);
// private static void LogSent(String msg) => Console.WriteLine("SENT : " + msg);
//
// private static MimeMessage CreateMimeMessage((String title, String message) m)
// {
// return new MimeMessage
// {
// Subject = m.title,
// Sender = SenderAddress,
// To = {RecipientAddress},
// Body = new TextPart(TextFormat.Plain) { Text = m.message }
// };
// }
//
// private static (String title, String message) ReceiveErrorMessage()
// {
// return Try(ReadDatagram) .OnError("META: Failed to read from socket")
// .ThenTry(Extensions.Deserialize) .OnError("META: Failed parse error datagram")
// .Catch(ResetSocket);
// }
//
// private static IReadOnlyList<Byte> ReadDatagram() => _incomingSocket.ReadDatagram().Payload;
//
//
// private static String SendMail(MimeMessage message)
// {
// using var smtp = new SmtpClient();
//
// smtp.Connect(SmtpServer.Host, SmtpServer.Port, false);
// smtp.Authenticate(SmtpUser, SmtpPassword);
//
// if (message != null) smtp.Send(message);
//
// smtp.Disconnect(true);
//
// return message?.Subject;
// }
//
// private static (String, String) ResetSocket(Exception e)
// {
// _incomingSocket.Dispose();
// _incomingSocket = new UdpClient(IncomingEndPoint);
//
// return (e.Message, e.ToString());
// }
}

View File

@ -1,16 +0,0 @@
using System.Net;
namespace InnovEnergy.Logging;
internal static class Settings
{
public static readonly IPEndPoint IncomingEndPoint = IPEndPoint.Parse("127.0.0.1:6030");
public static readonly DnsEndPoint SmtpServer = new DnsEndPoint("smtp.friends.com", 587) ;
public static readonly String Sender = "log@innov.energy";
public static readonly String Recipient = Sender;
public static readonly String SmtpUser = Sender;
public static readonly String SmtpPassword = "xxxx";
public static readonly TimeSpan EmailSubjectThrottle = TimeSpan.FromDays(1);
}