From bce8d9486d94c03c436ac45c1f765edb7ff212c5 Mon Sep 17 00:00:00 2001 From: ig Date: Thu, 23 Feb 2023 16:01:35 +0100 Subject: [PATCH] remove Logging.csproj --- csharp/app/Logging/Extensions.cs | 24 ------- csharp/app/Logging/Logger.cs | 39 ----------- csharp/app/Logging/Logging.csproj | 13 ---- csharp/app/Logging/Server.cs | 108 ------------------------------ csharp/app/Logging/Settings.cs | 16 ----- 5 files changed, 200 deletions(-) delete mode 100644 csharp/app/Logging/Extensions.cs delete mode 100644 csharp/app/Logging/Logger.cs delete mode 100644 csharp/app/Logging/Logging.csproj delete mode 100644 csharp/app/Logging/Server.cs delete mode 100644 csharp/app/Logging/Settings.cs diff --git a/csharp/app/Logging/Extensions.cs b/csharp/app/Logging/Extensions.cs deleted file mode 100644 index 11a48f767..000000000 --- a/csharp/app/Logging/Extensions.cs +++ /dev/null @@ -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 data) - { - var strData = data - .ToArray() - .Apply(Encoding.UTF8.GetString); - - return (strData.UntilFirst(NewLine), strData.AfterFirst(NewLine)); - } - -} \ No newline at end of file diff --git a/csharp/app/Logging/Logger.cs b/csharp/app/Logging/Logger.cs deleted file mode 100644 index c3a16be68..000000000 --- a/csharp/app/Logging/Logger.cs +++ /dev/null @@ -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 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); -} \ No newline at end of file diff --git a/csharp/app/Logging/Logging.csproj b/csharp/app/Logging/Logging.csproj deleted file mode 100644 index 97e97480a..000000000 --- a/csharp/app/Logging/Logging.csproj +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - InnovEnergy.Logging - - - - - - - diff --git a/csharp/app/Logging/Server.cs b/csharp/app/Logging/Server.cs deleted file mode 100644 index fd60cd547..000000000 --- a/csharp/app/Logging/Server.cs +++ /dev/null @@ -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 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()); - // } -} \ No newline at end of file diff --git a/csharp/app/Logging/Settings.cs b/csharp/app/Logging/Settings.cs deleted file mode 100644 index ba8cf1793..000000000 --- a/csharp/app/Logging/Settings.cs +++ /dev/null @@ -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); -} \ No newline at end of file