using System; using System.Runtime.Caching; using Kreta.BusinessLogic.Helpers; using Kreta.Core.ConnectionType; using Kreta.Core.Logic; using Kreta.DataAccessManual; using Kreta.DataAccessManual.Util; using Kreta.Ellenorzo.Dao.VN.Ellenorzo; using Kreta.Ellenorzo.Domain.VN.Common; using Kreta.Ellenorzo.Domain.VN.Intezmeny; using Kreta.Ellenorzo.Domain.VN.UniqueIdentifier; namespace Kreta.Ellenorzo.BL.VN.Intezmeny { internal static class IntezmenySubqueries { internal static IntezmenyAdatok GetSajatIntezmenyAdatok(DefaultConnectionParameters dcp) { var intezmenyAdatok = new IntezmenyHelper(new DalHandlerConnectionType(new MobileConnectionType(dcp.FelhasznaloId, dcp.IntezmenyId, dcp.IntezmenyAzonosito, dcp.TanevId), dcp.DalHandler)).GetIntezmenyiAdatok(); var response = new IntezmenyAdatok { Uid = new IntezmenyUid(intezmenyAdatok.IntezmenyId), Azonosito = intezmenyAdatok.IntezmenyAzonosito, TeljesNev = intezmenyAdatok.Nev, RovidNev = intezmenyAdatok.RovidNev }; return response; } internal static IntezmenyAdatokDao GetIntezmenyAdatokFromCache(string intezmenyAzonosito) { var cache = MemoryCache.Default; var cacheKey = $"{intezmenyAzonosito}_mobileIntezmenyAdatok"; if (!(cache[cacheKey] is IntezmenyAdatokDao intezmenyAdatok)) { intezmenyAdatok = new IntezmenyAdatokDao(); Dal.MobileConnection.Run( intezmenyAzonosito, null, h => { intezmenyAdatok = h.IntezmenyDal().GetIntezmenyIdAktivTanevIdByAzonosito(intezmenyAzonosito).Tables[0].Rows[0].ToDao(); }); var policy = new CacheItemPolicy { AbsoluteExpiration = new DateTimeOffset(DateTime.Now.AddMinutes(20)) }; cache.Set(cacheKey, intezmenyAdatok, policy); } return intezmenyAdatok; } internal static void RemoveIntezemenyAdatokCache(string intezmenyAzonosito) { _ = MemoryCache.Default.Remove($"{intezmenyAzonosito}_mobileIntezmenyAdatok"); } } }