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,31 @@
using System.Collections.Generic;
namespace Kreta.Framework.Session
{
public class ConnectionManager
{
public virtual void Initialize()
{
}
public virtual IEnumerable<string> GetOsszesIntezmeny()
{
return null;
}
public virtual string GetIntezmenyConnectionString(string intezmenyAzonosito)
{
return SDAServer.Instance.Configuration.DBConnection;
}
public virtual string GetSystemConnectionString(string intezmenyAzonosito)
{
return SDAServer.Instance.Configuration.DBConnection;
}
public virtual IEnumerable<string> GetSystemConnectionStrings()
{
return null;
}
}
}

View file

@ -0,0 +1,121 @@
using System;
using Kreta.Framework.Entities;
namespace Kreta.Framework.Session.Instrumentation
{
public class SessionLogger
{
private const string insertCommandText = @"
INSERT INTO T_FELHASZNALOBELEPESTORTENET (C_SESSIONID, C_SERVERNAME, C_USERIP, C_LOGINDATE, C_LASTACTIVITY, C_FELHASZNALOID, C_GONDVISELOID, SERIAL, CREATED, CREATOR)
VALUES (:pSESSIONID, :pSERVERNAME, :pUSERIP, :pLOGINDATE, :pLASTACTIVITY, :pUSERID, :pTUTELARYID, :pSERIAL, :pCREATED, :pCREATOR)";
private const string insertCommandTextWithIntezmeny = @"
DECLARE @intezmenyId INT = (SELECT ID FROM T_INTEZMENY WHERE C_AZONOSITO = :pIntezmenyAzonosito AND TOROLT = 'F')
DECLARE @tanevId INT = (SELECT ID FROM T_TANEV WHERE TOROLT = 'F' AND C_AKTIV = 'T' AND C_INTEZMENYID = @intezmenyId)
INSERT INTO T_FELHASZNALOBELEPESTORTENET (C_SESSIONID, C_SERVERNAME, C_USERIP, C_LOGINDATE, C_LASTACTIVITY, C_FELHASZNALOID, C_GONDVISELOID, C_INTEZMENYID, C_TANEVID, SERIAL, CREATED, CREATOR)
VALUES (:pSESSIONID, :pSERVERNAME, :pUSERIP, :pLOGINDATE, :pLASTACTIVITY, :pUSERID, :pTUTELARYID, @intezmenyId, @tanevId, :pSERIAL, :pCREATED, :pCREATOR)";
private const string updateCommandText = @"
UPDATE T_FELHASZNALOBELEPESTORTENET SET C_LASTACTIVITY = :pLASTACTIVITY, SERIAL = SERIAL + 1, LASTCHANGED = :pLASTCHANGED, MODIFIER = :pMODIFIER WHERE (C_FELHASZNALOID = :pUSERID and C_SESSIONID = :pSESSIONID)";
private string ConnectionString(string intezmenyAzonosito)
{
return SDAServer.Instance.ConnectionManager.GetIntezmenyConnectionString(intezmenyAzonosito);
}
public void SessionCreated(object sender, SessionEventArgs e)
{
try
{
using (var connection = new SDA.DataProvider.SDAConnection(ConnectionString(e.IntezmenyAzonosito)))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
using (var command = connection.CreateCommand())
{
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = insertCommandText;
if (!string.IsNullOrWhiteSpace(e.IntezmenyAzonosito))
{
command.CommandText = insertCommandTextWithIntezmeny;
command.Parameters.Add("pIntezmenyAzonosito", SDA.DataProvider.SDADBType.String).Value = e.IntezmenyAzonosito;
}
DAUtil.BindParameter(command, "pSESSIONID", SDA.DataProvider.SDADBType.String, 36, e.SessionId, false);
DAUtil.BindParameter(command, "pSERVERNAME", SDA.DataProvider.SDADBType.String, 50, e.ServerName, false);
DAUtil.BindParameter(command, "pUSERIP", SDA.DataProvider.SDADBType.String, 15, e.ClientIP?.Split(':')[0], false);
DAUtil.BindParameter(command, "pLOGINDATE", SDA.DataProvider.SDADBType.DateTime, DateTime.Now, false);
DAUtil.BindParameter(command, "pLASTACTIVITY", SDA.DataProvider.SDADBType.DateTime, DateTime.Now, false);
DAUtil.BindIdParameter(command, "pUSERID", e.FelhasznaloId);
DAUtil.BindParameter(command, "pTUTELARYID", SDA.DataProvider.SDADBType.Int, e.GondviseloId, !e.GondviseloId.HasValue);
command.Parameters.Add("pSERIAL", SDA.DataProvider.SDADBType.Int).Value = 0;
command.Parameters.Add("pCREATED", SDA.DataProvider.SDADBType.DateTime).Value = DateTime.Now;
command.Parameters.Add("pCREATOR", SDA.DataProvider.SDADBType.Int).Value = e.UserUniqueIdentifier;
command.ExecuteNonQuery();
}
transaction.Commit();
}
}
}
catch (Exception exception)
{
try
{
if (SDAServer.Instance != null)
{
SDAServer.Instance.Logger.ExceptionThrown(exception);
}
}
catch
{
}
}
}
public void SessionDeleted(object sender, SessionEventArgs e)
{
try
{
using (var connection = new SDA.DataProvider.SDAConnection(ConnectionString(e.IntezmenyAzonosito)))
{
connection.Open();
using (var transaction = connection.BeginTransaction())
{
using (var command = connection.CreateCommand())
{
command.Connection = connection;
command.Transaction = transaction;
command.CommandText = updateCommandText;
DAUtil.BindParameter(command, "pLASTACTIVITY", SDA.DataProvider.SDADBType.DateTime, DateTime.Now, false);
DAUtil.BindParameter(command, "pSESSIONID", SDA.DataProvider.SDADBType.String, 36, e.SessionId, false);
DAUtil.BindIdParameter(command, "pUSERID", e.FelhasznaloId);
command.Parameters.Add("pLASTCHANGED", SDA.DataProvider.SDADBType.DateTime).Value = DateTime.Now;
command.Parameters.Add("pMODIFIER", SDA.DataProvider.SDADBType.String).Value = e.UserUniqueIdentifier;
command.ExecuteNonQuery();
}
transaction.Commit();
}
}
}
catch (Exception exception)
{
try
{
if (SDAServer.Instance != null)
{
SDAServer.Instance.Logger.ExceptionThrown(exception);
}
}
catch
{
}
}
}
}
}

