This commit is contained in:
skidoodle 2024-03-13 00:33:46 +01:00
commit e124a47765
19374 changed files with 9806149 additions and 0 deletions

View file

@ -0,0 +1,752 @@
using System;
using System.Runtime.Caching;
using System.Xml;
using Kreta.BusinessLogic.Classes;
using Kreta.BusinessLogic.Helpers;
using Kreta.Core;
using Kreta.Core.ConnectionType;
using Kreta.Enums.ManualEnums;
using Kreta.Web.Helpers;
using Kreta.Web.Security;
namespace Kreta.Web.Utils
{
public static class ProfileUtils
{
private static readonly CacheItemPolicy DefaultCacheItemPolicy = new CacheItemPolicy { SlidingExpiration = TimeSpan.FromMinutes(60) };
private static string GetUserProfileDocumentCacheKey(string sessionId)
{
return $"{nameof(UserProfileDocument)}_{sessionId}";
}
private static string GetUserProfileImageCacheKey(string sessionId)
{
return $"{nameof(UserProfileImage)}_{sessionId}";
}
private static XmlDocument UserProfileDocument
{
get
{
string userProfileDocumentCacheKey = GetUserProfileDocumentCacheKey(ClaimData.SessionId);
XmlDocument userProfileDocument = Cache.Get(userProfileDocumentCacheKey) as XmlDocument;
if (userProfileDocument == null)
{
userProfileDocument = new FelhasznaloHelper(ConnectionTypeExtensions.GetSessionConnectionType()).GetUserProfileDocument();
Cache.Add(userProfileDocumentCacheKey, userProfileDocument, DefaultCacheItemPolicy);
}
return userProfileDocument;
}
}
public static void SaveUserProfileDocument()
{
var doc = UserProfileDocument;
var xml = doc.InnerXml;
if (!string.IsNullOrWhiteSpace(xml))
{
var helper = new FelhasznaloHelper(new SessionConnectionType(ClaimData.SessionId, ClaimData.FelhasznaloId, ClaimData.IntezmenyId, ClaimData.IntezmenyAzonosito, ClaimData.AktivTanevID.Value));
helper.SetProfile(xml);
}
RemoveUserProfileDocument(ClaimData.SessionId);
}
public static void RemoveUserProfileDocument(string sessionId) => Cache.Remove(GetUserProfileDocumentCacheKey(sessionId));
public static string UserProfileImage
{
get
{
string userProfileImageCacheKey = GetUserProfileImageCacheKey(ClaimData.SessionId);
string userProfileImage = Cache.Get(userProfileImageCacheKey) as string;
if (userProfileImage == null)
{
var helper = new FelhasznaloHelper(new SessionConnectionType(ClaimData.SessionId, ClaimData.FelhasznaloId, ClaimData.IntezmenyId, ClaimData.IntezmenyAzonosito, ClaimData.AktivTanevID.Value));
userProfileImage = helper.ProfileKep();
Cache.Add(userProfileImageCacheKey, userProfileImage, DefaultCacheItemPolicy);
}
return userProfileImage;
}
set
{
string userProfileImageCacheKey = GetUserProfileImageCacheKey(ClaimData.SessionId);
Cache.Set(userProfileImageCacheKey, value, DefaultCacheItemPolicy);
}
}
public static void RemoveUserProfileImage(string sessionId) => Cache.Remove(GetUserProfileImageCacheKey(sessionId));
public static void UpdateProfile(string FullControlID, string text)
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/Controls") == null)
{
//doc.DocumentElement.AppendChild(doc.CreateNode(System.Xml.XmlNodeType.Element, "Web", ""));
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(System.Xml.XmlNodeType.Element, "Controls", ""));
}
//regi tipusu profile torlese
if (doc.SelectNodes("UserProfile/Controls/*[not (@ID)]").Count > 0)
{
doc.SelectSingleNode("UserProfile/Controls").InnerXml = "";
}
XmlNode node = doc.SelectSingleNode(string.Format("UserProfile/Controls/c[@ID='{0}']", FullControlID));
//ha nincs még ez a control eltárolva
if (node == null)
{
XmlNode newnode = doc.CreateNode(System.Xml.XmlNodeType.Element, "c", "");
XmlAttribute attr = doc.CreateAttribute("ID");
attr.InnerXml = FullControlID;
newnode.Attributes.Append(attr);
node = doc.SelectSingleNode("UserProfile/Controls").AppendChild(newnode);
}
node.InnerXml = text;
SaveUserProfileDocument();
}
public static bool HideTips
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/HideTips");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/HideTips") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "HideTips", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/HideTips");
node.InnerXml = value.ToString();
}
}
public static bool EmailHelyettesites
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/EmailHelyettesites");
if (node == null)
{
return true;
}
bool result;
return (bool.TryParse(node.InnerText, out result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/EmailHelyettesites") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "EmailHelyettesites", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/EmailHelyettesites");
node.InnerXml = value.ToString();
}
}
public static bool IsHianyzokAutoKitoltesEnabled
{
get => GetIsHianyzokAutoKitoltesEnabled();
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/HianyzokAutoKitoltes") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "HianyzokAutoKitoltes", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/HianyzokAutoKitoltes");
node.InnerXml = value.ToString();
}
}
/// INFO @DevKornel: Mobil használja
public static bool GetIsHianyzokAutoKitoltesEnabled(int? felhasznaloId = null)
{
if (!felhasznaloId.HasValue)
{
felhasznaloId = ClaimData.FelhasznaloId;
}
if (felhasznaloId < 1)
{
return false;
}
try
{
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/HianyzokAutoKitoltes");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
catch (ArgumentNullException)
{
//mobilos hívásnál nem elérhető a userprofiledocument, emiatt elnyeljük az Exceptiont
return true;
}
}
public static bool FogadooraEmail
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmail");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmail") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmail", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmail");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmailUj
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmailUj");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmailUj") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmailUj", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmailUj");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmailJelentkezes
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmailJelentkezes");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmailJelentkezes") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmailJelentkezes", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmailJelentkezes");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmailJelentkezesLemondas
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmailJelentkezesLemondas");
if (node == null)
{
return false;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmailJelentkezesLemondas") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmailJelentkezesLemondas", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmailJelentkezesLemondas");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmlekeztetoEmailJelentkezes
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmlekeztetoEmailJelentkezes");
if (node == null)
{
return false;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmlekeztetoEmailJelentkezes") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmlekeztetoEmailJelentkezes", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmlekeztetoEmailJelentkezes");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmailTorles
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmailTorles");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmailTorles") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmailTorles", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmailTorles");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmail3Nappal
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmail3Nappal");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmail3Nappal") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmail3Nappal", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmail3Nappal");
node.InnerXml = value.ToString();
}
}
public static bool FogadooraEmail1Nappal
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return false;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/FogadooraEmail1Nappal");
if (node == null)
{
return true;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/FogadooraEmail1Nappal") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "FogadooraEmail1Nappal", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/FogadooraEmail1Nappal");
node.InnerXml = value.ToString();
}
}
public static bool NemNaplozottTanorakEmail
{
get
{
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/NemNaplozottTanorakEmail");
if (ClaimData.FelhasznaloId < 1 || node == null)
{
return false;
}
return (bool.TryParse(node.InnerText, out bool result)) && result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/NemNaplozottTanorakEmail") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "NemNaplozottTanorakEmail", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/NemNaplozottTanorakEmail");
node.InnerXml = value.ToString();
}
}
public static AtlagMegjelenitesTipus AtlagMegjelenitesTipusa
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return AtlagMegjelenitesTipus.OsszesJegy;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/AtlagMegjelenitesTipusa");
if (node == null)
{
return AtlagMegjelenitesTipus.OsszesJegy;
}
var tipus = node.InnerText.ToEnum(AtlagMegjelenitesTipus.OsszesJegy);
return tipus;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/AtlagMegjelenitesTipusa") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "AtlagMegjelenitesTipusa", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/AtlagMegjelenitesTipusa");
node.InnerXml = value.ToString();
}
}
public static AtlagbaBeleszamitoOsztalyTipus AtlagbaBeleszamitoOsztalyTipusa
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return AtlagbaBeleszamitoOsztalyTipus.OsztalyCsoportValahaKapottJegyeinekAtlaga;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/AtlagbaBeleszamitoOsztalyTipusa");
if (node == null)
{
return AtlagbaBeleszamitoOsztalyTipus.OsztalyCsoportValahaKapottJegyeinekAtlaga;
}
var tipus = node.InnerText.ToEnum(AtlagbaBeleszamitoOsztalyTipus.OsztalyCsoportValahaKapottJegyeinekAtlaga);
return tipus;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/AtlagbaBeleszamitoOsztalyTipusa") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "AtlagbaBeleszamitoOsztalyTipusa", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/AtlagbaBeleszamitoOsztalyTipusa");
node.InnerXml = value.ToString();
}
}
public static HaladasiNaploFulTipus HaladasiNaploFulTipusa
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return HaladasiNaploFulTipus.Tanorak;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/HaladasiNaploFulTipusa");
if (node == null)
{
return HaladasiNaploFulTipus.Tanorak;
}
var tipus = node.InnerText.ToEnum(HaladasiNaploFulTipus.Tanorak);
return tipus;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/HaladasiNaploFulTipusa") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "HaladasiNaploFulTipusa", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/HaladasiNaploFulTipusa");
node.InnerXml = value.ToString();
}
}
public static HaladasiNaploNezetTipus HaladasiNaploNezetTipusa
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return HaladasiNaploNezetTipus.MunkaHet;
}
XmlNode node = UserProfileDocument.SelectSingleNode("UserProfile/HaladasiNaploNezetTipusa");
if (node == null)
{
return HaladasiNaploNezetTipus.MunkaHet;
}
var tipus = node.InnerText.ToEnum(HaladasiNaploNezetTipus.MunkaHet);
return tipus;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/HaladasiNaploNezetTipusa") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "HaladasiNaploNezetTipusa", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/HaladasiNaploNezetTipusa");
node.InnerXml = value.ToString();
}
}
public static bool HetirendMegjeleniteseBelepeskor
{
get
{
if (ClaimData.FelhasznaloId < 1)
{
return true;
}
XmlNode node = UserProfileDocument?.SelectSingleNode("UserProfile/HetirendMegjeleniteseBelepeskor");
if (node == null)
{
return true;
}
return !bool.TryParse(node.InnerText, out bool result) || result;
}
set
{
var doc = UserProfileDocument;
if (doc.SelectSingleNode("UserProfile") == null)
{
XmlElement el = doc.CreateElement("UserProfile");
doc.AppendChild(el);
}
if (doc.SelectSingleNode("UserProfile/HetirendMegjeleniteseBelepeskor") == null)
{
doc.SelectSingleNode("UserProfile").AppendChild(doc.CreateNode(XmlNodeType.Element, "HetirendMegjeleniteseBelepeskor", ""));
}
XmlNode node = doc.SelectSingleNode("UserProfile/HetirendMegjeleniteseBelepeskor");
node.InnerXml = value.ToString();
}
}
}
}