From 0820bbdae9a7b3c0aa36b3d231dd40c9e6c92d01 Mon Sep 17 00:00:00 2001 From: Christian Date: Mon, 25 Sep 2023 19:03:08 +0200 Subject: [PATCH] =?UTF-8?q?Laden=20der=20Kunden=20Dlls=20im=20PluginLoader?= =?UTF-8?q?=20=C3=BCberarbeitet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + Host/ReportView.aspx.cs | 27 +-- Host/Web.config | 4 + Report/AbstractReportCreator.cs | 4 - Report/DefaultReportCreator.cs | 9 +- ReportImp/AkggMid/AkggMid.csproj | 4 +- ReportImp/BeWoDarmstadt/Zeitzuschlagsbeleg.cs | 7 +- .../IlkaLinkAmbulanteHilfen.csproj | 4 +- ReportImp/SHKServiceSBD/SHKServiceSBD.csproj | 4 +- .../Plugins/TimeSheetReportService.cs | 8 +- .../ReportServiceImp.cs | 81 +-------- Service/Core/ServiceLogic.cs | 72 -------- Service/Plugins/PluginLoader.cs | 163 +++++++++++++++--- Shared/Services/Calculations.cs | 7 +- 14 files changed, 170 insertions(+), 225 deletions(-) diff --git a/.gitignore b/.gitignore index 8a7c25cb1..833e7afab 100644 --- a/.gitignore +++ b/.gitignore @@ -650,3 +650,4 @@ obj /ReportImp/Lazy/Properties/licenses.licx /TestReportCustomization/Class1.cs /TestReportCustomization/TestReportCustomization.csproj +/CustomerDlls diff --git a/Host/ReportView.aspx.cs b/Host/ReportView.aspx.cs index e1ba9552f..f93deea8f 100644 --- a/Host/ReportView.aspx.cs +++ b/Host/ReportView.aspx.cs @@ -936,36 +936,15 @@ namespace Host } String t = slicedToken["tenant"].ToString(); - AbstractReportCreator creator = null; -#if DEBUG + SessionFacade.Tenant = t; - - //Kundennummern zum Testen nur noch in PluginLoader eintragen: - t = PluginLoader.Tenant; + AbstractReportCreator creator = PluginLoader.FindClass(); - String customerDllPath = HttpContext.Current.Server.MapPath(@"bin\" + t + "_reports.dll"); -#else - String customerDllPath = HttpContext.Current.Server.MapPath(@"Customer\" + t + "_reports.dll"); -#endif - if (File.Exists(customerDllPath)) - { - var allTypes = Assembly.LoadFrom(customerDllPath).GetTypes(); - - var reportCreator = allTypes.FirstOrDefault(i => typeof(AbstractReportCreator).IsAssignableFrom(i)); - if (reportCreator != null) - { - creator = Activator.CreateInstance(reportCreator) as AbstractReportCreator; - } - - } - if (creator == null) creator = new DefaultReportCreator(); creator.TemplateOid = templateOid; - creator.Tenant = t; - creator.ReportPath = customerDllPath; - + #if DEBUG creator.TempPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, @"demo\temp"); #else diff --git a/Host/Web.config b/Host/Web.config index 8a991ae7e..dea884486 100644 --- a/Host/Web.config +++ b/Host/Web.config @@ -219,6 +219,10 @@ + + + + diff --git a/Report/AbstractReportCreator.cs b/Report/AbstractReportCreator.cs index ae0c7362c..0a9b7c7a1 100644 --- a/Report/AbstractReportCreator.cs +++ b/Report/AbstractReportCreator.cs @@ -9,10 +9,6 @@ namespace BeWo.Report { public abstract class AbstractReportCreator { - public String Tenant { get; set; } - - public string ReportPath { get; set; } - public string TempPath { get; set; } public long? TemplateOid { get; set; } diff --git a/Report/DefaultReportCreator.cs b/Report/DefaultReportCreator.cs index 6c8e4a5b2..725ce9101 100644 --- a/Report/DefaultReportCreator.cs +++ b/Report/DefaultReportCreator.cs @@ -50,13 +50,10 @@ namespace BeWo.Report } } Type[] lAllReportTypes = null; - var fullPath = Path.GetFullPath(ReportPath); - if (Tenant != null && File.Exists(ReportPath)) - { - lAllReportTypes = Assembly.LoadFrom(ReportPath).GetTypes(); - result = FindReportImp(lAllReportTypes, specificReportId, typename, true); - } + lAllReportTypes = PluginLoader.GetAllCustomerTypes(); + result = FindReportImp(lAllReportTypes, specificReportId, typename, true); + if (result == null) { diff --git a/ReportImp/AkggMid/AkggMid.csproj b/ReportImp/AkggMid/AkggMid.csproj index df1804af5..60c5ff0ec 100644 --- a/ReportImp/AkggMid/AkggMid.csproj +++ b/ReportImp/AkggMid/AkggMid.csproj @@ -17,7 +17,7 @@ true full false - ..\..\Host\bin\ + ..\..\CustomerDlls\ DEBUG;TRACE prompt 4 @@ -25,7 +25,7 @@ pdbonly true - ..\..\Host\bin\ + ..\..\CustomerDlls\ TRACE prompt 4 diff --git a/ReportImp/BeWoDarmstadt/Zeitzuschlagsbeleg.cs b/ReportImp/BeWoDarmstadt/Zeitzuschlagsbeleg.cs index 3162d2e83..bacb7c27e 100644 --- a/ReportImp/BeWoDarmstadt/Zeitzuschlagsbeleg.cs +++ b/ReportImp/BeWoDarmstadt/Zeitzuschlagsbeleg.cs @@ -306,7 +306,6 @@ namespace BeWoDarmstadt { AddValueToCell(zs.MinutenNachtSo21_6, datum, table1.Rows[7], nachtSo2Minuten); } - } private void AddValueToTableLeistungen(ServiceRecord sr) @@ -470,6 +469,10 @@ namespace BeWoDarmstadt private double CheckUhrzeiten(DateTime start, int startStunde, int endStunde, double minuten) { + if (startStunde > 0 && start.Hour == 0 && start.Minute == 0 && start.Second > 0) + { + return 0; + } if (startStunde > endStunde) //Nachts { DateTime nachtStartDt = start.Date.AddHours(startStunde); @@ -485,7 +488,7 @@ namespace BeWoDarmstadt return minutes; } else - { + { DateTime tagsStartDt = start.Date.AddHours(startStunde); DateTime tagsEndDt = start.Date.AddHours(endStunde); DateTime dtEnd = start.AddMinutes(minuten); diff --git a/ReportImp/IlkaLinkAmbulanteHilfen/IlkaLinkAmbulanteHilfen.csproj b/ReportImp/IlkaLinkAmbulanteHilfen/IlkaLinkAmbulanteHilfen.csproj index 7b346e627..0bb5eebe2 100644 --- a/ReportImp/IlkaLinkAmbulanteHilfen/IlkaLinkAmbulanteHilfen.csproj +++ b/ReportImp/IlkaLinkAmbulanteHilfen/IlkaLinkAmbulanteHilfen.csproj @@ -17,7 +17,7 @@ true full false - ..\..\Host\bin\ + ..\..\CustomerDlls\ DEBUG;TRACE prompt 4 @@ -25,7 +25,7 @@ pdbonly true - ..\..\Host\bin\ + ..\..\CustomerDlls\ TRACE prompt 4 diff --git a/ReportImp/SHKServiceSBD/SHKServiceSBD.csproj b/ReportImp/SHKServiceSBD/SHKServiceSBD.csproj index 3ee0f3667..9537d09f8 100644 --- a/ReportImp/SHKServiceSBD/SHKServiceSBD.csproj +++ b/ReportImp/SHKServiceSBD/SHKServiceSBD.csproj @@ -17,7 +17,7 @@ true full false - ..\..\Host\bin\ + ..\..\CustomerDlls\ DEBUG;TRACE prompt 4 @@ -25,7 +25,7 @@ pdbonly true - ..\..\Host\bin\ + ..\..\CustomerDlls\ TRACE prompt 4 diff --git a/ReportService/Plugins/TimeSheetReportService.cs b/ReportService/Plugins/TimeSheetReportService.cs index aad34c829..d1f1f2f7f 100644 --- a/ReportService/Plugins/TimeSheetReportService.cs +++ b/ReportService/Plugins/TimeSheetReportService.cs @@ -56,13 +56,7 @@ namespace ReportingService.Plugins private static DefaultReportCreator CreateReportCreator() { var reportCreator = PluginLoader.FindClass(); - reportCreator.Tenant = PluginLoader.Tenant; - -#if DEBUG - reportCreator.ReportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + PluginLoader.Tenant + "_reports.dll"); -#else - reportCreator.ReportPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Customer\" + PluginLoader.Tenant + "_reports.dll"); -#endif + return reportCreator; } } diff --git a/ReportService/ServiceImplementations/ReportServiceImp.cs b/ReportService/ServiceImplementations/ReportServiceImp.cs index f0b794bd2..4494fbba6 100644 --- a/ReportService/ServiceImplementations/ReportServiceImp.cs +++ b/ReportService/ServiceImplementations/ReportServiceImp.cs @@ -175,92 +175,19 @@ namespace ReportingService.ServiceImplementations private static AbstractReportCreator GetReportCreator() { - var derTenant = MultitenancyOperationContextExt.Current.Tenant; - AbstractReportCreator creator = null; -#if DEBUG - //Kundennummern zum Testen nur noch in PluginLoader eintragen: - derTenant = PluginLoader.Tenant; - - - var customerDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + derTenant + "_reports.dll"); -#else - var customerDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Customer\" + derTenant + "_reports.dll"); -#endif - if (File.Exists(customerDllPath)) - { - var allTypes = Assembly.LoadFrom(customerDllPath).GetTypes(); - - var reportCreator = allTypes.FirstOrDefault(i => typeof(AbstractReportCreator).IsAssignableFrom(i)); - if (reportCreator != null) - { - creator = Activator.CreateInstance(reportCreator) as AbstractReportCreator; - } - - } - - if (creator == null) - creator = new DefaultReportCreator(); - - creator.Tenant = derTenant; - creator.ReportPath = customerDllPath; + AbstractReportCreator creator = PluginLoader.FindClass(); #if DEBUG creator.TempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"demo\temp"); #else - creator.TempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, derTenant + @"\temp"); + creator.TempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, PluginLoader.Tenant + @"\temp"); #endif return creator; } - private static AbstractReportCreator GetReportCreator(string tenant) - { - AbstractReportCreator creator = null; -#if DEBUG - //Kundennummern zum Testen nur noch in PluginLoader eintragen: - tenant = PluginLoader.Tenant; - - // Ist "C:\Users\lyndo\BeWo\BeWoPlanerMobil\bin\2387527289_reports.dll" - // statt "C:\Users\lyndo\BeWo\Host\bin\2387527289_reports.dll" - - var path = @"..\Host\"; - - var customerDllPath = Path.Combine(path, @"bin\" + tenant + "_reports.dll");// Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + tenant + "_reports.dll"); -#else - var customerDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Customer\" + tenant + "_reports.dll"); -#endif - if (File.Exists(customerDllPath)) - { - var allTypes = Assembly.LoadFrom(customerDllPath).GetTypes(); - - var reportCreator = allTypes.FirstOrDefault(i => typeof(AbstractReportCreator).IsAssignableFrom(i)); - if (reportCreator != null) - { - creator = Activator.CreateInstance(reportCreator) as AbstractReportCreator; - } - - } - - if (creator == null) - { - creator = new DefaultReportCreator(); - } - - creator.Tenant = tenant; - creator.ReportPath = customerDllPath; - -#if DEBUG - creator.TempPath = Path.Combine(path, @"demo\temp"); -#else - - creator.TempPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, tenant + @"\temp"); -#endif - - return creator; - } - private static BeWoEntityBase LoadToBargeldkasseRelatedObject(TableID pObjectTid, long pObjectOid) { switch (pObjectTid) @@ -316,7 +243,7 @@ namespace ReportingService.ServiceImplementations // Zum Test im MoK public MemoryStream CreateKilometerauswertungForAllCustomersForWebVersion(List customerOids, DateTime rangeDate, string tenant) { - var reportCreator = GetReportCreator(tenant); + var reportCreator = GetReportCreator(); var report = reportCreator.CreateKilometerauswertungForAllCustomers(customerOids, null, new DateTime(rangeDate.Year, rangeDate.Month, 1), new DateTime(rangeDate.Year, rangeDate.Month, 1).AddMonths(1).AddDays(-1)); @@ -325,7 +252,7 @@ namespace ReportingService.ServiceImplementations public MemoryStream CreateMedikamentenlistenReport(long mvlOid, string tenant) { - var reportCreator = GetReportCreator(tenant); + var reportCreator = GetReportCreator(); var report = reportCreator.CreateMediVerordListenReport(mvlOid); diff --git a/Service/Core/ServiceLogic.cs b/Service/Core/ServiceLogic.cs index 6afbed10f..ff645de20 100644 --- a/Service/Core/ServiceLogic.cs +++ b/Service/Core/ServiceLogic.cs @@ -26,78 +26,6 @@ namespace BeWo.Service.Core return true; } - //public static ICostBearerCalc GetCalcualtionsObjectForCostBearer(long pCostBearerOid) - //{ - // var cb = DAOFactory.GenericDAO.LoadByID(pCostBearerOid); - - // if (!string.IsNullOrEmpty(cb.CalculationsDllName)) - // { - // Type[] calcTypes = new Type[0]; - - // string customReportDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + cb.CalculationsDllName); - // if (File.Exists(customReportDllPath)) - // { - // calcTypes = Assembly.LoadFrom(customReportDllPath).GetTypes(); - - // foreach (var iType in calcTypes) - // { - // if (typeof(ICostBearerCalc).IsAssignableFrom(iType)) - // { - // return Activator.CreateInstance(iType) as ICostBearerCalc; - // } - // } - // } - // } - - // return new InvoiceCreation(); - //} - - //public static List GetCostRateListForCostBearer(CostBearer costBearer) - //{ - // List list = new List(); - - // if (costBearer != null && costBearer.CostRatePeriods != null) - // { - // foreach (CostRatePeriod crp in costBearer.CostRatePeriods) - // { - // CostRate cr = new CostRate(); - // cr.Amount = crp.CostRateValue; - // switch (crp.CostRateType) - // { - // case CostRatePeriodType.HourlyRate: - // cr.CostRateType = CostRateType.HourlyRate; - // break; - // case CostRatePeriodType.MinutesIntervall: - // cr.CostRateType = CostRateType.MinutesIntervall; - // break; - // case CostRatePeriodType.RateFactor: - // cr.CostRateType = CostRateType.RateFactor; - // break; - // } - - // cr.StartDate = crp.StartDate; - // cr.EndDate = crp.EndDate; - - // list.Add(cr); - // } - // } - - // return list; - //} - - - //public static string GetNextInvoiceNumber(int increment, InvoiceBase invoiceBase) - //{ - // string next = String.Empty; - // InvoiceNumberDC invoiceNumber = new AccountingServiceImp().LoadInvoiceNumber(); - - // if (invoiceNumber != null && invoiceNumber.Use) - // { - // next = ApplyPattern(invoiceNumber.Pattern, invoiceNumber.CurrentNumber + increment, invoiceBase); - // } - // return next; - //} - public static void SetActivationType(Dictionary pOid2Version, ActivationTypeId activationType) where T : BeWoEntityBase, new() diff --git a/Service/Plugins/PluginLoader.cs b/Service/Plugins/PluginLoader.cs index e207050a4..2d3b23ec0 100644 --- a/Service/Plugins/PluginLoader.cs +++ b/Service/Plugins/PluginLoader.cs @@ -3,6 +3,7 @@ using System.Configuration; using System.IO; using System.Linq; using System.Reflection; +using System.Threading; using BeWo.Data; using BS.Shared.Core; @@ -10,7 +11,9 @@ namespace BeWo.Service.Plugins { public class PluginLoader { - public static String Tenant + private static object _Lock = string.Empty; + + public static String Tenant { get { @@ -344,7 +347,7 @@ namespace BeWo.Service.Plugins //t = "6971328056"; // SKM Krefeld //t = "4199238586"; // MeZ Menden; //t = "3226307161"; // Roman Roger Puth - //todo t = "3522103738"; // AWO Münsterland-Recklinghausen + //t = "3522103738"; // AWO Münsterland-Recklinghausen //t = "5592509446"; // Kontakt Verein für psychosoziale Hilfen e.V //t = "5344902949"; // SHK Service GmbH SBD //t = "1422963536"; // Malteser-Johanniter-Johanneshaus gGmbH @@ -371,34 +374,112 @@ namespace BeWo.Service.Plugins } } + public static String CustomerPluginPath() { - var pluginPath = ConfigurationManager.AppSettings.Get("PluginPath"); - -#if DEBUG - if(!(pluginPath is null)) - { - var alt = Path.Combine(pluginPath, Tenant + "_Reports.dll"); - - pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, alt); - - return pluginPath; - } -#endif + var pluginPath = ConfigurationManager.AppSettings.Get("PluginPath"); - if (pluginPath != null) - { - return Path.Combine(pluginPath, Tenant + "_Reports.dll"); + var dllName = Tenant + "_Reports.dll"; + + if (!String.IsNullOrEmpty(pluginPath)) + { + if (pluginPath.StartsWith("..")) + { + pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginPath); + } } + else + { #if DEBUG - return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + Tenant + "_Reports.dll"); + pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "bin"); #else - return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Customer\" + Tenant + "_Reports.dll"); + pluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Customer"); #endif - } + } + - public static T FindClass() where T : new() + return Path.Combine(pluginPath, dllName); + } + + private static void CheckAndUpdateCustomerAssembly() + { + + var customerdll = CustomerPluginPath(); + var dllName = Path.GetFileName(customerdll); + var pluginBasePath = ConfigurationManager.AppSettings.Get("PluginBasePath"); + if (!String.IsNullOrEmpty(pluginBasePath)) + { + if (pluginBasePath.StartsWith("..")) + { + pluginBasePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, pluginBasePath); + } + } + bool aktualisiereAssembly = false; + + if (!String.IsNullOrEmpty(pluginBasePath)) + { + //Prüfe, ob eine neuere Version der dll im Base Path existiert + var baseDll = Path.Combine(pluginBasePath, dllName); + + try + { + if (File.Exists(baseDll)) + { + if (!File.Exists(customerdll)) + { + aktualisiereAssembly = true; + } + else + { + if (File.GetLastWriteTime(baseDll) > File.GetLastWriteTime(customerdll)) + { + aktualisiereAssembly = true; + } + else if (File.GetLastWriteTime(baseDll) == File.GetLastWriteTime(customerdll)) + { + var fibase = new FileInfo(baseDll); + var fiwork = new FileInfo(customerdll); + if (fibase.Length != fiwork.Length) + { + aktualisiereAssembly = true; + } + } + } + + if (aktualisiereAssembly) + { + try + { + Monitor.Enter(_Lock); + + File.Copy(baseDll, customerdll, true); + } + catch + { + + } + finally + { + Monitor.Exit(_Lock); + } + } + + if (aktualisiereAssembly || GetAssembliyForDll(dllName) == null) + { + Assembly.Load(File.ReadAllBytes(customerdll)); + } + } + } + catch + { + //do nothing + } + } + + } + + public static T FindClass() where T : new() { var t = FindClass(null, null); if (t == null) @@ -421,9 +502,8 @@ namespace BeWo.Service.Plugins if (Tenant != null) { - if (File.Exists(CustomerPluginPath())) - lAllTypes = Assembly.LoadFrom(CustomerPluginPath()).GetTypes(); - } + lAllTypes = PluginLoader.GetAllCustomerTypes(); + } T result = default(T); if (lAllTypes != null) @@ -432,7 +512,40 @@ namespace BeWo.Service.Plugins return result; } - public static T FindClass(Type[] lAllTypes, string specificId, string typename) + public static Type[] GetAllCustomerTypes() + { + var path = CustomerPluginPath(); + var dllName = Path.GetFileName(path); + CheckAndUpdateCustomerAssembly(); + + var a = GetAssembliyForDll(dllName); + + if (a != null) + { + return a.GetTypes(); + } + + return null; + } + + private static Assembly GetAssembliyForDll(String dllName) + { + var assemblies = AppDomain.CurrentDomain.GetAssemblies(); + + for (int i = assemblies.Length - 1; i >= 0; i--) + { + var a = assemblies[i]; + + if (a.FullName.StartsWith(dllName.Replace(".dll", ""))) + { + return a; + } + } + + return null; + } + + public static T FindClass(Type[] lAllTypes, string specificId, string typename) { T result = default(T); diff --git a/Shared/Services/Calculations.cs b/Shared/Services/Calculations.cs index a4c66f787..0d4e942a9 100644 --- a/Shared/Services/Calculations.cs +++ b/Shared/Services/Calculations.cs @@ -189,8 +189,11 @@ namespace BS.Shared.Services ratefactor = (100 + factor.Value) / 100; } - - return (this.GetApprovedAmountTotal(relDC) / this.GetMonthCount(relDC.ApprovedStartDate.Value, relDC.ApprovedEndDate.Value)) / ratefactor; + var monate = this.GetMonthCount(relDC.ApprovedStartDate.Value, relDC.ApprovedEndDate.Value); + if (monate != 0) + { + return (this.GetApprovedAmountTotal(relDC) / monate) / ratefactor; + } } } return 0;