From 8b75149950b147db8af9f812ad7210592b84e9e5 Mon Sep 17 00:00:00 2001 From: Rene Evertz Date: Mon, 18 Nov 2024 11:48:14 +0100 Subject: [PATCH] =?UTF-8?q?Utils=20SendMail=20bisschen=20umgeschrieben,=20?= =?UTF-8?q?UnitTest=20f=C3=BCr=20Mail=20send,=20GkvServerGetStatusRequest?= =?UTF-8?q?=20Error=20Mail=20Einbindung?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DakotaUnitTest/DakotaReaderUnitTest.cs | 2 +- DakotaUnitTest/MailUnitTest.cs | 7 +- Host/Web.config | 2 +- Service/Core/Utils.cs | 491 ++++++++++-------- .../AccountingServiceImp.cs | 2 +- 5 files changed, 276 insertions(+), 228 deletions(-) diff --git a/DakotaUnitTest/DakotaReaderUnitTest.cs b/DakotaUnitTest/DakotaReaderUnitTest.cs index 083f77c35..a8dae64fd 100644 --- a/DakotaUnitTest/DakotaReaderUnitTest.cs +++ b/DakotaUnitTest/DakotaReaderUnitTest.cs @@ -38,7 +38,7 @@ namespace DakotaUnitTest { var count = Reader.GetAllFileEntryCount(); - Assert.IsTrue(count == 1105); + Assert.IsTrue(count == 1106); } [TestMethod] diff --git a/DakotaUnitTest/MailUnitTest.cs b/DakotaUnitTest/MailUnitTest.cs index f5061b4a1..b5ad8a9c5 100644 --- a/DakotaUnitTest/MailUnitTest.cs +++ b/DakotaUnitTest/MailUnitTest.cs @@ -10,9 +10,12 @@ namespace DakotaUnitTest [TestMethod] public void SendTestMail() { - var subject = ""; + var title = "TEST - UNITTEST"; + var body = "TEST - BODY"; - //var success = Utils.SendMail(subject, body, sende) + var success = Utils.SendDakotaErrorMail(title, body); + + Assert.IsTrue(success); } } } diff --git a/Host/Web.config b/Host/Web.config index 5f53a6506..6bb37fb5e 100644 --- a/Host/Web.config +++ b/Host/Web.config @@ -216,7 +216,7 @@ - + diff --git a/Service/Core/Utils.cs b/Service/Core/Utils.cs index 4b85928db..77620e6f0 100644 --- a/Service/Core/Utils.cs +++ b/Service/Core/Utils.cs @@ -21,132 +21,177 @@ using BS.Shared.Extensions; namespace BeWo.Service.Core { - public class Utils - { - private static readonly Regex indexRegex = new Regex("(?:Index=\"){1}([0-9]+)\"{1}"); - private static readonly Regex idRegex = new Regex("(?:Id=\")(([a-z0-9]{8})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{12}))(?=\"{1})"); + public class Utils + { + private static readonly Regex indexRegex = new Regex("(?:Index=\"){1}([0-9]+)\"{1}"); + private static readonly Regex idRegex = new Regex("(?:Id=\")(([a-z0-9]{8})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{4})-{1}([a-z0-9]{12}))(?=\"{1})"); - public static FaultException CreateBeWoFaultException(Exception ex) - { - try - { - //SendErrorMail("MYSQL EXCEPTION - AUTOMATED MAIL NOTIFICATION", ex.ToString()); - } - catch - { - } + private static readonly string _GKV_Module_Name = "GKV/EDI"; - return new FaultException(new BeWoFault(ex), ex.ToString()); - } - - public static string GetClientIP() - { - if (OperationContext.Current != null) - { - MessageProperties properties = OperationContext.Current.IncomingMessageProperties; - var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; - return endpoint.Address; - } - return null; - } - - public static string GetMD5(string val) - { - var lMD5 = new MD5CryptoServiceProvider(); - string lHash = BitConverter.ToString(lMD5.ComputeHash(Encoding.UTF8.GetBytes(val))); - return lHash; - } - - public static string GetSHA256(string val) - { - var csp = new SHA256CryptoServiceProvider(); - string lHash = BitConverter.ToString(csp.ComputeHash(Encoding.UTF8.GetBytes(val))); - return lHash; - } - - public static bool IsValidEmail(string email) - { - //return Regex.IsMatch(email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); - - return Regex.IsMatch(email, - @"^(?("")("".+?(? _Module2Email = new Dictionary() { - var server = ConfigurationManager.AppSettings.Get("SmptServer"); - var user = ConfigurationManager.AppSettings.Get("SmtpUser"); - //var pass = ConfigurationManager.AppSettings.Get("SmtpPassword"); - var pass = "JJVjJntw2yaRDAxInotF"; - String to = toAddress; - if (String.IsNullOrEmpty(to)) + { _GKV_Module_Name, "dakota.exchange@ownsoft.de"} + }; + + public static FaultException CreateBeWoFaultException(Exception ex) + { + try + { + //SendErrorMail("MYSQL EXCEPTION - AUTOMATED MAIL NOTIFICATION", ex.ToString()); + } + catch + { + } + + return new FaultException(new BeWoFault(ex), ex.ToString()); + } + + public static string GetClientIP() + { + if (OperationContext.Current != null) + { + MessageProperties properties = OperationContext.Current.IncomingMessageProperties; + var endpoint = properties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty; + return endpoint.Address; + } + return null; + } + + public static string GetMD5(string val) + { + var lMD5 = new MD5CryptoServiceProvider(); + string lHash = BitConverter.ToString(lMD5.ComputeHash(Encoding.UTF8.GetBytes(val))); + return lHash; + } + + public static string GetSHA256(string val) + { + var csp = new SHA256CryptoServiceProvider(); + string lHash = BitConverter.ToString(csp.ComputeHash(Encoding.UTF8.GetBytes(val))); + return lHash; + } + + public static bool IsValidEmail(string email) + { + //return Regex.IsMatch(email, @"^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"); + + return Regex.IsMatch(email, + @"^(?("")("".+?(? pSearchParameter, int pSearchFieldCount) - { - //List lDifferentParameter; + public static string[][] T(List pSearchParameter, int pSearchFieldCount) + { + //List lDifferentParameter; - return null; - } + return null; + } public static string GetRecurringAppointmentsId(SchedulerAppointment appointment) { @@ -232,102 +277,102 @@ namespace BeWo.Service.Core } - public static bool UserHasRight(ApplicationUser user, UserRightType right) - { - return GetGrantedRights(user).Contains(right); + public static bool UserHasRight(ApplicationUser user, UserRightType right) + { + return GetGrantedRights(user).Contains(right); - } + } - public static List GetGrantedRights(ApplicationUser user) - { - var rights = new List(); - foreach (var ug in user.UserGroups) - { - foreach (var rr in ug.Rights) - { - rights.Add(rr.RightType); - } - } + public static List GetGrantedRights(ApplicationUser user) + { + var rights = new List(); + foreach (var ug in user.UserGroups) + { + foreach (var rr in ug.Rights) + { + rights.Add(rr.RightType); + } + } - return rights; - } + return rights; + } - public static string GetRecurrenceIdFromRecurrenceInfo(string pRecurrenceInfo) - { - var regex = new Regex("(Id=\\\"[a-z0-9-]+\\\")"); + public static string GetRecurrenceIdFromRecurrenceInfo(string pRecurrenceInfo) + { + var regex = new Regex("(Id=\\\"[a-z0-9-]+\\\")"); - var match = regex.Match(pRecurrenceInfo); - if(match.Success) - { - var value = match.Value; - var actualId = value.Split("\""); - if(actualId.Count > 1) - { - return actualId[1]; - } - } + var match = regex.Match(pRecurrenceInfo); + if (match.Success) + { + var value = match.Value; + var actualId = value.Split("\""); + if (actualId.Count > 1) + { + return actualId[1]; + } + } - return null; - } + return null; + } - public static string GetRecurrenceIndexFromRecurrenceInfo(string pRecurrenceInfo) - { - if(!pRecurrenceInfo.Contains("Index")) - { - return null; - } + public static string GetRecurrenceIndexFromRecurrenceInfo(string pRecurrenceInfo) + { + if (!pRecurrenceInfo.Contains("Index")) + { + return null; + } - var regex = new Regex("(Index=\\\"\\d+\\\")"); + var regex = new Regex("(Index=\\\"\\d+\\\")"); - var match = regex.Match(pRecurrenceInfo); - if(match.Success) - { - var value = match.Value; - var actualIndex = value.Split("\""); + var match = regex.Match(pRecurrenceInfo); + if (match.Success) + { + var value = match.Value; + var actualIndex = value.Split("\""); - if(actualIndex.Count > 1) - { - return actualIndex[1]; - } - } + if (actualIndex.Count > 1) + { + return actualIndex[1]; + } + } - return null; - } + return null; + } - public static List ExtractRecurrenceIdFromRecurrenceString(List appointments) - { - var result = new List(); + public static List ExtractRecurrenceIdFromRecurrenceString(List appointments) + { + var result = new List(); - foreach(var recurrenceInfo in appointments.Where(w => w.RecurrenceInfo != null).Select(s => s.RecurrenceInfo)) - { - var id = GetRecurrenceIdFromRecurrenceInfo(recurrenceInfo); + foreach (var recurrenceInfo in appointments.Where(w => w.RecurrenceInfo != null).Select(s => s.RecurrenceInfo)) + { + var id = GetRecurrenceIdFromRecurrenceInfo(recurrenceInfo); - if(id != null) - { - result.AddIfNotIn(id); - } - } - - return result; - } + if (id != null) + { + result.AddIfNotIn(id); + } + } - public static string ExtractIdFromRecurrenceInfo(string pRecurrenceInfo) - { - return pRecurrenceInfo != null ? idRegex.Match(pRecurrenceInfo).Groups[1].Value : null; - } + return result; + } - public static int ExtractIndexFromRecurrenceInfo(string pRecurrenceInfo) - { - if (pRecurrenceInfo != null) - { - var indexString = indexRegex.Match(pRecurrenceInfo).Groups[1].Value; + public static string ExtractIdFromRecurrenceInfo(string pRecurrenceInfo) + { + return pRecurrenceInfo != null ? idRegex.Match(pRecurrenceInfo).Groups[1].Value : null; + } - var index = !string.IsNullOrEmpty(indexString) ? int.Parse(indexString) : 0; + public static int ExtractIndexFromRecurrenceInfo(string pRecurrenceInfo) + { + if (pRecurrenceInfo != null) + { + var indexString = indexRegex.Match(pRecurrenceInfo).Groups[1].Value; - return index; - } + var index = !string.IsNullOrEmpty(indexString) ? int.Parse(indexString) : 0; - return -1; - } - } + return index; + } + + return -1; + } + } } \ No newline at end of file diff --git a/Service/ServiceImplementations/AccountingServiceImp.cs b/Service/ServiceImplementations/AccountingServiceImp.cs index ea58330f3..63823d9ee 100644 --- a/Service/ServiceImplementations/AccountingServiceImp.cs +++ b/Service/ServiceImplementations/AccountingServiceImp.cs @@ -1195,7 +1195,7 @@ namespace BeWo.Service.ServiceImplementations } catch (Exception e) { - throw e; + Utils.SendDakotaErrorMail("GkvServerGetStatusRequest Error", e); return true; }