Files
BeWoPlaner/Service/ServiceImplementations/DownloadServiceImp.cs
Rene Evertz c5ba4bd0ad Kleines Mergechen
Merge branch 'feature_rene_18_ai'

# Conflicts:
#	BeWo/BeWo.csproj
#	BeWo/BeWoApp.xaml.cs
#	BeWo/ServiceProxy/GeneratedCustomerService.cs
#	BeWo/ServiceProxy/GeneratedEmployeeService.cs
#	BeWo/ServiceProxy/GeneratedOperationsService.cs
#	BeWo/View/Detail/Accounting/GkvAbrechnungOverview.xaml.cs
#	BeWo/View/Detail/EmployeeView.xaml
#	BeWo/app.config
#	BeWoAllReports.sln
#	BeWoPlanerMobil.sln
#	Data/Access/SearchDAO.cs
#	Data/Data.csproj
#	Data/Security/UserRightHelper.cs
#	Server/Components/AICore/Prompt/SystemPrompts/Examples/TranscriptionService.cs
#	Service/DCEntityMapper/GkvAbrechnungDC_GkvAbrechnung.cs
#	Service/ServiceImplementations/EmployeeServiceImp.cs
#	Shared/BeWoEntityEnums.cs
#	Shared/Core/EnumTranslations.cs
#	Shared/Core/GkvValidator.cs
#	Shared/Core/ValidatorExtended.cs
#	Shared/Shared.csproj
2026-02-20 16:36:41 +01:00