View file

@ -0,0 +1,14 @@
using Kreta.Framework.Security;
namespace Kreta.Framework.Session
{
public class OrganizationSystemSession : UserContext
{
protected internal const string SessionId = "ORGANIZATION_SYSTEM";
public OrganizationSystemSession(string intezmenyAzonosito) :
base(new LoginInfo(SessionId, 0, "127.0.0.1", int.MaxValue, SessionId, intezmenyAzonosito))
{
}
}
}

View file

@ -0,0 +1,30 @@
using Kreta.Framework.Security;
using SDA.DataProvider;
namespace Kreta.Framework.Session
{
public class ServiceSystemSession : UserContext
{
protected internal const string SessionId = "SERVICE_SYSTEM";
public ServiceSystemSession(string systemConnectionString) :
base(new LoginInfo(SessionId, 0, "127.0.0.1", int.MaxValue, SessionId), new ServiceSystemTransactionContext(systemConnectionString))
{
}
private class ServiceSystemTransactionContext : TransactionContext
{
private string connectionString;
public ServiceSystemTransactionContext(string connectionstring) : base(null)
{
connectionString = connectionstring;
}
internal override SDAConnection CreateConnection()
{
return SDAServer.Instance.CreateConnection(connectionString);
}
}
}
}

View file

@ -0,0 +1,107 @@
using System;
using Kreta.Framework.Security;
namespace Kreta.Framework.Session
{
/// <summary>
/// Provides data for the <see cref="SessionCreated" />, <see cref="SessionDeleted" />, <see cref="SessionActivated"/>, and <see cref="SessionDeactivated"/> events.
/// <see cref="SessionEventargs" /> is the base class for classes containing <see cref="UserContext"/> based session event data.
/// </summary>
public class SessionEventArgs : EventArgs
{
internal SessionEventArgs(LoginInfo loginInfo, string serverName)
{
SessionId = loginInfo.SessionID;
IntezmenyAzonosito = loginInfo.IntezmenyAzonosito;
UserUniqueIdentifier = loginInfo.UniqueIdentifier;
FelhasznaloId = loginInfo.FelhasznaloId;
GondviseloId = loginInfo.GondviseloId;
ClientIP = loginInfo.ClientIP;
ServerName = serverName;
}
public string IntezmenyAzonosito { get; protected set; }
/// <summary>
/// Gets the current session-identifier for the user
/// </summary>
public string SessionId { get; protected set; }
/// <summary>
/// Gets the globally unique user identifier for the user.
/// </summary>
public int UserUniqueIdentifier { get; protected set; }
/// <summary>
/// Gets the user related <see cref="IPAddress"/> information
/// </summary>
public string ClientIP { get; protected set; }
/// <summary>
/// Gets the local user identifier for the user.
/// </summary>
public int FelhasznaloId { get; protected set; }
public int? GondviseloId { get; protected set; }
/// <summary>
/// Gets the server identifier.
/// </summary>
public string ServerName { get; protected set; }
}
/// <summary>
/// Represents the delegate that will handle the <see cref="SessionCreated"/> event
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the <see cref="SessionManager"/> class, the sender is the object that raises the event.</param>
/// <param name="e">A <see cref="SessionEventArgs"/> instance that contains the event data.</param>
/// <remarks>
/// When you create a <see cref="SessionCreatedEventHandler" /> delegate, you identify the method that will handle the event.
/// To associate the event with your event handler, add an instance of the delegate to the event.
/// The event handler is called whenever the event occurs, unless you remove the delegate.
/// </remarks>
public delegate void SessionCreatedEventHandler(object sender, SessionEventArgs e);
/// <summary>
///
/// </summary>
/// <param name="sender">The sender.</param>
/// <param name="e">The <see cref="SessionEventArgs"/> instance containing the event data.</param>
public delegate void SessionAccessEventHandler(object sender, SessionEventArgs e);
/// <summary>
/// Represents the delegate that will handle the <see cref="SessionActivated"/> event
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the <see cref="SessionManager"/> class, the sender is the object that raises the event.</param>
/// <param name="e">A <see cref="SessionEventArgs"/> instance that contains the event data.</param>
/// <remarks>
/// When you create a <see cref="SessionActivatedEventHandler" /> delegate, you identify the method that will handle the event.
/// To associate the event with your event handler, add an instance of the delegate to the event.
/// The event handler is called whenever the event occurs, unless you remove the delegate.
/// </remarks>
public delegate void SessionActivatedEventHandler(object sender, SessionEventArgs e);
/// <summary>
/// Represents the delegate that will handle the <see cref="SessionDeactivated"/> event
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the <see cref="SessionManager"/> class, the sender is the object that raises the event.</param>
/// <param name="e">A <see cref="SessionEventArgs"/> instance that contains the event data.</param>
/// <remarks>
/// When you create a <see cref="SessionDeactivatedEventHandler" /> delegate, you identify the method that will handle the event.
/// To associate the event with your event handler, add an instance of the delegate to the event.
/// The event handler is called whenever the event occurs, unless you remove the delegate.
/// </remarks>
public delegate void SessionDeactivatedEventHandler(object sender, SessionEventArgs e);
/// <summary>
/// Represents the delegate that will handle the <see cref="SessionDeleted"/> event
/// </summary>
/// <param name="sender">The source of the event. When this event is raised by the <see cref="SessionManager"/> class, the sender is the object that raises the event.</param>
/// <param name="e">A <see cref="SessionEventArgs"/> instance that contains the event data.</param>
/// <remarks>
/// When you create a <see cref="SessionDeletedEventHandler" /> delegate, you identify the method that will handle the event.
/// To associate the event with your event handler, add an instance of the delegate to the event.
/// The event handler is called whenever the event occurs, unless you remove the delegate.
/// </remarks>
public delegate void SessionDeletedEventHandler(object sender, SessionEventArgs e);
}

