using System; using System; using System.Configuration; using System.IO; using System.Linq; using System.Reflection; using BeWo.Data; using BS.Shared.Core; using NHibernate.Mapping; namespace BeWo.Service.Plugins { public class PluginLoader { public static String Tenant { get { #if DEBUG var t = "demo"; //t = "irgendwaswasesnichtgibt"; //t = "5473568546"; //Interner Chat // t = "2356097460"; // Lebenshilfe Würzburg //t = "1234567890"; // Präsentationsdatenbank //t = "5687373602"; // LH Duisburg //t = "5509064354"; // LH Duisburg Service Plus //t = "5620636022"; // GPZ Biberach //t = "8562233401"; // Sozialwirkstatt Schmitz //t = "1076891970"; // Assistenza //t = "0216265667"; // LH Hannover //t = "1774789565"; // LH Essen //t = "9342168675"; // ABC Betreuungen //t = "1193188501"; // Aids Hilfe Dortmund //t = "7860351957"; // SKF Alsdorf //t = "3311520228"; // Die Düne //t = "1352143437"; // Sewo //t = "7107514623"; // BeWo Neuss //t = "9098141768"; // Fib e.V. Marburg //t = "1505148718"; // VSD Hamm //t = "5926081834"; // Spektrum //t = "1378137009"; // BeWo Direkt+ //t = "3010479871"; // Aachener Verein //t = "3849764093"; // Club 74 //t = "5805202339"; // Wegweiser Betreuungsdienst //t = "2301474784"; // Hauskrankenpflege Leiendecker //t = "8243565510"; // Der Karren //t = "7709306800"; // Der Karren SBD //t = "2499262621"; // HPH Bersenbrück //t = "4950382346"; // Holsinger //t = "5973016645"; // Verein Lebensgestaltung Hanau //t = "7375324044"; // Diakonie KK Kleve //t = "1441747891"; // BeWo Mobil Köln //t = "5120047701"; // Trialog //t = "3629696651"; // Soziale Dienste Niederrhein //t = "9893557471"; // Caritas Frankfurt //t = "2918696314"; // Caritas Frankfurt 2 //t = "6923790936"; // Integra e.V. //t = "2392153512"; // Christopherus Haus //t = "9495336024"; // VKM Aachen //t = "5237724939"; // Indro ABW //t = "7635986435"; // Köln Ring //t = "4074176860"; // Soziale Dienstleistung Gessner //t = "2542550178"; // LWVEingliederungshilfe //t = "3963982016"; // Convoi //t = "1600408120"; // BeWo Amrath //t = "3886054624"; // Brücke ABW //t = "2028095630"; // Integra Heinsberg //t = "5351926758"; // Viva a Vida //t = "2215396183"; // Diakonie Remscheid Lennep //t = "5157599087"; // SHG Schwerte //t = "4526293996"; // Fortis //t = "3647969417"; // Caritas Bottrop //t = "3963982016"; // Convoi //t = "3057313346"; // SSB Mainz //t = "6246287823"; // BeWo Alsdorf //t = "1420341656"; // Vibb Essen //t = "4941141927"; // Signcom //t = "8897605322"; // SPZ Ratingen //t = "6483870127"; // Wigonetz //t = "9482484652"; // Blömeling und Teckhaus //t = "8001550599"; // Biallas BeWo //t = "7282396774"; // Caritas Unna //t = "6884855402"; // IBP //t = "4867997795"; // ADiK Kleve //t = "3184859776"; // Sergej Becker //t = "7752610643"; // BWK Gbr //t = "3785623125"; // Betreuwo //t = "7130228334"; // LH Borken //t = "4209820830"; // VKM Hamm //t = "5700328131"; // Betreutes Wohnen St. Ludgerus Essen-Werden //t = "1907984777"; // Soziale Dienste Katrin Schmidt //t = "9033246467"; // SKM Menden //t = "9290510010"; // Soziale Dienste Schilling (ehemals BeWo Schilling) //t = "5251218094"; // KOMO e.V. //t = "3529871747"; // Vivat gemeinnützige GmbH //t = "8561513464"; // Caritasverband Wuppertal/Solingen //t = "2727001973"; // SD Julia Schönberg //t = "5653806613"; // Feid und Kollegen //t = "3830114427"; // FiZ Familie im Zentrum Hof //t = "7138297573"; // Tagwerk betreutes wohnen //t = "1008896531"; // BeWo Auxilio //t = "9383760246"; // Die Kette //t = "5915565037"; // Lebenshilfe Remscheid //t = "3350425974"; // BeWo Rückenwind //t = "9447917179"; // LH Rodenkirchen //t = "4690407894"; // Bleib im Leben //t = "2509786400"; // LH Stade //t = "8677523325"; // BeWo Richartz //t = "1765854593"; // Mein Betreutes Wohnen //t = "6802909544"; // Lebenshilfe Coburg //t = "9417634361"; // Synprax //t = "5761861730"; // Lebenshilfe Warendorf //t = "6712648331"; // BeWo Färber //t = "4982295287"; // ASB Hamm //t = "3890031575"; // Die Wohnhelfer Kuhrau //t = "3536719736"; // BeWo Stefanie Schäfer (BeWoKerpen) //t = "7739670213"; // SPZ Leverkusen //t = "3341456098"; // Hilfe Daheim (früher BeWo Schillinger) //t = "4271389563"; // Komm Mit //t = "5430005891"; // Marienhospital Eickel //t = "3265049248"; // Gerdas Pflegedienst //t = "1549622397"; // Kontakt und Krisenhilfe //t = "4782194565"; // Skm Rheydt //t = "7535795843"; // Sozialwerk Dürener Christen //t = "6388340414"; // Weitblick //t = "0288588964"; // BeWo Marin //t = "8872796313"; // WMB //t = "6297638711"; // ASB Bergisch Gladbach //t = "5553641242"; // RheinSupport (ehem. Aids und Drogenberatung) //t = "1218057423"; // LH Koblenz //t = "3517812158"; // Haus Theresia //t = "7058292376"; // BeWo Heinsberg //t = "3227700467"; // Psychosozialer Trägerverein //t = "4378753169"; // Die Wohnhelfer Köln //t = "2214258555"; // Betreuungsbüro Baak //t = "4525013596"; // Hph Bersenbrück Freizeit und Reisen //t = "1609455614"; // Hph Bersenbrück Aph //t = "7852961459"; // B&B Betreutes Wohnen //t = "8719930557"; // Lebenshilfe Rhein-Sieg //t = "8947336185"; // Lebenshilfe Ahrweiler //t = "5712358157"; // FINDUS //t = "8828216586"; // Caritas Aachen //t = "7062943632"; // ABW Elsebrock //t = "3956369664"; // LH Wetterau //t = "3984525482"; // API Berlin //t = "9975231461"; // Selwo //t = "8181286349"; // BeWo am Rhein //t = "4595275645"; // Eigenständig //t = "7912635399"; // Prof. Dr. Eggers Stiftung //t = "3549726254"; // Socia //t = "1992495802"; // Monvita //t = "7381352241"; // Ressource e.V. //t = "3607551608"; // Betreuungsbüro Scholz //t = "3104936392"; // B.A.P. Bielefelder Ambulante Pflege //t = "1106039294"; // Hph Bersenbrück ATZ //t = "5562845955"; // Praunheimer Werkstätten //t = "4801617798"; // Severin //t = "1172092025"; // Flingern //t = "3852198843"; // LH Mannheim //t = "9800364930"; // BeWo Leverkusen //t = "4439874912"; // BeWo Sahin //t = "1873138856"; // BUG e.V. //t = "6463422907"; // Caritas Leverkusen //t = "6149463003"; // Diakonisches Werk Bad Windsheim Neustadt a. d. Aisch //t = "6548202677"; // VKM Aachen SBD //t = "7803602698"; // Taubblindendienst //t = "5518600303"; // Wetterleuchten e.V. //t = "4096649015"; // AWO Dortmund //t = "3614251071"; // Pusteblume //t = "7755740484"; // Sawo //t = "8275654834"; // Twg Jonathan //t = "6586058528"; // Freundeskreis Suchtkrankenhilfe e.V. //t = "2632162696"; // Pro BeWo Düren //t = "6340891020"; // Caritas Ahlen //t = "3659854106"; // alpha e.V. //t = "5809130435"; // Lebenshilfe Kusel //t = "3367947706"; // PaS Mönchengladbach //t = "2331203795"; // BeWo für dich //t = "5426234256"; // SKM Leverkusen //t = "4137042939"; // MLG Lebengestalten / Haus Müllestumpe //t = "5260936181"; // LORI //t = "1931553444"; // HIBA //t = "7185338722"; // BeWo Walz & Paiva //t = "3196643272"; // Betreutes Wohnen Lisa Wöll //t = "3432911735"; // Caritas Günzburg - Neu Ulm //t = "2591682148"; // Humanitas //t = "9805564204"; // LeWo Aachen //t = "7215356798"; // Triathlon //t = "3664416736"; // LH Mönchengladbach //t = "4290816992"; // BeWo im flow //t = "3612443220"; // ABW Weeger //t = "6265842607"; // BeWo Dienstleistungen Pougin und Klaasen //t = "9273332501"; // Pflegedienst Wessel //t = "4693476852"; // HSH Netzwerk //t = "3884496709"; // Wahl e.V. //t = "9883255779"; // VKM Menden //t = "9556218062"; // Diakonie Landshut //t = "2279593936"; // Diakonie Mülheim //t = "3623837005"; // Betreuwo Wesel //t = "8407321888"; // AWO Wesel //t = "8454426692"; // Mit-Menschen Wuppertal //t = "0629004412"; // BeWo-Colonia Basaran (Projekt //t = "7668701607"; // Wohnstätten Essen //t = "3833058951"; // Aids Hilfe Duisburg (Self) //t = "9463879250"; // ABW Dziallas und Muhrin //t = "7964339639"; // Lebenshilfe Trier //t = "1477928721"; // ASB Regionalverband Rhein-Erft/Dueren e.V. //t = "6178990609"; // Johannes-Diakonie Mosbach //t = "7185105541"; // Nous GmbH //t = "5022131330"; // Tabula Rasa //t = "4189934785"; // Landshuter Netzwerke //t = "4290816992"; // BeWo Imflow //t = "7584236951"; // Aachener Betreuungsbüro Kirschbaum und Manz GbR //t = "3678599942"; // VKM Rietberg //t = "4069072369"; // BeWo Dreilich&Pastor (Pastor) //t = "4160851689"; // BeWo Dreilich&Pastor (Dreilich) //t = "9970072066"; // Bussmannshof //t = "2993745954"; // Kollegium für freie Jugendarbeit und Berufsbildung e.V. //t = "5495240031"; // Christian Luft //t = "6922762575"; // BHS Solingen //t = "3472573348"; // ASB Mönchengladbach //t = "8831599797"; // SeHT Münster //t = "7817461089"; // FAB e.V. (Familienarbeit und Beratung e.V.) //t = "5207911843"; // Pro Balance //t = "8619663355"; // HSH Cologne //t = "1652658918"; // LH Frankfurt Oder //t = "7696927868"; // Kuhring Betreuung //t = "6251348980"; // BeWo Gün //t = "6782533512"; // LH Dorsten //t = "5890882255"; // Fortis Nova //t = "2422863972"; // Diakonisches Werk Mülheim (Therapeutische Wohngemeinschaft) //t = "2141858509"; // INKOMM GmbH //t = "8975059766"; // Quer-Fällt-Ein //t = "8928179244"; // ASB Ruhr e.V. Regionalverband //t = "4423043131"; // Die Perspektive e.V. //t = "5263375280"; // LH Wolfsburg //t = "4900722829"; // Evangelische Kirchengemeinde Bottrop t = "9853685258"; // Input //t = "7622428090"; // Freie gemeinnützige Beratungsstelle für Psychotherapie e.V. (BfpDus) (Panama) //t = "0206140343"; // Lebenswelt Gabriel //t = "6916712798"; // LH Rodenkirchen Bewo //t = "6255521162"; // KCM GmbH //t = "2697528233"; // Diakonisches Werk Wesel //t = "2547623489"; // Sprungbrett //t = "5076807716"; // Psychosoziale Hilfen Bochum e.V. //t = "1601313225"; // Bella Donna //t = "5098825926"; // SAB GmbH //t = "7808149226"; // BeWo Flex //t = "7419804320"; // Gender Bewo //t = "4500422855"; // BeWo Nordeifel //t = "3565931805"; // Betreuungsbüro Frank Röhrig //t = "4152581290"; // MVZ Medikus GmbH (Stoffwechsel Betreutes wohnen) //t = "4529320405"; // BeWo Stelzel //t = "2594047883"; // KOMM Ambulante Dienste e. V. //t = "1558685648"; // KIMM //t = "3460972350"; // Caritas Kleve I //t = "2623845876"; // Passgenau Hildesheim //t = "4368361336"; // Kompass BeWo Wesel //t = "3257905806"; // Diakonisches Werk Herne //t = "2535794597"; // Mobilo Ambulant //t = "7114701269"; // Die Brücke Hilfe und Halt //t = "6447060239"; // Empathie Fachassistenz //t = "6919016656"; // Leben und Wohnen Christian Wilke //t = "8281327384"; // Caritasverband Düren-Jülich e.V. (Eingliederungshilfe) //t = "6023735102"; // Kölner BeWo (Selbstbestimmt Leben) //t = "2998118179"; // BeWo Plus //t = "9254115251"; // Praunheimer Werkstätten 2.DB //t = "5880845152"; // Bewegt Systemische Beratung und Begleitung (Kathrin Lilly) //t = "5798370140"; // Team Pfeil //t = "8242644560"; // Bewolonia - Fr. Sultan Schulz //t = "4817284046"; // Verein für Sozialmedizin Stade e.V. //t = "6323001211"; // ASB Faßbacher Hof gGmbH //t = "9389386079"; // VARO Sozialagentur //t = "7951718431"; // Ambulant Betreutes Wohnen Astrid Pulm //t = "5850903700"; // Alzey Teilhabe //t = "5929601293"; // Lebenshilfe Duisburg Frühförderung (Projekt heißt LebenshilfeDuisburgAtz) //t = "4823067940"; // Die Kette 2 //t = "8283849714"; // Forum e.V. (proviel GmbH) //t = "3915346496"; // Sprungbrett 2. DB (Haus Theresia) //t = "2387527289"; // Lebenshilfe Duisburg HPFH //t = "5595701056"; // Domiziel Ansbach //t = "9430188510"; // Pro INTEGRA //t = "4820371076"; // Zuhause Wohnen Iris Thimm //t = "1078667960"; // FAM Rhein-Sieg Gbr //t = "9388871209"; // Sozialwerk Aachener Christen e.V. //t = "1566251835"; // Sicherleben Michael Voß //t = "4947061147"; // Diakonisches Werk Passau //t = "9064234785"; // BeWo Rimbach return t; #else if (MultitenancyOperationContextExt.Current != null) return MultitenancyOperationContextExt.Current.Tenant; return SessionFacade.Tenant; #endif } } private static String CustomerPluginPath() { var path = ConfigurationManager.AppSettings.Get("PluginPath"); if (path != null) { return Path.Combine(path, Tenant + "_reports.dll"); } #if DEBUG return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\" + Tenant + "_reports.dll"); #else return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"Customer\" + Tenant + "_reports.dll"); #endif } public static T FindClass() where T : new() { var t = FindClass(null, null); if (t == null) { t = new T(); } return t; } public static T FindClass(string specificId) { return FindClass(specificId, null); } public static T FindClass(string specificId, string typename) { Type[] lAllTypes = null; var type = typeof(T); if (Tenant != null) { if (File.Exists(CustomerPluginPath())) lAllTypes = Assembly.LoadFrom(CustomerPluginPath()).GetTypes(); } T result = default(T); if (lAllTypes != null) result = FindClass(lAllTypes, specificId, typename); return result; } public static T FindClass(Type[] lAllTypes, string specificId, string typename) { T result = default(T); if (!string.IsNullOrEmpty(specificId) && !string.IsNullOrEmpty(typename)) { var cbSpecific = lAllTypes .Where(i => typeof(T).IsAssignableFrom(i)) .FirstOrDefault(t => t.GetCustomAttributes(typeof(IDSpecificClassAttribute), true) .ToList() .Exists(i => { var attr = (IDSpecificClassAttribute)i; if (attr.Identifiers != null) return attr.Identifiers.Contains(specificId); if (!String.IsNullOrEmpty(attr.Identifier)) return attr.Identifier.Equals(specificId); return false; } ) && t.FullName == typename); if (cbSpecific != null) result = (T)Activator.CreateInstance(cbSpecific); } if (!string.IsNullOrEmpty(typename)) { var cbSpecific = lAllTypes.FirstOrDefault(t => t.FullName == typename); if (cbSpecific != null) result = (T)Activator.CreateInstance(cbSpecific); } if (!string.IsNullOrEmpty(specificId)) { var cbSpecific = lAllTypes .Where(i => typeof(T).IsAssignableFrom(i)) .FirstOrDefault(t => t.GetCustomAttributes(typeof(IDSpecificClassAttribute), true) .ToList() .Exists(i => { var attr = (IDSpecificClassAttribute)i; if (attr.Identifiers != null) return attr.Identifiers.Contains(specificId); if (!String.IsNullOrEmpty(attr.Identifier)) return attr.Identifier.Equals(specificId); return false; } )); if (cbSpecific != null) result = (T)Activator.CreateInstance(cbSpecific); if (result == null) { foreach (var iType in lAllTypes) if (typeof(T).IsAssignableFrom(iType)) if (iType.Name == specificId) result = (T)Activator.CreateInstance(iType); } } if (result == null) { var list2 = lAllTypes.Where(t => typeof (T).IsAssignableFrom(t)).ToList(); var list = list2.Where(t => t.GetCustomAttributes(typeof (IgnoreAutoPluginAttribute), true).Length == 0).ToList(); if (list.Count == 1) result = (T)Activator.CreateInstance(list[0]); else if (list.Count > 1) { foreach (var type in list) { var attrs = type.GetCustomAttributes(typeof(IDSpecificClassAttribute), true); if (attrs.Length == 0) return (T)Activator.CreateInstance(type); } result = (T)Activator.CreateInstance(list[0]); } } return result; } } }