738 lines
35 KiB
C#

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.ServiceModel;
using System.Text;
using BeWo.Service.Plugins;
using BeWo.Data.Access;
using BeWo.Data.Entities;
using BeWo.Service.Core;
using BeWo.Service.DCEntityMapper;
using BeWo.Service.ServiceContracts;
using BS.Shared;
using BS.Shared.DataContracts;
using BS.Shared.Extensions;
using BS.Shared.RSS;
using BeWo.Data;
using Utils = BeWo.Service.Core.Utils;
using BS.Shared.Translation;
using BeWo.Service.Reporting;
using BS.Shared.Core;
using SecurityUtils = BeWo.Service.Security.SecurityUtils;
namespace BeWo.Service.ServiceImplementations
{
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class DownloadServiceImp : IDownloadService
{
public string PrepareExcelFile(string pFileID, string[] pHeaderCaption, string[][] pContent)
{
try
{
var exporter = PluginLoader.FindClass<DataExporter>();
if (exporter != null)
{
return exporter.CreateExportString(pFileID, pHeaderCaption, pContent);
}
return null;
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileCustomerExport(string pFileID, long[] pSortedOids)
{
try
{
#region alt
// var lCustomers = DAOFactory.GenericDAO.LoadByIDs<Customer>(pSortedOids);
// string[] lHeaderCaption = {
// "Nachname", // 0
// "Vorname", // 1
// "Geburtsdatum", // 3
// "Beruf", // 4
// "Geschlecht", // 5
// "Familienstand", // 6
// "Telefon", // 7
// "Mobil", // 8
// "Mail", // 9
// "Fax", // 10
// "Strasse", // 11
// "PLZ", // 12
// "Ort", // 13
// "Bemerkung", // 14
// "Erstbetreuung", // 15
// "Betreuung begonnen", // 16
// "Betreuung beendet", // 17
// "Grund für Beendigung" // 18
// };
// var lContent = new string[lCustomers.Count][];
// for (int iRowCount = 0; iRowCount < lCustomers.Count; iRowCount++)
// {
// lContent[iRowCount] = new string[lHeaderCaption.Count()];
// lContent[iRowCount][0] = lCustomers[iRowCount].Person.LastName;
// lContent[iRowCount][1] = lCustomers[iRowCount].Person.FirstName;
// //lContent[iRowCount][2] = lCustomers[iRowCount].ReferenceNumber;
// if (lCustomers[iRowCount].Person.DateOfBirth.HasValue)
// {
// lContent[iRowCount][2] = lCustomers[iRowCount].Person.DateOfBirth.Value.ToShortDateString();
// }
// lContent[iRowCount][3] = lCustomers[iRowCount].Person.Profession;
// lContent[iRowCount][4] = lCustomers[iRowCount].Person.Sex == Sex.Male
// ? "männlich"
// : "weiblich";
// if (lCustomers[iRowCount].Person.FamilyStatus != null)
// {
// switch (lCustomers[iRowCount].Person.FamilyStatus.Value)
// {
// case FamilyStatus.Divorced:
// lContent[iRowCount][5] = "geschieden";
// break;
// case FamilyStatus.Married:
// lContent[iRowCount][5] = "verheiratet";
// break;
// case FamilyStatus.Single:
// lContent[iRowCount][5] = "ledig";
// break;
// case FamilyStatus.Widowed:
// lContent[iRowCount][5] = "verwitwet";
// break;
// case FamilyStatus.Partner:
// lContent[iRowCount][5] = "in Partnerschaft";
// break;
// case FamilyStatus.PartnerDivorced:
// lContent[iRowCount][5] = "getrennt lebend";
// break;
// case FamilyStatus.PartnerDead:
// lContent[iRowCount][5] = "partnerhinterblieben";
// break;
//case FamilyStatus.PartnerMarried:
// lContent[iRowCount][5] = "verpartnert";
// break;
//case FamilyStatus.Entpartnert:
// lContent[iRowCount][5] = "entpartnert";
// break;
// }
// }
// foreach (var iContact in lCustomers[iRowCount].Person.Contacts)
// {
// switch (iContact.Type)
// {
// case ContactType.business_Phone:
// lContent[iRowCount][6] = iContact.Value;
// break;
// case ContactType.business_MobilePhone:
// lContent[iRowCount][7] = iContact.Value;
// break;
// case ContactType.business_Mail:
// lContent[iRowCount][8] = iContact.Value;
// break;
// case ContactType.business_Fax:
// lContent[iRowCount][9] = iContact.Value;
// break;
// }
// }
// if (lCustomers[iRowCount].Person.Address != null)
// {
// lContent[iRowCount][10] = lCustomers[iRowCount].Person.Address.Street;
// lContent[iRowCount][11] = lCustomers[iRowCount].Person.Address.PostalCode;
// lContent[iRowCount][12] = lCustomers[iRowCount].Person.Address.Town;
// }
// lContent[iRowCount][13] = lCustomers[iRowCount].Notice;
// if (lCustomers[iRowCount].Employee2CustomerList == null)
// continue;
// foreach (var e2c in lCustomers[iRowCount].Employee2CustomerList)
// {
// foreach (var vle in e2c.ValueList.Select(vle2o => vle2o.Entry).Where(vle => vle.SystemEntryID != null && vle.SystemEntryID.Value == SystemEntryID.EmployeeRoleMainAttendant))
// {
// lHeaderCaption[14] = vle.Value;
// lContent[iRowCount][14] = e2c.Employee.Person.FirstName + " " + e2c.Employee.Person.LastName;
// }
// }
// lContent[iRowCount][15] = String.Format("{0:dd.MM.yyyy}", lCustomers[iRowCount].AssistanceBegin);
// lContent[iRowCount][16] = String.Format("{0:dd.MM.yyyy}", lCustomers[iRowCount].TerminationDate);
// if (lCustomers[iRowCount].TerminationReason != null)
// {
// lContent[iRowCount][17] = lCustomers[iRowCount].TerminationReason.Value;
// }
// else
// {
// lContent[iRowCount][17] = "";
// }
// }
#endregion
//WriteExcelFile(pFileID, lHeaderCaption, lContent, pPath);
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForCustomerExport();
var lContent = helper.PrepareContentArrayForCustomerExport(pSortedOids);
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileEmployeeExport(string pFileID, long[] pSortedOids)
{
try
{
string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, pFileID + ".tmp");
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForEmployeeExport();
var lContent = helper.PrepareContentArrayForEmployeeExport(pSortedOids);
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileOrganisationExport(string pFileID, long[] pSortedOids)
{
try
{
var lOrganisations = DAOFactory.GenericDAO.LoadByIDs<Organisation>(pSortedOids);
string[] lHeaderCaption = {
"Name", // 0
"Notizen", // 1
"Ist Kostenträger", // 2
"Stundensatz", // 3
"Rundungsintervall (Minuten)", // 4
"pauschaler Faktor (%)", // 5
"Strasse", // 6
"PLZ", // 7
"Ort", // 8
"Postfach", // 9
"Telefon", // 10
"Fax", // 11
"Mail", // 12
"Homepage" // 13
};
string[][] lContent = new string[lOrganisations.Count][];
for (int iRowCount = 0; iRowCount < lOrganisations.Count; iRowCount++)
{
lContent[iRowCount] = new string[lHeaderCaption.Count()];
lContent[iRowCount][0] = lOrganisations[iRowCount].Name;
lContent[iRowCount][1] = lOrganisations[iRowCount].Notice;
lContent[iRowCount][2] = lOrganisations[iRowCount].CostBearer != null
? "Ja"
: "Nein";
if (lOrganisations[iRowCount].CostBearer != null)
{
var costRates = lOrganisations[iRowCount].CostBearer.CostRatePeriods.MapToNewDCs();
lContent[iRowCount][3] = costRates.GetCurrentlyValidRateValue(CostRatePeriodType.HourlyRate).ToStringNullCheck();
lContent[iRowCount][4] = costRates.GetCurrentlyValidRateValue(CostRatePeriodType.MinutesIntervall).ToStringNullCheck();
lContent[iRowCount][5] = costRates.GetCurrentlyValidRateValue(CostRatePeriodType.RateFactor).ToStringNullCheck();
}
if (lOrganisations[iRowCount].Address != null)
{
lContent[iRowCount][6] = lOrganisations[iRowCount].Address.Street;
lContent[iRowCount][7] = lOrganisations[iRowCount].Address.PostalCode;
lContent[iRowCount][8] = lOrganisations[iRowCount].Address.Town;
}
foreach (var iContact in lOrganisations[iRowCount].Contacts)
{
switch (iContact.Type)
{
case ContactType.business_POBox:
lContent[iRowCount][9] = iContact.Value;
break;
case ContactType.business_Phone:
lContent[iRowCount][10] = iContact.Value;
break;
case ContactType.business_Fax:
lContent[iRowCount][11] = iContact.Value;
break;
case ContactType.business_Mail:
lContent[iRowCount][12] = iContact.Value;
break;
case ContactType.business_Homepage:
lContent[iRowCount][13] = iContact.Value;
break;
}
}
}
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFilePersonExport(string pFileID, long[] pSortedOids)
{
try
{
string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, pFileID + ".tmp");
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForPersonExport();
var lContent = helper.PrepareContentArrayForPersonExport(pSortedOids);
#region alt
//var lPersons = DAOFactory.GenericDAO.LoadByIDs<Person>(pSortedOids);
//string[] lHeaderCaption = {
// "Titel", // 0
// "Nachname", // 1
// "Vorname", // 2
// "Funktion", // 3
// "Geburtsdatum", // 4
// "Strasse", // 5
// "PLZ", // 6
// "Ort", // 7
// "Telefon", // 8
// "Mobil", // 9
// "Mail", // 10
// "Fax", // 11
// "Bemerkung" // 12
// };
//string[][] lContent = new string[lPersons.Count][];
//for (int iRowCount = 0; iRowCount < lPersons.Count; iRowCount++)
//{
// lContent[iRowCount] = new string[lHeaderCaption.Count()];
// if (lPersons[iRowCount].Title != null)
// {
// lContent[iRowCount][0] = lPersons[iRowCount].Title.Value;
// }
// else
// {
// lContent[iRowCount][0] = string.Empty;
// }
// lContent[iRowCount][1] = lPersons[iRowCount].LastName;
// lContent[iRowCount][2] = lPersons[iRowCount].FirstName;
// if (lPersons[iRowCount].Function != null)
// {
// lContent[iRowCount][3] = lPersons[iRowCount].Function.Value;
// }
// else
// {
// lContent[iRowCount][3] = string.Empty;
// }
// lContent[iRowCount][4] = lPersons[iRowCount].DateOfBirth.DoIfNotNull(d => d.ToShortDateString());
// // lContent[iRowCount][4] = lPersons[iRowCount].Sex == Sex.Male ? "männlich" : "weiblich";
// if (lPersons[iRowCount].Address != null)
// {
// lContent[iRowCount][5] = lPersons[iRowCount].Address.Street;
// lContent[iRowCount][6] = lPersons[iRowCount].Address.PostalCode;
// lContent[iRowCount][7] = lPersons[iRowCount].Address.Town;
// }
// foreach (var iContact in lPersons[iRowCount].Contacts)
// {
// switch (iContact.Type)
// {
// case ContactType.private_Phone:
// lContent[iRowCount][8] = iContact.Value;
// break;
// case ContactType.private_MobilePhone:
// lContent[iRowCount][9] = iContact.Value;
// break;
// case ContactType.private_Mail:
// lContent[iRowCount][10] = iContact.Value;
// break;
// case ContactType.private_Fax:
// lContent[iRowCount][11] = iContact.Value;
// break;
// }
// }
// lContent[iRowCount][12] = lPersons[iRowCount].Notice;
//}
#endregion
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileSupportConceptExport(string pFileID, long[] pSortedOids)
{
try
{
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForSupportConceptExport();
var lContent = helper.PrepareContentArrayForSupportConceptExport(pSortedOids);
return WriteHtmlFile(lHeaderCaption, lContent);
#region alt
//var exporter = PluginLoader.FindClass<DataExporter>();
//if (exporter != null)
//{
//return exporter.PrepareExcelFileSupportConceptExport(pFileID, pSortedOids);
//}
//return null;
#endregion
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileTeamExport(string pFileID, long[] pSortedOids)
{
try
{
string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, pFileID + ".tmp");
var lTeams = DAOFactory.GenericDAO.LoadByIDs<Team>(pSortedOids);
List<string> lHeaderCaption = new List<string>();
string[][] lContent = new string[lTeams.Max(t => t.MemberList.Count)][];
for (int i = 0; i < lTeams.Max(t => t.MemberList.Count); i++)
{
lContent[i] = new string[lTeams.Count * 2];
}
int iColumnCount = 0;
foreach (var iTeam in lTeams)
{
lHeaderCaption.AddRange(new[]
{
iTeam.Name + " (Leitung: " + iTeam.Leader.Person + ")", string.Empty
});
int lRowCount = 0;
foreach (var iMember in iTeam.MemberList)
{
lContent[lRowCount++][iColumnCount] = iMember.Person.ToString();
}
iColumnCount += 2;
}
return WriteHtmlFile(lHeaderCaption.ToArray(), lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileUserExport(string pFileID, long[] pSortedOids)
{
try
{
string lPath = BS.Shared.Core.Utils.CreateSavePath(AppDomain.CurrentDomain.BaseDirectory, pFileID + ".tmp");
#region alt
//var lUser = DAOFactory.GenericDAO.LoadByIDs<ApplicationUser>(pSortedOids);
//string[] lHeaderCaption = {
// "Mitarbeiter", "Login", "zugeordnete Benutzergruppen"
// };
//string[][] lContent = new string[lUser.Count][];
//for (int iRowCount = 0; iRowCount < lUser.Count; iRowCount++)
//{
// lContent[iRowCount] = new string[3];
// if (lUser[iRowCount].Employee != null)
// {
// lContent[iRowCount][0] = lUser[iRowCount].Employee.Person.ToString();
// }
// else
// {
// lContent[iRowCount][0] = "";
// }
// lContent[iRowCount][1] = lUser[iRowCount].LoginName;
// lContent[iRowCount][2] = string.Join(", ", lUser[iRowCount].UserGroups.Select(ug => ug.Name).ToArray());
//}
#endregion
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForUserExport();
var lContent = helper.PrepareContentArrayForUserExport(pSortedOids);
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public string PrepareExcelFileUserGroupExport(string pFileID, long[] pSortedOids)
{
try
{
var helper = PluginLoader.FindClass<ExportAndPrintHelper>();
var lHeaderCaption = helper.PrepareHeaderArrayForUserGroupExport();
var lContent = helper.PrepareContentArrayForUserGroupExport(pSortedOids);
#region alt
//Translator t = new Translator(new ServiceTranslator());
//var lUserGroups = DAOFactory.GenericDAO.LoadByIDs<UserGroup>(pSortedOids);
//string[] lHeaderCaption = {
// "Name", "Beschreibung", "zugeordnete Rechte"
// };
//string[][] lContent = new string[lUserGroups.Count][];
//for (int iRowCount = 0; iRowCount < lUserGroups.Count; iRowCount++)
//{
// lContent[iRowCount] = new string[3];
// lContent[iRowCount][0] = lUserGroups[iRowCount].Name;
// lContent[iRowCount][1] = lUserGroups[iRowCount].Description;
// lContent[iRowCount][2] = string.Join(", ", lUserGroups[iRowCount].Rights.Select(r => BS.Shared.Core.EnumTranslations.UserRightType2Translations[r.RightType]).OrderBy(s => s).ToArray());
//}
#endregion
return WriteHtmlFile(lHeaderCaption, lContent);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
public RssFeed ReadRssFeed(string url)
{
try
{
var urlneu = ConfigurationManager.AppSettings.Get("RssFeedUrl");
//var urlneu = "http://bsnewsmaster.beyondsoft.de/news_rss.php?ClientOID=236180486&CategoryOID=2002858128";
if (string.IsNullOrEmpty(urlneu))
{
//urlneu = "http://bsnewsmaster.beyondsoft.de/news_rss.php?ClientOID=236180486&CategoryOID=2002858128";
urlneu = "https://apps.ownsoft.de/news/rss?evplaner[base_cat]=55";
}
RssFeed feed = new RssFeed();
RssManager mgr = new RssManager(urlneu);
feed.Items = mgr.GetFeed();
feed.Title = mgr.FeedTitle;
feed.Description = mgr.FeedDescription;
var t = PluginLoader.Tenant;
if (!String.IsNullOrEmpty(t))
{
//Liste aller Datenbanken pro Server
//https://support.bewoplaner.de/api/getcontractstate.php?ContractsState=app2.bewoplaner.de&CustomerIDs=1
var alleApp1 = "4190877552,4801617798,5620636022,4950382346,2547623489,6246287823,5380327510,3886054624,1234567890,1441747891,1106039294,1505148718,4199238586,1549622397,2994586539,1873138856,1420341656,5430005891,6712648331,1076891970,3785623125,1378137009,1992495802,5926081834,4378753169,5653806613,5484692276,6923790936,2214258555,3227700467,3341456098,3265049248,6601628227,2998118179,7138297573,9495336024,2499262621,5462295916,1733934665,5805202339,9290510010,1608775460,3915346496,3460972351,8562233401,6380958500,3184859776,3517812158,3460972350,7381352241,6297638711,2808556629,5120047701,3623837005,1000000000,8897605322,4525013596,8181286349,2301474784,9342168675,9278594862,4137042939,8027708435,7419804320";
var alleApp2 = "demo,1421021462,3196643272,2544632712,4917794021,9109849293,8719930557,6272871054,2215396183,9447917179,3890031575,9094672461,2463764327,1352143437,3522103738,2839619357,9893557471,4069072369,2954725299,9814444882,3563903598,2918696314,3010479871,7077286353,7564067748,3892746107,2000000000,7058292376,8828216586,1159580198,2356097460,6161292640,6884855402,8423627748,5509064354,3057313346,2181497347,7852961459,2599702516,6653973776,6322291780,7282396774,5761861730,9171211375,9381048759,0629004412,5687373602,8603970172,1676990640,1783511855,1701920223,2028095630,1062385308,1774789565,8947336185,3936475760,6265842607,3311520228,7107514623,5351926758,2235342307,9805564204,4434019324,3718732195,7923170615,5344902949,3647969417,4529320405,6463422907,7130228334,4941141927,6219220038,5518600303,4160851689,2927247138,9383760246,1172092025,6320805883,6149463003";
var alleApp6 = "3565931805,2727860898,6971328056,8251343124,5065709552,6819347851,2986016022,1750211065,6028314513,3640152169,4351087063,1102876860,4947061147,5578206856,6323001211,1378705749,6178735147,5929601293,3295440484,6082225533,9416221963,1262219859,6000000000,5850903700,5427523619,4293131072,7114701269,9815376800,5960095273,1549093609,8281327384,4820371076,5381886394,5798370140,2438529184,6916712798,6917917884,4817284046,3835353926,8366649557,1508800817,8283849714,9926705197,8323809196,2385915144,9318163880,2535794597,9518001524,1048483934,1193950621,1316958991,1422963536,9064234785,1147414607,3620355768,9430188510,4823067940,9394004017,5433105975,5169297106,1566251835,5240630948,4152581290,2594047883,8740758367,9734214365,9995011876,1253359817,7748694330,9678360705,4748304562,9389386079,5161991213,5595701056,8002913382,5208402821,6758396876,1011478760,3240672437,3629696651,2120989920,7951718431,9254115251,4368361336,3536079480,2976949196,5880845152,5722262183,5537187628,9388871209,7037547461,6860475645,7712740386,2105680746,5592509446,5315865694,2661610871,3208082132,4654766672,2387527289,3551932724,3217696911,7663765314,8242644560,8184278271,4148215029,2314784470,5076807716,6181807138,4052216789,1526158312";
if (feed.Items.Count < 4 && (alleApp1.Contains(t) || alleApp2.Contains(t) || alleApp6.Contains(t)))
{
var item = new RssItem();
item.Title = "BeWoPlaner Update Mobil Client";
feed.Items.Add(item);
if (alleApp2.Contains(t))
{
item.Date = new DateTime(2025, 07, 25);
item.Description = @"Sehr geehrte Kunden,
auf Ihrem Server wird am Wochenende bis zum 28.07.25 ein Update des Mobilklient (mobile BeWoPlaner Variante) eingespielt.";
}
else
{
item.Date = new DateTime(2025, 8, 6);
item.Description = @"Sehr geehrte Kunden,
auf Ihrem Server wurde ein Update des Mobilklient (mobile BeWoPlaner Variante) eingespielt.";
}
feed.Items = feed.Items.OrderByDescending(f => f.Date).ToList();
}
}
return feed;
}
catch (Exception)
{
// throw(BeWo.Service.Core.Utils.ThrowBeWoFaultException(e));
return null;
}
}
private void WriteExcelFile(string pFileId, string[] pHeaderCaption, string[][] pContent, string pPath = "")
{
using (var uFileStream = File.Create(pPath))
using (var uSw = new StreamWriter(uFileStream))
uSw.Write(new ExcelDownload(pHeaderCaption, pContent).CreateExcelOutputString());
}
private static string WriteHtmlFile(string[] pHeaderCaption, string[][] pContent)
{
return new ExcelDownload(pHeaderCaption, pContent).CreateExcelOutputString();
}
public string CreateTemporaryUrl(string link, bool noExpiration)
{
var token = CreateTemporaryToken(link, noExpiration);
var url = TokenUtils.CreateTemporaryUrlByToken(link, token);
return url;
}
public string CreateTemporaryToken(string link, bool noExpiration)
{
string token = SecurityUtils.CreateToken(noExpiration, link);
var slicedToken = SecurityUtils.sliceToken(token, link);
var isPermaLink = Boolean.Parse(slicedToken["ispermalink"].ToString());
var lUser = new ApplicationUser();
if (slicedToken.ContainsKey("user"))
lUser = DAOFactory.UserDAO.FindUserByLoginName(slicedToken["user"].ToString());
var tt = new TemporaryToken
{
EmployeeOid = lUser.Employee.Oid,
EncodedToken = token,
ExpirationDate = DateTime.Parse(slicedToken["expdate"].ToString()),
RequestedLink = link,
IsPermaLink = isPermaLink,
CreatorIP = Utils.GetClientIP()
};
try
{
DAOFactory.GenericDAO.Insert(tt);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
return token;
}
// TODO: Erweitern für den MoK
public FileAttachmentDC GetFileAttachment(long oid)
{
PluginLoader.FindClass<IpAddressChecker>().CheckIpAddress();
var fileAttachment = DAOFactory.GenericDAO.LoadByID<FileAttachment>(oid);
var fileAttachmentDC = MapperFactory.FileAttachmentDC_FileAttachment.MapToNewDC(fileAttachment);
var tenant = MultitenancyOperationContextExt.Current.Tenant;
if(fileAttachment.Oid.HasValue && tenant != null)
{
try
{
FileAttachmentUtils.CheckForFileRootDirectory();
FileAttachmentUtils.SaveFileToFileDirectory(fileAttachment);
fileAttachmentDC.BinaryData = fileAttachment.Data ?? FileAttachmentUtils.LoadFileFromDirectoryForMobile(fileAttachment.Oid, tenant);
}
catch(Exception exception)
{
throw Utils.CreateBeWoFaultException(exception);
}
}
fileAttachmentDC.URL = fileAttachment.Path; // Ist der Dateiname
return fileAttachmentDC;
}
public FileAttachmentDC GetFileAttachmentForMobile(long oid, string tenant)
{
PluginLoader.FindClass<IpAddressChecker>().CheckIpAddress();
var fileAttachment = DAOFactory.GenericDAO.LoadByID<FileAttachment>(oid);
var fileAttachmentDC = MapperFactory.FileAttachmentDC_FileAttachment.MapToNewDC(fileAttachment);
if (fileAttachment.Oid.HasValue && tenant != null)
{
try
{
FileAttachmentUtils.CheckForFileRootDirectory();
FileAttachmentUtils.SaveFileToFileDirectory(fileAttachment);
fileAttachmentDC.BinaryData = fileAttachment.Data ?? FileAttachmentUtils.LoadFileFromDirectory(fileAttachment.Oid);
}
catch (Exception exception)
{
throw Utils.CreateBeWoFaultException(exception);
}
}
fileAttachmentDC.URL = fileAttachment.Path; // Ist der Dateiname
return fileAttachmentDC;
}
public QueryDC CreateQuery(QueryDC query)
{
try
{
var exporter = PluginLoader.FindClass<DataExporter>();
return exporter?.CreateQuery(query);
}
catch (Exception e)
{
throw Utils.CreateBeWoFaultException(e);
}
}
}
}