View file

@ -0,0 +1,167 @@
using System;
using Kreta.Framework.Caching;
using Kreta.Framework.Security;
namespace Kreta.Framework.Session
{
public class SessionManager : IDisposable
{
private readonly LoginInfoCache loginInfoCache;
private readonly string serverName;
public event SessionCreatedEventHandler SessionCreated;
public event SessionDeletedEventHandler SessionDeleted;
public bool IsSessionAlive(string sessionid)
{
return loginInfoCache.GetLoginInfo(sessionid) != null;
}
public SessionManager(Configuration configuration, Caching.CacheManager cacheManager)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}
if (configuration.SessionTimeout > int.MaxValue / (1000 * 60) || configuration.SessionTimeout < 0)
{
throw new InvalidConfigurationException("SessionTimeout is out of range.");
}
serverName = configuration.ServerName;
loginInfoCache = cacheManager.AquireCache<LoginInfoCache>();
loginInfoCache.SessionTimeout = configuration.SessionTimeout;
}
public virtual UserContext ActivateSystemSession()
{
var session = new SystemSession();
session.Activate();
return session;
}
public virtual void DeactivateSystemSession()
{
UserContext session = UserContext.Instance;
if (session != null)
{
session.DeActivate();
}
}
public virtual UserContext ActivateServiceSystemSession(string connectionString)
{
var session = new ServiceSystemSession(connectionString);
session.Activate();
return session;
}
public virtual void DeactivateServiceSystemSession()
{
UserContext session = UserContext.Instance;
if (session != null)
{
session.DeActivate();
}
}
public virtual UserContext ActivateOrganizationSystemSession(string organizationIdentifier)
{
var session = new OrganizationSystemSession(organizationIdentifier);
session.Activate();
return session;
}
public virtual void DeactivateOrganizationSystemSession()
{
UserContext session = UserContext.Instance;
if (session != null)
{
session.DeActivate();
}
}
public virtual UserContext ActivateSession(string sessionId)
{
LoginInfo loginInfo = loginInfoCache.GetLoginInfo(sessionId);
if (loginInfo == null)
{
throw new InvalidSessionException(sessionId, SessionReason.NOT_EXISTS);
}
var session = new UserContext(loginInfo);
session.Activate();
return session;
}
public void DeActivateSession(string sessionId)
{
LoginInfo loginInfo = loginInfoCache.GetLoginInfo(sessionId);
if (loginInfo == null)
{
throw new InvalidSessionException(sessionId, SessionReason.NOT_EXISTS);
}
var session = UserContext.Instance;
if (session != null)
{
session.DeActivate();
}
}
public void CreateSession(LoginInfo loginInfo)
{
if (loginInfoCache.IsExistsLoginInfo(loginInfo.SessionID))
{
throw new InvalidSessionException(loginInfo.SessionID, SessionReason.EXISTS);
}
loginInfoCache.PutLoginInfo(loginInfo);
DoSessionCreated(loginInfo, serverName);
}
protected virtual void DoSessionCreated(LoginInfo loginInfo, string serverName)
{
SessionCreated?.Invoke(this, new SessionEventArgs(loginInfo, serverName));
}
public void PingSession(string sessionId)
{
loginInfoCache.Ping(sessionId);
}
public void DeleteSession(string sessionId)
{
LoginInfo loginInfo = loginInfoCache.GetLoginInfo(sessionId);
if (loginInfo == null)
{
return;
}
loginInfoCache.RemoveLoginInfo(sessionId);
DeleteSession(loginInfo);
}
public void DeleteSession(LoginInfo loginInfo)
{
DoSessionDeleted(loginInfo, serverName);
}
protected virtual void DoSessionDeleted(LoginInfo loginInfo, string serverName)
{
SessionDeleted?.Invoke(this, new SessionEventArgs(loginInfo, serverName));
}
public void Dispose()
{
GC.SuppressFinalize(this);
}
}
}

