using System; using System.Collections.Specialized; using System.Data; using System.IO; using System.Linq; using System.Text.RegularExpressions; using Aspose.Pdf; using Hangfire; using Kreta.BusinessLogic.Classes; using Kreta.BusinessLogic.Exceptions; using Kreta.BusinessLogic.HelperClasses.Dokumentum; using Kreta.BusinessLogic.Helpers.Nyomtatvanyok.Iktatas; using Kreta.BusinessLogic.Interfaces; using Kreta.Core; using Kreta.Core.ConnectionType; using Kreta.Core.Iktato.Poszeidon.Factory.Interface; using Kreta.Core.Iktato.Poszeidon.Infrastructure; using Kreta.DataAccess.Interfaces; using Kreta.DataAccessManual; using Kreta.DataAccessManual.Interfaces; using Kreta.DataAccessManual.Util; using Kreta.Enums.ManualEnums; using Kreta.Resources; namespace Kreta.BusinessLogic.Helpers { public class PoszeidonHelper : LogicBase { private readonly int MaxNameLength = 255; private static readonly string illegalPathChars = new string(Path.GetInvalidPathChars()) + new string(Path.GetInvalidFileNameChars()); private static readonly Regex illegalPathCharsRegex = new Regex(string.Format("[{0}]", Regex.Escape(illegalPathChars))); private IIktatoRepositoryFactory IktatoRepositoryFactory { get; } private IktatoServiceConfiguration IktatoServiceConfiguration { get; } public PoszeidonHelper(IConnectionType connectionType, IIktatoRepositoryFactory iktatoRepositoryFactory, IktatoServiceConfiguration iktatoServiceConfiguration) : base(connectionType) { if (iktatoRepositoryFactory != null) { IktatoRepositoryFactory = iktatoRepositoryFactory; } if (iktatoServiceConfiguration != null) { IktatoServiceConfiguration = iktatoServiceConfiguration; } } public (string fajlnev, byte[] tartalom) Lekeres(string iktatottDokumentumId) { return Dal.CustomConnection.Run(ConnectionType, h => { var intezmeny = h.IntezmenyDal().Get(IntezmenyId); var iktatottDokumentum = h.IktatottDokumentumDal().Get(int.Parse(iktatottDokumentumId)); if (iktatottDokumentum.DokumentumStatusz == Enums.DokumentumStatuszEnum.Iktatva.AsInt()) { try { var iktatoRepositoryConfiguration = GetIktatoRepositoryConfiguration(intezmeny.IktatoSzervezetAzonosito, intezmeny.PoszeidonBejelentkezesiNev); var elektronikusPeldanySztornozva = IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).IsElektronikusPeldanySztornozva(iktatottDokumentum.ElektronikusPeldanyId.Value.ToString()); if (elektronikusPeldanySztornozva) { throw new PoszeidonbanSztornozvaException(ErrorResource.PoszeidonbanSztornozvaLettAzElektronikusPeldany); } return (fajlnev: iktatottDokumentum.FajlNev, tartalom: IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).GetIktatottDokumentum(iktatottDokumentum.ElektronikusPeldanyId.Value.ToString())); } catch (PoszeidonbanSztornozvaException) { throw; } catch (Exception) { throw; } } try { return (fajlnev: iktatottDokumentum.FajlNev, tartalom: iktatottDokumentum.Dokumentum.Tartalom); } catch { return (fajlnev: "Üres", tartalom: Array.Empty()); } }); } public (string fajlnev, byte[] tartalom) LekeresCsatolmany(IFileServiceHelper fileServiceHelper, string iktatottDokumentumCsatolmanyId) { return Dal.CustomConnection.Run(ConnectionType, h => { var intezmeny = h.IntezmenyDal().Get(IntezmenyId); var iktatottDokumentumCsatolmany = h.IktatottDokumentumCsatolmanyDal().Get(int.Parse(iktatottDokumentumCsatolmanyId)); var fajlNev = $"{iktatottDokumentumCsatolmany.File.FileNev}.{iktatottDokumentumCsatolmany.File.Extension}"; if (iktatottDokumentumCsatolmany.IsAttached) { try { var iktatoRepositoryConfiguration = GetIktatoRepositoryConfiguration(intezmeny.IktatoSzervezetAzonosito, intezmeny.PoszeidonBejelentkezesiNev); var elektronikusPeldanySztornozva = IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).IsElektronikusPeldanySztornozva(iktatottDokumentumCsatolmany.ElektronikusPeldanyId.Value.ToString()); if (elektronikusPeldanySztornozva) { throw new PoszeidonbanSztornozvaException(ErrorResource.PoszeidonbanSztornozvaLettAzElektronikusPeldany); } var posziCsatolmany = IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).GetIktatottDokumentum(iktatottDokumentumCsatolmany.ElektronikusPeldanyId.Value.ToString()); return (fajlnev: fajlNev, tartalom: posziCsatolmany); } catch (PoszeidonbanSztornozvaException) { throw; } catch (Exception) { throw; } } try { var fileHelper = new FileHelper(new DalHandlerConnectionType(ConnectionType, h), fileServiceHelper); var (name, data) = fileHelper.GetFileData(iktatottDokumentumCsatolmany.File.ID); return (fajlnev: name, tartalom: data); } catch { throw; } }); } private int FoszamosIktatas(IDalHandler h, Stream stream, string iktatasiAzonosito, int iktatoId, int? osztalyId, Enums.DokumentumKategoriaEnum dokumentumkategoria, Enums.DokumentumTipusEnum dokumentumTipus, int elemiSzint, NameValueCollection kulcsSzavak = null, string formatum = Constants.ContentTypes.Pdf, int? sztornozottFoszamosId = null) { byte[] dokumentumTartalom; using (stream) { dokumentumTartalom = Kreta.Framework.Util.StreamUtil.ConvertStreamToByteArray(stream); } var intezmeny = h.IntezmenyDal().Get(IntezmenyId); var osztalyCsoportDal = h.OsztalyCsoport(); var osztalyCsoport = osztalyCsoportDal.Get(); if (osztalyId.IsEntityId()) { osztalyCsoport = osztalyCsoportDal.Get(osztalyId.Value); } string kiterjesztes = GetKiterjesztesFromNyomtatvanyFormatum(formatum); var dokumentumNev = iktatasiAzonosito.Length > (MaxNameLength - kiterjesztes.Length) ? iktatasiAzonosito.Substring(0, MaxNameLength - kiterjesztes.Length) : iktatasiAzonosito; var fajlnev = dokumentumNev; if (!string.IsNullOrWhiteSpace(kiterjesztes)) { fajlnev = dokumentumNev + kiterjesztes; } var dal = h.NyomtatvanyokDal(); var iktatottDokumentum = h.IktatottDokumentumDal().Get(); iktatottDokumentum.TanevId = TanevId; iktatottDokumentum.IktatoSzemelyId = iktatoId; iktatottDokumentum.DokumentumStatusz = (int)Enums.DokumentumStatuszEnum.IktatoszamraVar; Enums.DokumentumKategoriaEnum katEnum = dokumentumkategoria; Enums.DokumentumTipusEnum tipusEnum = dokumentumTipus; iktatottDokumentum.DokumentumKategoria = (int)katEnum; iktatottDokumentum.DokumentumTipus = (int)tipusEnum; iktatottDokumentum.DokumentumNeve = iktatasiAzonosito; iktatottDokumentum.FajlNev = ReplaceForbiddenFilenameCharacters(fajlnev); iktatottDokumentum.Mappa = string.Join("\\", new string[] { intezmeny.IktatoSzervezetAzonosito, katEnum.GetDisplayName(TanevId), tipusEnum.GetDisplayName(TanevId) }); if (osztalyId.IsEntityId()) { iktatottDokumentum.FeladatEllatasiHelyId = osztalyCsoport.FeladatEllatasiHelyId; } iktatottDokumentum.DokumentumElemiSzint = elemiSzint; if (sztornozottFoszamosId.HasValue) { iktatottDokumentum.FoszamosIktatottDokumentumId = sztornozottFoszamosId.Value; } var iktatottDokumentumId = dal.Insert(iktatottDokumentum); var kapottDokumentum = h.DokumentumDal().Get(); kapottDokumentum.Tartalom = dokumentumTartalom; kapottDokumentum.IktatottDokumentumId = iktatottDokumentumId; kapottDokumentum.TanevId = iktatottDokumentum.TanevId; var kapottDokumentumId = dal.Insert(kapottDokumentum); iktatottDokumentum.GeneraltDokumentumId = kapottDokumentumId; CreateDokumentumKulcsszavak(kulcsSzavak, dal, iktatottDokumentum, iktatottDokumentumId); SetIktatottDokumentumPropertySpecial(kulcsSzavak, iktatottDokumentum); dal.FullUpdate(iktatottDokumentum); string id = BackgroundJob.Enqueue((iktatas) => iktatas.FoszamosIktatasDal(iktatottDokumentumId, iktatoId, 0, IntezmenyAzonosito, IntezmenyId, TanevId, null)); iktatottDokumentum.EnqueuedJobId = int.Parse(id); dal.Update(iktatottDokumentum); return iktatottDokumentumId; } private int AlszamosIktatas(IDalHandler h, Stream stream, int iktatottId, string iktatasiAzonosito, int iktatoId, int? osztalyId, Enums.DokumentumKategoriaEnum dokumentumKategoria, Enums.DokumentumTipusEnum dokumentumTipus, int elemiSzint, NameValueCollection kulcsSzavak = null, string formatum = Constants.ContentTypes.Pdf) { byte[] dokumentumTartalom; using (stream) { dokumentumTartalom = Kreta.Framework.Util.StreamUtil.ConvertStreamToByteArray(stream); } var intezmeny = h.IntezmenyDal().Get(IntezmenyId); var osztalyCsoportDal = h.OsztalyCsoport(); var osztalyCsoport = osztalyCsoportDal.Get(); if (osztalyId.IsEntityId()) { osztalyCsoport = osztalyCsoportDal.Get(osztalyId.Value); } string kiterjesztes = GetKiterjesztesFromNyomtatvanyFormatum(formatum); var dokumentumNev = iktatasiAzonosito.Length > (MaxNameLength - kiterjesztes.Length) ? iktatasiAzonosito.Substring(0, MaxNameLength - kiterjesztes.Length) : iktatasiAzonosito; var iktatottDokumentumDal = h.IktatottDokumentumDal(); var iktatottDokumentumParent = iktatottDokumentumDal.Get(iktatottId); var fajlnev = dokumentumNev; if (!string.IsNullOrWhiteSpace(kiterjesztes)) fajlnev = dokumentumNev + kiterjesztes; var dal = h.NyomtatvanyokDal(); var iktatottDokumentum = iktatottDokumentumDal.Get(); iktatottDokumentum.TanevId = TanevId; iktatottDokumentum.IktatoSzemelyId = iktatoId; iktatottDokumentum.DokumentumStatusz = (int)Enums.DokumentumStatuszEnum.IktatoszamraVar; Enums.DokumentumKategoriaEnum katEnum = dokumentumKategoria; Enums.DokumentumTipusEnum tipusEnum = dokumentumTipus; iktatottDokumentum.DokumentumKategoria = (int)katEnum; iktatottDokumentum.DokumentumTipus = (int)tipusEnum; iktatottDokumentum.DokumentumNeve = iktatasiAzonosito; iktatottDokumentum.FajlNev = ReplaceForbiddenFilenameCharacters(fajlnev); iktatottDokumentum.Mappa = string.Join("\\", new string[] { intezmeny.IktatoSzervezetAzonosito, katEnum.GetDisplayName(TanevId), tipusEnum.GetDisplayName(TanevId) }); if (osztalyId.IsEntityId()) { iktatottDokumentum.FeladatEllatasiHelyId = osztalyCsoport.FeladatEllatasiHelyId; } iktatottDokumentum.DokumentumElemiSzint = elemiSzint; iktatottDokumentum.FoszamosIktatottDokumentumId = FindBaseFoszamosIktatottDokumentumId(iktatottId, iktatottDokumentumDal); var iktatottDokumentumId = dal.Insert(iktatottDokumentum); var kapottDokumentum = h.DokumentumDal().Get(); kapottDokumentum.Tartalom = dokumentumTartalom; kapottDokumentum.IktatottDokumentumId = iktatottDokumentumId; kapottDokumentum.TanevId = iktatottDokumentum.TanevId; var kapottDokumentumId = dal.Insert(kapottDokumentum); iktatottDokumentum.GeneraltDokumentumId = kapottDokumentumId; CreateDokumentumKulcsszavak(kulcsSzavak, dal, iktatottDokumentum, iktatottDokumentumId); SetIktatottDokumentumPropertySpecial(kulcsSzavak, iktatottDokumentum); dal.FullUpdate(iktatottDokumentum); string id; if (!string.IsNullOrWhiteSpace(iktatottDokumentumParent.Iktatoszam)) { id = BackgroundJob.Enqueue((iktatas) => iktatas.AlszamosIktatasDal(iktatottDokumentumId, iktatottId, iktatoId, 0, IntezmenyAzonosito, IntezmenyId, TanevId, null)); } else { var jobId = iktatottDokumentumParent.EnqueuedJobId.Value.ToString(); id = Hangfire.BackgroundJob.ContinueWith(jobId, (iktatas) => iktatas.AlszamosIktatasDal(iktatottDokumentumId, iktatottId, iktatoId, 0, IntezmenyAzonosito, IntezmenyId, TanevId, null)); } iktatottDokumentum.EnqueuedJobId = int.Parse(id); dal.Update(iktatottDokumentum); return iktatottDokumentumId; } private int FindBaseFoszamosIktatottDokumentumId(int id, IIktatottDokumentumDal iktatottDokumentumDal) { var iktd = iktatottDokumentumDal.Get(id); if (iktd.IsFoszamos && !iktd.FoszamosIktatottDokumentumId.IsEntityId()) { return id; } return FindBaseFoszamosIktatottDokumentumId(iktd.FoszamosIktatottDokumentumId, iktatottDokumentumDal); } private static void CreateDokumentumKulcsszavak(NameValueCollection kulcsSzavak, INyomtatvanyokDal dal, IIktatottDokumentum iktatottDokumentum, int iktatottDokumentumId) { if (kulcsSzavak != null) { foreach (var key in kulcsSzavak.AllKeys) { foreach (var ertek in kulcsSzavak[key].Split(",".ToCharArray())) { var dokumentumKulcsszoErtek = dal.GetDokumentumKulcsszoErtek(); var ertekUj = ertek; if (ertek.Length > Constants.MinMaxValues.MaxKulcsszoErtekLength) { ertekUj = ertek.Substring(0, Constants.MinMaxValues.MaxKulcsszoErtekLength - 3) + "..."; } dokumentumKulcsszoErtek.Ertek = ertekUj; dokumentumKulcsszoErtek.TanevId = iktatottDokumentum.TanevId; var dokumentumKulcsszoErtekId = dal.Insert(dokumentumKulcsszoErtek); var dokumentumKulcsszo = dal.GetDokumentumKulcsszo(); dokumentumKulcsszo.IktatottDokumentumId = iktatottDokumentumId; dokumentumKulcsszo.DokumentumKulcsszoTipus = ((Enums.DokumentumKulcsszoTipusEnum)Enum.Parse(typeof(Enums.DokumentumKulcsszoTipusEnum), key)).AsInt(); dokumentumKulcsszo.DokumentumKulcsszoErtekId = dokumentumKulcsszoErtekId; dokumentumKulcsszo.TanevId = iktatottDokumentum.TanevId; dal.Insert(dokumentumKulcsszo); dal.AddDokumentumKulcsszo(iktatottDokumentum, dokumentumKulcsszo); } } } } private static void SetIktatottDokumentumPropertySpecial(NameValueCollection kulcsSzavak, IIktatottDokumentum iktatottDokumentum) { if ((iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.HelyettesitesiNaplo.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.PedagogusAltalAdottOsztalyzatokErtekelesek.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.HaladasiMunkafuzetTanaronkent.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.MunkaidoElszamololapHonap.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.NemKotottMunkaidoReszletezoHetiBontas.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.NemKotottMunkaidoReszletezoHaviBontasHonap.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.PedagogusOrarendje.AsInt()) || (iktatottDokumentum.DokumentumTipus == Enums.DokumentumTipusEnum.TermekOrarendje.AsInt()) ) { if (int.TryParse(kulcsSzavak[nameof(Enums.DokumentumKulcsszoTipusEnum.FeladatellatasiHely)], out var feladatellatasihelyId)) { iktatottDokumentum.FeladatEllatasiHelyId = feladatellatasihelyId; } } } public int Iktatas(Stream stream, string iktatasiAzonosito, int iktatoId, Enums.DokumentumKategoriaEnum dokumentumKategoria, Enums.DokumentumTipusEnum dokumentumTipus, int? osztalyId = null, NameValueCollection kulcsSzavak = null, FoszamDefinicioValueModel foszamDefinicio = null, string formatum = Constants.ContentTypes.Pdf) { return Dal.CustomConnection.Run(ConnectionType, h => { var newstream = AddIktatoszamEsVonalkodPlaceholderIfNeeded(dokumentumTipus, stream, formatum); //Az azonosító alapján meghatározni, hogy létezik-e a db-ben ilyen rekord //Ha igen, alszámos iktatás, ha nem, főszámos, és eltárolni az új iktatási azonositot int? iktatottId = IktatasLetezik(h, dokumentumKategoria.AsInt(), dokumentumTipus.AsInt(), foszamDefinicio); var sztornozottFoszamosId = iktatottId.HasValue ? IsStornozott(h, iktatottId.Value) : null; if (iktatottId.HasValue && !sztornozottFoszamosId.HasValue) { return AlszamosIktatas(h, newstream, iktatottId.Value, iktatasiAzonosito, iktatoId, osztalyId, dokumentumKategoria, dokumentumTipus, foszamDefinicio.Szint.AsInt(), kulcsSzavak, formatum); } return FoszamosIktatas(h, newstream, iktatasiAzonosito, iktatoId, osztalyId, dokumentumKategoria, dokumentumTipus, foszamDefinicio.Szint.AsInt(), kulcsSzavak, formatum, sztornozottFoszamosId); }); } private int? IsStornozott(IDalHandler h, int iktatottParentId) { var iktDokDal = h.IktatottDokumentumDal(GridParameters); var parent = iktDokDal.Get(iktatottParentId); int? ret = null; var intezmeny = new IntezmenyHelper(new DalHandlerConnectionType(ConnectionType, h)).GetIntezmenyiAdatok(); var iktatoRepositoryConfiguration = GetIktatoRepositoryConfiguration(intezmeny.IktatoSzervezetAzonosito, intezmeny.PoszeidonBejelentkezesiNev); var retSztornozva = IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).IsUgyiratSztornozva(parent.Iktatoszam); if (retSztornozva) { try { var nyomtatvanyokDal = h.NyomtatvanyokDal(GridParameters); var ds = nyomtatvanyokDal.GetFoszamosAlszamosIktatottDokumentumIds(parent.FoszamosIktatottDokumentumId); ret = parent.FoszamosIktatottDokumentumId; IIktatottDokumentum iktatottDokumentum; foreach (var id in ds.Tables[0].AsEnumerable().Select(r => r.Field("Id"))) { iktatottDokumentum = iktDokDal.Get(id); if (!IktatoRepositoryFactory.GetIktatoRepository(iktatoRepositoryConfiguration).IktatokonyvByIktatoszam(iktatottDokumentum.Iktatoszam, intezmeny.IktatoSzervezetAzonosito)) { if (iktatottDokumentum.DokumentumKulcsszo.Count > 0) { var ertekek = iktatottDokumentum.DokumentumKulcsszo.Select(x => x.DokumentumKulcsszoErtek).ToArray(); iktDokDal.DokumentumKulcsszoCascadeDeleteAll(id); foreach (var ertek in ertekek) { iktDokDal.DeleteDokumentumKulcsszoErtek(ertek.ID); } } if (iktatottDokumentum.Dokumentum != null) { iktDokDal.DeleteDokumentum(iktatottDokumentum.Dokumentum.ID); } iktDokDal.DeleteIktatottDokumentum(id); } } } catch (Exception) { throw; } } return ret; } public DataSet GetFelhasznaloIktatottDokumentumai(IktatottDokumentumSearchCo searchCo) { return Dal.CustomConnection.Run(ConnectionType, h => { if (searchCo.OsztalyId.HasValue) { var osztcsopDal = h.OsztalyCsoport(); if (!osztcsopDal.IsOsztaly(searchCo.OsztalyId.Value, TanevId)) { searchCo.CsoportId = searchCo.OsztalyId; searchCo.OsztalyId = null; } } var dal = h.NyomtatvanyokDal(GridParameters); return dal.GetFelhasznaloIktatottDokumentumai(searchCo); }); } public HelperClasses.IntezmenyiDokumentumCO IntezmenyiKotelezoDokumentum(int? tanevId, Enums.DokumentumTipusEnum dokumentumTipus) { return Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NyomtatvanyokDal(); var iktatottDokumentumId = dal.GetIntezmenyiIktatottDokumentum(IntezmenyId, tanevId, (int)dokumentumTipus); HelperClasses.IntezmenyiDokumentumCO co = new HelperClasses.IntezmenyiDokumentumCO(); co.Statusz = IntezmenyiDokumentumStatuszEnum.NincsFeltoltve; co.Nev = dokumentumTipus.GetDisplayName(TanevId); co.FajlNev = ""; co.Tipus = dokumentumTipus; co.IktatottDokumentumId = iktatottDokumentumId; if (iktatottDokumentumId.IsEntityId()) { var iktatottDokumentum = h.IktatottDokumentumDal().Get(iktatottDokumentumId); co.FajlNev = iktatottDokumentum.FajlNev; co.Statusz = IntezmenyiDokumentumStatuszEnum.Feltoltve; } return co; }); } public HelperClasses.IntezmenyiDokumentumCO IntezmenyiKotelezoDokumentumPublikus(int? tanevId, Enums.DokumentumTipusEnum dokumentumTipus) { return Dal.CustomConnection.Run(ConnectionType, h => { var dal = h.NyomtatvanyokDal(); var iktatottDokumentumId = dal.GetIntezmenyiIktatottDokumentum(IntezmenyId, tanevId, (int)dokumentumTipus); HelperClasses.IntezmenyiDokumentumCO co = new HelperClasses.IntezmenyiDokumentumCO(); co.Statusz = IntezmenyiDokumentumStatuszEnum.NincsFeltoltve; co.Nev = ""; co.FajlNev = ""; co.Tipus = dokumentumTipus; co.IktatottDokumentumId = iktatottDokumentumId; if (iktatottDokumentumId.IsEntityId()) { var iktatottDokumentum = h.IktatottDokumentumDal().Get(iktatottDokumentumId); co.FajlNev = iktatottDokumentum.FajlNev; co.Statusz = IntezmenyiDokumentumStatuszEnum.Feltoltve; } return co; }); } private int? IktatasLetezik(IDalHandler h, int dokumentumKategoria, int dokumentumTipus, FoszamDefinicioValueModel foszamDefinicio) { return h.NyomtatvanyokDal().IktatasLetezik(foszamDefinicio.IntezmenyId.Value, foszamDefinicio.TanevId, dokumentumKategoria, dokumentumTipus, foszamDefinicio.Szint.AsInt(), foszamDefinicio.OsztalyId, foszamDefinicio.CsoportId, foszamDefinicio.TanarId, foszamDefinicio.EvfolyamId, foszamDefinicio.TeremId, foszamDefinicio.GondviseloNeve, foszamDefinicio.TanuloNeve, foszamDefinicio.TanuloEgyediAzonosito, foszamDefinicio.AlkalmazottEgyediAzonosito); } private string GetKiterjesztesFromNyomtatvanyFormatum(string formatum) { switch (formatum) { case Constants.ContentTypes.Excel: return Constants.ImportExport.FileExtensionExcel; case Constants.ContentTypes.Word: return Constants.ImportExport.FileExtensionWord; case Constants.ContentTypes.Pdf: return Constants.ImportExport.FileExtensionPdf; case Constants.ContentTypes.Xlsx: return Constants.ImportExport.FileExtensionExcelX; case Constants.ContentTypes.Docx: return Constants.ImportExport.FileExtensionDocx; default: return string.Empty; } } public void RestartIktatasJob(int iktatottDokumentumId) { var iktatottDokumentum = Dal.CustomConnection.Run(ConnectionType, h => { return h.IktatottDokumentumDal().Get(iktatottDokumentumId); }); var ret = BackgroundJob.Requeue(iktatottDokumentum.FailedJobId.ToString()); } private Stream AddIktatoszamEsVonalkodPlaceholderIfNeeded(Enums.DokumentumTipusEnum dokumentumTipus, Stream stream, string formatum = Constants.ContentTypes.Pdf) { switch (dokumentumTipus) { case Enums.DokumentumTipusEnum.AlapitoOkirat: case Enums.DokumentumTipusEnum.SzervezetiEsMukodesiSzabalyzat: case Enums.DokumentumTipusEnum.PedagogiaiProgram: case Enums.DokumentumTipusEnum.Hazirend: case Enums.DokumentumTipusEnum.Munkaterv: case Enums.DokumentumTipusEnum.mukodesi_engedely: switch (formatum) { case Constants.ContentTypes.Word: case Constants.ContentTypes.Docx: return AddIktatoszamEsVonalkodPlaceholderToDoc(stream, formatum); default: return AddIktatoszamEsVonalkodPlaceholderToPdf(stream); } case Enums.DokumentumTipusEnum.TantargyfelosztasFormazottPDF: case Enums.DokumentumTipusEnum.ElfogadottTantargyfelosztasFormazottPDF: return AddIktatoszamEsVonalkodPlaceholderToPdf(stream); default: return stream; } } private IktatoRepositoryConfiguration GetIktatoRepositoryConfiguration(string intezmenyIktatoSzervezetAzonosito, string intezmenyPoszeidonBejelentkezesiNev) { return new IktatoRepositoryConfiguration() { EndpointAddress = string.Format(IktatoServiceConfiguration.EndpointAddress, "poszeidonai"), Password = IktatoServiceConfiguration.Password, Username = string.Format(IktatoServiceConfiguration.Username, intezmenyIktatoSzervezetAzonosito), PoszeidonAzonosito = intezmenyPoszeidonBejelentkezesiNev }; } private static Stream AddIktatoszamEsVonalkodPlaceholderToPdf(Stream stream) { var ms = new MemoryStream(); Document doc = new Document(stream); Aspose.Pdf.Text.TextFragment tf = new Aspose.Pdf.Text.TextFragment("{ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-/}"); foreach (var page in doc.Pages) { HeaderFooter footer = new HeaderFooter(); Table tab1 = new Table(); tab1.ColumnWidths = "50%"; tab1.DefaultCellTextState.ForegroundColor = Color.White; tab1.Margin.Top = 10; footer.Paragraphs.Add(tab1); Row row1 = tab1.Rows.Add(); Cell cell = row1.Cells.Add("{iktatoSzam}"); cell.DefaultCellTextState.FontSize = 16; cell.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Left; cell = row1.Cells.Add("{vonalkod}"); cell.DefaultCellTextState.HorizontalAlignment = HorizontalAlignment.Left; cell.DefaultCellTextState.FontSize = 20; tf.TextState.ForegroundColor = page.Background; footer.Paragraphs.Add(tf); page.Header = footer; } doc.Save(ms); stream.Close(); stream.Dispose(); return ms; } private static Stream AddIktatoszamEsVonalkodPlaceholderToDoc(Stream stream, string formatum) { var ret = new MemoryStream(); Aspose.Words.Document doc = new Aspose.Words.Document(stream); Aspose.Words.DocumentBuilder builder = new Aspose.Words.DocumentBuilder(doc); builder.MoveToHeaderFooter(Aspose.Words.HeaderFooterType.FooterPrimary); Aspose.Words.Tables.Table table = builder.StartTable(); builder.CellFormat.ClearFormatting(); builder.InsertCell(); builder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100 / 2); builder.Font.Size = 18; builder.Write("{iktatoSzam}"); builder.CurrentParagraph.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Left; builder.InsertCell(); builder.CellFormat.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPercent(100 / 2); builder.Font.Size = 20; builder.Write("{vonalkod}"); builder.CurrentParagraph.ParagraphFormat.Alignment = Aspose.Words.ParagraphAlignment.Right; builder.EndRow(); table.PreferredWidth = Aspose.Words.Tables.PreferredWidth.FromPoints((builder.PageSetup.PageWidth - builder.PageSetup.LeftMargin - builder.PageSetup.RightMargin) * 0.95); builder.EndTable(); table.ClearBorders(); builder.MoveToDocumentEnd(); doc.Save(ret, (formatum == Constants.ContentTypes.Word) ? Aspose.Words.SaveFormat.Doc : Aspose.Words.SaveFormat.Docx); ret.Position = 0; stream.Close(); stream.Dispose(); return ret; } private static string ReplaceForbiddenFilenameCharacters(string filename) { return illegalPathCharsRegex.Replace(filename, "_"); } } }