149 lines
3.8 KiB
C#
149 lines
3.8 KiB
C#
using System;
|
|
using Kreta.Core;
|
|
using Kreta.Framework;
|
|
|
|
namespace Kreta.DataAccessManual.Util
|
|
{
|
|
internal class Connection : ConnectionBase
|
|
{
|
|
public Connection(string sessionId) : base(sessionId)
|
|
{
|
|
activatedByMe = ActivateSession();
|
|
}
|
|
|
|
protected override bool ActivateSession()
|
|
{
|
|
return DataUtil.ActivateSession(this.SessionId);
|
|
}
|
|
|
|
protected override void DeactivateSession()
|
|
{
|
|
DataUtil.DeactivateSession(SessionId);
|
|
}
|
|
}
|
|
|
|
internal class OrganizationConnection : ConnectionBase
|
|
{
|
|
private readonly string intezmenyAzonosito;
|
|
|
|
public OrganizationConnection(string intezmenyAzonosito) : base(string.Empty)
|
|
{
|
|
this.intezmenyAzonosito = intezmenyAzonosito;
|
|
activatedByMe = ActivateSession();
|
|
}
|
|
|
|
protected override bool ActivateSession()
|
|
{
|
|
return DataUtil.ActivateOrganizationSystemSession(intezmenyAzonosito);
|
|
}
|
|
|
|
protected override void DeactivateSession()
|
|
{
|
|
DataUtil.DeactivateOrganizationSystemSession();
|
|
}
|
|
}
|
|
|
|
internal class MobileConnection : ConnectionBase
|
|
{
|
|
private readonly string intezmenyAzonosito;
|
|
|
|
public MobileConnection(string intezmenyAzonosito, int? tanevId, int? felhasznaloId) : base(string.Empty)
|
|
{
|
|
this.intezmenyAzonosito = intezmenyAzonosito;
|
|
activatedByMe = ActivateSession();
|
|
|
|
if (tanevId.IsEntityId())
|
|
{
|
|
UserContext.Instance.SetTanev(tanevId.Value, tanevId.Value);
|
|
}
|
|
if (felhasznaloId.IsEntityId())
|
|
{
|
|
UserContext.Instance.SetFelhasznaloId(felhasznaloId.Value);
|
|
}
|
|
}
|
|
|
|
protected override bool ActivateSession()
|
|
{
|
|
return DataUtil.ActivateMobileSession(intezmenyAzonosito);
|
|
}
|
|
|
|
protected override void DeactivateSession()
|
|
{
|
|
DataUtil.DeactivateMobileSession();
|
|
}
|
|
}
|
|
|
|
internal class SystemConnection : ConnectionBase
|
|
{
|
|
public SystemConnection() : base(string.Empty)
|
|
{
|
|
activatedByMe = ActivateSession();
|
|
}
|
|
|
|
protected override bool ActivateSession()
|
|
{
|
|
return DataUtil.ActivateSystemSession();
|
|
}
|
|
|
|
protected override void DeactivateSession()
|
|
{
|
|
DataUtil.DeactivateSystemSession();
|
|
}
|
|
}
|
|
|
|
internal class ServiceSystemConnection : ConnectionBase
|
|
{
|
|
private readonly string connectionString;
|
|
|
|
public ServiceSystemConnection(string connectionString) : base(string.Empty)
|
|
{
|
|
this.connectionString = connectionString;
|
|
activatedByMe = ActivateSession();
|
|
}
|
|
|
|
protected override bool ActivateSession()
|
|
{
|
|
return DataUtil.ActivateServiceSystemSession(connectionString);
|
|
}
|
|
|
|
protected override void DeactivateSession()
|
|
{
|
|
DataUtil.DeactivateServiceSystemSession();
|
|
}
|
|
}
|
|
|
|
internal abstract class ConnectionBase : IDisposable
|
|
{
|
|
/*TODO: ezek törölhetőek lesznek ha majd kikopik a helperes Session aktiváció*/
|
|
protected bool activatedByMe = false;
|
|
|
|
protected readonly string SessionId;
|
|
|
|
internal ConnectionBase(string sessionId)
|
|
{
|
|
this.SessionId = sessionId;
|
|
}
|
|
|
|
protected virtual bool ActivateSession()
|
|
{
|
|
return false;
|
|
}
|
|
|
|
protected virtual void DeactivateSession()
|
|
{
|
|
}
|
|
|
|
~ConnectionBase()
|
|
{
|
|
Dispose();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
if (activatedByMe)
|
|
{
|
|
DeactivateSession();
|
|
}
|
|
}
|
|
}
|
|
}
|