View file

@ -0,0 +1,28 @@
using Kreta.Framework.Security;
using SDA.DataProvider;
namespace Kreta.Framework.Session
{
public class SystemSession : UserContext
{
protected internal const string SessionId = "SYSTEM";
public SystemSession() :
base(new LoginInfo(SessionId, 0, "127.0.0.1", int.MaxValue, SessionId), new SystemTransactionContext(SDAServer.Instance.GetOrganizationIdentifier()))
{
}
private class SystemTransactionContext : TransactionContext
{
public SystemTransactionContext(string intezmenyAzonosito) : base(intezmenyAzonosito)
{
}
internal override SDAConnection CreateConnection()
{
var connectionString = SDAServer.Instance.GetSystemConnectionString(IntezmenyAzonosito);
return SDAServer.Instance.CreateConnection(connectionString);
}
}
}
}

View file

@ -0,0 +1,232 @@
using System;
using System.Data;
using SDA.DataProvider;
namespace Kreta.Framework
{
/// <summary>
/// Adatbázis ügylet kontextus.
/// </summary>
public class TransactionContext : IDisposable
{
private static object SyncObject = new object();
private SDAConnection dbConnection;
private SDATransaction dbTransaction;
private bool IsTransactional { get; set; }
private bool IsLocked { get; set; }
protected string IntezmenyAzonosito { get; set; }
/// <summary>
/// Az osztály alapértelmezett konstruktora.
/// </summary>
public TransactionContext(string intezmenyAzonosito) : this(intezmenyAzonosito, true)
{
}
/// <summary>
/// Az osztály konstruktora.
/// </summary>
/// <param name="isTransactional">Tranzakciós legyen-e a kontextus, vagy sem.</param>
public TransactionContext(string intezmenyAzonosito, bool isTransactional)
{
IsTransactional = isTransactional;
IntezmenyAzonosito = intezmenyAzonosito;
}
#region Belső dolgok
internal virtual SDAConnection CreateConnection()
{
if (!string.IsNullOrWhiteSpace(IntezmenyAzonosito))
{
var connectionString = SDAServer.Instance.GetIntezmenyConnectionString(IntezmenyAzonosito);
return SDAServer.Instance.CreateConnection(connectionString);
}
return SDAServer.Instance.CreateConnection();
}
private void Prepare()
{
DoPrepareConnection();
DoPrepareTransaction();
}
private void DoPrepareConnection()
{
if (dbConnection == null)
{
dbConnection = CreateConnection();
dbConnection.Open();
}
else
{
if (dbConnection.State == ConnectionState.Closed)
{
// Ide nem kéne bejönnie...
dbConnection.Open();
}
}
}
private void DoPrepareTransaction()
{
if (IsTransactional && dbTransaction == null)
{
dbTransaction = dbConnection.BeginTransaction();
}
}
private void DisposeTransaction()
{
if (dbTransaction != null)
{
try
{
dbTransaction.Dispose();
}
finally
{
dbTransaction = null;
}
}
}
private void CloseLocked()
{
}
private void CloseNotLocked()
{
DisposeTransaction();
if (dbConnection != null)
{
try
{
dbConnection.Dispose();
}
finally
{
dbConnection = null;
}
}
}
#endregion
#region Nyilvános felület
/// <summary>
/// Zárolja a munkamenet ügyletét, így a munkamenet passziválásakor nem fog elveszni.
/// </summary>
public bool Lock()
{
lock (SyncObject)
{
if (IsLocked)
{
return false;
}
IsLocked = true;
return true;
}
}
/// <summary>
/// Feloldja a munkamenet ügyletének zárolását.
/// </summary>
public void Unlock()
{
lock (SyncObject)
{
IsLocked = false;
}
}
/// <summary>
/// A munkamenethez tartozó adatbáziskapcsolat.
/// </summary>
public SDAConnection DBConnection
{
get
{
Prepare();
return dbConnection;
}
}
/// <summary>
/// A munkamenethez tartozó ügylet.
/// </summary>
public SDATransaction DBTransaction
{
get
{
Prepare();
return dbTransaction;
}
}
/// <summary>
/// Jóváhagyja az ügyletet.
/// </summary>
public void Commit()
{
if (IsTransactional && !IsLocked && dbTransaction != null)
{
dbTransaction.Commit();
DisposeTransaction();
}
}
/// <summary>
/// Visszagörgeti az ügyletet.
/// </summary>
public void Rollback()
{
if (IsTransactional && dbTransaction != null)
{
dbTransaction.Rollback();
DisposeTransaction();
DoPrepareTransaction();
}
}
/// <summary>
/// Lezárja a kontextust.
/// </summary>
public void Close()
{
if (dbConnection == null && dbTransaction == null)
{
return;
}
if (IsLocked)
{
CloseLocked();
}
else
{
CloseNotLocked();
}
}
/// <summary>
/// Lezárja a kontextust.
/// </summary>
public void Dispose()
{
Close();
GC.SuppressFinalize(this);
}
#endregion
}
}

