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 BeWo.Service.Security; 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 BeWo.Service.ServiceUtils; 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(); 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(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(); var lHeaderCaption = helper.PrepareHeaderArrayForCustomerExport(); var lContent = helper.PrepareContentArrayForCustomerExport(pSortedOids); return WriteHtmlFile(lHeaderCaption, lContent); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } private static ApplicationUser GetLoggedInUser() { ApplicationUser loggedInUser; if (LoggedInUserOperationContextExt.Current != null && LoggedInUserOperationContextExt.Current.User != null) { loggedInUser = LoggedInUserOperationContextExt.Current.User; } else { loggedInUser = SessionFacade.LoggedInUser; } return loggedInUser; } public string PrepareExcelFileEmployeeExport(string pFileID, long[] pSortedOids) { try { var lEmployees = DAOFactory.GenericDAO.LoadByIDs(pSortedOids); bool darfVertragSehen = true; int arrayCount = 37; string[] lHeaderCaption; if (!Utils.UserHasRight(GetLoggedInUser(), UserRightType.Employee_AllowEditContracts)) { arrayCount = 26; darfVertragSehen = false; } if (darfVertragSehen) { lHeaderCaption = new string[37] { "Nachname", // 0 "Vorname", // 1 "Personalnummer", // 2 "Geburtsdatum", // 3 "Beruf", // 4 "Geschlecht", // 5 "Familienstand", // 6 "Krankenkasse", // 7 "Steuernummer", // 8 "beschäftigt als", // 9 "Probezeit (Tage)", // 10 "Kündigungsfrist (Tage)", // 11 "Urlaubstage", // 12 "FLS/Woche", // 13 "Gesamtstunden/Woche", // 14 "Arbeitstage pro Woche", // 15 "Eintrittsdatum", // 16 "Enddatum", // 17 "Versicherungsnummer", "Stundensatz", "Telefon", "Mobil", // 21 "Mail", "private Mail", "Fax", "Strasse", "PLZ", // 26 "Ort", // 27 "Kontonummer", "Bankleitzahl", "Bank", "BIC", // 31 "IBAN", "Bemerkung", // 33 "Fachkraft", "Qualifikation", "Arbeitsschwerpunkte", }; } else { lHeaderCaption = new string[25] { "Nachname", // 0 "Vorname", // 1 "Personalnummer", // 2 "Geburtsdatum", // 3 "Beruf", // 4 "Geschlecht", // 5 "Familienstand", // 6 "Krankenkasse", // 7 "Steuernummer", // 8 "Telefon", "Mobil", // 20 "Mail", "private Mail", "Fax", "Strasse", "PLZ", // 25 "Ort", // 26 "Kontonummer", "Bankleitzahl", "Bank", "BIC", // 30 "IBAN", "Fachkraft", "Qualifikation", "Arbeitsschwerpunkte", }; } string[][] lContent = new string[lEmployees.Count][]; for (int iRowCount = 0; iRowCount < lEmployees.Count; iRowCount++) { lContent[iRowCount] = new string[lHeaderCaption.Count()]; lContent[iRowCount][0] = lEmployees[iRowCount].Person.LastName; lContent[iRowCount][1] = lEmployees[iRowCount].Person.FirstName; lContent[iRowCount][2] = lEmployees[iRowCount].PersonnelNumber; lContent[iRowCount][3] = lEmployees[iRowCount].Person.DateOfBirth.DoIfNotNull(d => d.ToShortDateString()); lContent[iRowCount][4] = lEmployees[iRowCount].Person.Profession; lContent[iRowCount][5] = lEmployees[iRowCount].Person.Sex == Sex.Male ? "männlich" : "weiblich"; if (lEmployees[iRowCount].Person.FamilyStatus != null) { switch (lEmployees[iRowCount].Person.FamilyStatus.Value) { case FamilyStatus.Divorced: lContent[iRowCount][6] = "geschieden"; break; case FamilyStatus.Married: lContent[iRowCount][6] = "verheiratet"; break; case FamilyStatus.Single: lContent[iRowCount][6] = "ledig"; break; case FamilyStatus.Widowed: lContent[iRowCount][6] = "verwitwet"; break; case FamilyStatus.Partner: lContent[iRowCount][6] = "in Partnerschaft"; break; case FamilyStatus.PartnerDivorced: lContent[iRowCount][6] = "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; } } lContent[iRowCount][7] = lEmployees[iRowCount].HealthInsurance; lContent[iRowCount][8] = lEmployees[iRowCount].TaxNumber; if (darfVertragSehen) { if (lEmployees[iRowCount].Person.LastName.StartsWith("Ber")) { int test = 0; } Contract lastContract = lEmployees[iRowCount].LastContract; if (lastContract != null) { if (lastContract.EmploymentType != null) { lContent[iRowCount][9] = lastContract.EmploymentType.Name; } lContent[iRowCount][10] = lastContract.ProbationPeriod.ToString(); lContent[iRowCount][11] = lastContract.CancellationPeriod.ToString(); decimal? urlaubstage = null; if (lastContract.EmploymentType != null && lastContract.EmploymentType.LeaveDays.HasValue) { urlaubstage = lastContract.EmploymentType.LeaveDays; } else { urlaubstage = lastContract.LeaveDays; } if (urlaubstage.HasValue) { lContent[iRowCount][12] = urlaubstage.Value.ToStringNullCheck(); } if (lastContract.WeeklyFLS.HasValue) { lContent[iRowCount][13] = lastContract.WeeklyFLS.Value.ToStringNullCheck(); } if (lastContract.WeeklyTotalHours.HasValue) { lContent[iRowCount][14] = lastContract.WeeklyTotalHours.Value.ToStringNullCheck(); } var wd = lastContract.WeeklyDays ?? 5; if (wd == 0) wd = 5; lContent[iRowCount][15] = String.Format("{0}", wd); if (!lastContract.ContractEndDate.HasValue) { lContent[iRowCount][17] = "unbefristet"; } else { lContent[iRowCount][17] = lastContract.ContractEndDate.DoIfNotNull(d => d.ToShortDateString()); } } var firstContract = lEmployees[iRowCount].FirstContract; if (firstContract != null) { lContent[iRowCount][16] = firstContract.EntryDate.DoIfNotNull(d => d.ToShortDateString()); } lContent[iRowCount][18] = lEmployees[iRowCount].InsuranceNumber; if (lastContract != null) { if (lastContract.HourlyRate.HasValue) { lContent[iRowCount][19] = lastContract.HourlyRate.Value.ToStringNullCheck(); } lContent[iRowCount][33] = lastContract.Notice; } } int index = 9; if (darfVertragSehen) { index = 20; } foreach (var iContact in lEmployees[iRowCount].Person.Contacts) { switch (iContact.Type) { case ContactType.business_Phone: lContent[iRowCount][index] = iContact.Value; break; case ContactType.business_MobilePhone: lContent[iRowCount][index + 1] = iContact.Value; break; case ContactType.business_Mail: lContent[iRowCount][index + 2] = iContact.Value; break; case ContactType.private_Mail: lContent[iRowCount][index + 3] = iContact.Value; break; case ContactType.business_Fax: lContent[iRowCount][index + 4] = iContact.Value; break; } } if (lEmployees[iRowCount].Person.Address != null) { lContent[iRowCount][index + 5] = lEmployees[iRowCount].Person.Address.Street; lContent[iRowCount][index + 6] = lEmployees[iRowCount].Person.Address.PostalCode; lContent[iRowCount][index + 7] = lEmployees[iRowCount].Person.Address.Town; } if (lEmployees[iRowCount].Person.BankAccount != null) { lContent[iRowCount][index + 8] = lEmployees[iRowCount].Person.BankAccount.AccountNumber; lContent[iRowCount][index + 9] = lEmployees[iRowCount].Person.BankAccount.BankCode; lContent[iRowCount][index + 10] = lEmployees[iRowCount].Person.BankAccount.BankName; lContent[iRowCount][index + 11] = lEmployees[iRowCount].Person.BankAccount.Bic; lContent[iRowCount][index + 12] = lEmployees[iRowCount].Person.BankAccount.IBAN; } if (darfVertragSehen) { index += 1; } if (lEmployees[iRowCount].IsQualified.HasValue) { lContent[iRowCount][index + 13] = lEmployees[iRowCount].IsQualified.Value ? "Ja" : "Nein"; } var qualis = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffQualificationsType) .Select(e2o => e2o.Entry); if (qualis != null && qualis.Count() > 0) { StringBuilder sb = new StringBuilder(); foreach (var entry in qualis) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(entry.Value); } lContent[iRowCount][index + 14] = sb.ToString(); } var focuses = lEmployees[iRowCount].ValueList.FindByType(ValueListEntryType.StaffActivityFocusType) .Select(e2o => e2o.Entry); if (focuses != null && focuses.Count() > 0) { StringBuilder sb = new StringBuilder(); foreach (var entry in focuses) { if (sb.Length > 0) { sb.Append(", "); } sb.Append(entry.Value); } lContent[iRowCount][index + 15] = sb.ToString(); } } return WriteHtmlFile(lHeaderCaption, lContent); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } public string PrepareExcelFileOrganisationExport(string pFileID, long[] pSortedOids) { try { var lOrganisations = DAOFactory.GenericDAO.LoadByIDs(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(); var lHeaderCaption = helper.PrepareHeaderArrayForPersonExport(); var lContent = helper.PrepareContentArrayForPersonExport(pSortedOids); #region alt //var lPersons = DAOFactory.GenericDAO.LoadByIDs(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(); var lHeaderCaption = helper.PrepareHeaderArrayForSupportConceptExport(); var lContent = helper.PrepareContentArrayForSupportConceptExport(pSortedOids); return WriteHtmlFile(lHeaderCaption, lContent); #region alt //var exporter = PluginLoader.FindClass(); //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(pSortedOids); List lHeaderCaption = new List(); 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(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(); 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(); var lHeaderCaption = helper.PrepareHeaderArrayForUserGroupExport(); var lContent = helper.PrepareContentArrayForUserGroupExport(pSortedOids); #region alt //Translator t = new Translator(new ServiceTranslator()); //var lUserGroups = DAOFactory.GenericDAO.LoadByIDs(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; 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().CheckIpAddress(); var fileAttachment = DAOFactory.GenericDAO.LoadByID(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().CheckIpAddress(); var fileAttachment = DAOFactory.GenericDAO.LoadByID(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(); return exporter?.CreateQuery(query); } catch (Exception e) { throw Utils.CreateBeWoFaultException(e); } } } }