View file

@ -0,0 +1,234 @@
using System;
using System.Text;
using System.Web;
using Kreta.Framework.Caching;
using Kreta.Framework.Security;
using SDA.DataProvider;
namespace Kreta.Framework
{
/// <summary>
/// Az osztály biztosítja a felhasználói muveletek elvégzéséhez szükséges környezetet.
/// Ide van kivezetve minden olyan metódus és változó, amire a futás során szükség lehet.
/// </summary>
public class UserContext
{
[ThreadStatic]
private static UserContext instance;
private readonly LoginInfoCache loginInfoCache;
public UserContext(LoginInfo loginInfo) : this(loginInfo, new TransactionContext(loginInfo.IntezmenyAzonosito))
{
}
public UserContext(LoginInfo loginInfo, TransactionContext transactionContext)
{
LoginInfo = loginInfo;
LastAccess = DateTime.Now;
LanguageContext = new LanguageContext(LanguageContext.DefaultLanguageContext.LCID);
TransactionContext = transactionContext;
loginInfoCache = SDAServer.Instance.CacheManager.AquireCache<LoginInfoCache>();
}
public override string ToString()
{
StringBuilder sb = new StringBuilder();
sb.Append("SessionId: ").Append(SessionID).Append('\n');
sb.Append("ClientIp: ").Append(ClientIP).Append('\n');
sb.Append("UserId: ").Append(FelhasznaloId).Append('\n');
sb.Append("LastAccess: ").Append(LastAccess).Append('\n');
return sb.ToString();
}
public TransactionContext TransactionContext { get; }
public LanguageContext LanguageContext { get; }
public LoginInfo LoginInfo { get; }
public int IntezmenyId => LoginInfo.IntezmenyId;
public int AktivTanevId => LoginInfo.AktivTanevId;
public int SelectedTanevId => LoginInfo.SelectedTanevId;
public string IntezmenyAzonosito => LoginInfo.IntezmenyAzonosito;
public int UniqueIdentifier => LoginInfo.UniqueIdentifier;
public string SessionID => LoginInfo.SessionID;
public int FelhasznaloId => LoginInfo.FelhasznaloId;
public string ClientIP => LoginInfo.ClientIP;
public void SetIntezmenyEsTanev(int intezmenyId, int aktivTanevId, int selectedTanevId)
{
LoginInfo.IntezmenyId = intezmenyId;
SetTanev(aktivTanevId, selectedTanevId);
}
public void SetTanev(int aktivTanevId, int selectedTanevId)
{
LoginInfo.AktivTanevId = aktivTanevId;
LoginInfo.SelectedTanevId = selectedTanevId;
UpdateLoginInfoCache();
}
public void SetFelhasznaloId(int felhasznaloId)
{
LoginInfo.FelhasznaloId = felhasznaloId;
LoginInfo.UniqueIdentifier = felhasznaloId;
UpdateLoginInfoCache();
}
public void SetSelectedTanevId(int selectedTanevId)
{
LoginInfo.SelectedTanevId = selectedTanevId;
UpdateLoginInfoCache();
}
private void UpdateLoginInfoCache()
{
if (loginInfoCache.IsExistsLoginInfo(SessionID))
{
loginInfoCache.UpdateLoginInfo(LoginInfo);
}
}
public bool Activated { get; private set; }
public DateTime LastAccess { get; set; }
/// <summary>
/// Visszadja az aktuális szálhoz tartozó UserContext példányt.
/// Ha nincs ilyen, akkor null-t ad vissza.
/// </summary>
public static UserContext Instance
{
get
{
if (HttpContext.Current != null)
{
return HttpContext.Current.Items[nameof(UserContext)] as UserContext;
}
return instance;
}
}
#region Módszerek
/// <summary>
/// Aktíválja a munkamenetet.
/// </summary>
public virtual void Activate()
{
LastAccess = DateTime.Now;
var userContext = this;
if (HttpContext.Current != null && !HttpContext.Current.Items.Contains(nameof(UserContext)))
{
HttpContext.Current.Items.Add(nameof(UserContext), userContext);
}
else
{
instance = userContext;
}
if (!userContext.Activated)
{
userContext.Activated = true;
}
}
/// <summary>
/// Passzíválja a munkamenetet.
/// </summary>
public virtual void DeActivate()
{
LastAccess = DateTime.Now;
var userContext = this;
if (HttpContext.Current != null && HttpContext.Current.Items.Contains(nameof(UserContext)))
{
userContext = HttpContext.Current.Items[nameof(UserContext)] as UserContext;
HttpContext.Current.Items.Remove(nameof(UserContext));
}
else
{
instance = null;
}
userContext.TransactionContext.Close();
userContext.Activated = false;
}
#endregion
#region Ügylet kezelés
/// <summary>
/// Feloldja a munkamenet ügyletének zárolását.
/// </summary>
/// <param name="commit">A ügyletet elkövesse, vagy visszagörgesse.</param>
internal void UnlockTransaction(bool commit)
{
TransactionContext.Unlock();
if (commit)
{
TransactionContext.Commit();
}
else
{
TransactionContext.Rollback();
}
}
/// <summary>
/// Jóváhagyja a munkamenethez tartozó ügyletet.
/// </summary>
public void CommitTransaction()
{
TransactionContext.Commit();
}
/// <summary>
/// Visszagörgeti a munkamenethez tartozó ügyletet.
/// </summary>
public void RollbackTransaction()
{
TransactionContext.Rollback();
}
/// <summary>
/// A munkamenethez tartozó adatbáziskapcsolat.
/// </summary>
public SDAConnection SDAConnection
{
get
{
return TransactionContext.DBConnection;
}
}
/// <summary>
/// A munkamenethez tartozó ügylet.
/// </summary>
public SDATransaction SDATransaction
{
get
{
return TransactionContext.DBTransaction;
}
}
#endregion
}
}