private void activateSession(Session session) { // Deactivate the current session if (_currentSession != null) { _currentSession.Deactivate(); } // Make the given session the current session _currentSession = session; // Activate the new current session if (_currentSession != null) { _currentSession.Activate(); } }
private async Task TestSession(Session session) { await Task.Run(() => { using (session.Activate()) using (var transacion = session.OpenTransaction()) { Assert.That(Session.Current, Is.Not.Null); Assert.That(Session.Current, Is.EqualTo(session)); var entity = new TestEntity(session); session.SaveChanges(); session.Query.All <TestEntity>().First(); entity.Remove(); session.SaveChanges(); } }); }
public void External( bool first, IsolationLevel?isolationLevel, TransactionOpenMode?transactionOpenMode, Action <bool, IsolationLevel?, TransactionOpenMode?> action) { using (Session session = domain.OpenSession()) using (Xtensive.Orm.TransactionScope tran = isolationLevel == null ? null : session.OpenTransaction()) using (session.Activate()) { if (tran != null) { session.EnsureTransactionIsStarted(); new Bar2(session, DateTime.Now, Guid.NewGuid()) { Name = Guid.NewGuid().ToString() }; } if (first) { if (wait1 != null && wait2 != null) { wait1.Set(); wait2.WaitOne(); } } else if (wait1 != null && wait2 != null) { wait2.Set(); wait1.WaitOne(); } action(first, isolationLevel, transactionOpenMode); if (tran != null) { tran.Complete(); } } }
public void SetUp() { session = Domain.OpenSession(); scope = session.Activate(); }
public void HandleSessionRequest(Activity activity, Session session) { Debug.WriteLine("HandleSessionRequest"); session.Activate(callback: null); }
public override void Handle(Server sender, InPacket packetReader) { ushort errorCode = packetReader.ReadUshort(); if (Enum.IsDefined(typeof(PlayerAuthorizationErrorCodes), errorCode)) { PlayerAuthorizationErrorCodes enumErrorCode = (PlayerAuthorizationErrorCodes)errorCode; uint targetId = packetReader.ReadUint(); switch (enumErrorCode) { // A new player logs in. case PlayerAuthorizationErrorCodes.Login: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (!session.IsActivated) { session.Activate((byte)sender.ID); sender.Send(new Packets.Internal.PlayerAuthorization(session)); } else { sender.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.SessionAlreadyActivated, targetId)); } } else { sender.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId)); } break; } // Update the information of a player. case PlayerAuthorizationErrorCodes.Update: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { /* Packet Structure v2 * * Connection Time * Ping * * [Sub Type] * - 1 - Update Channel * - 2 - Update Session Information * - 3 - Update Action * - 4 - Update Lobby Room information * - 5 - Update Ingame Room information * * [Data Blocks] * - [1] - Update Channel * - Current channel Id * - Channel Slot * * - [2] - Update Session Information * - Session - Kills * - Session - Deaths * - Session - Xp Earned * - Session - Dinar Earned * - Session - Dinar Spend * * - [3] - Update Action * - Update Type: * * [1]: Join Room * - Room ID * - Room Slot * - Room Is Master * * [2]: Leave Room * - Room ID * - Room Old Slot * - Room Was Master? * - New master slot * * [3]: Room Start * - Team * * [4]: Room Stop * - Kills * - Deaths * - Flags * - Points * - Xp Earned * - Dinar Earned * - xp Bonusses (%-Name:%-Name) * - dinar bonusses (%-Name:%-Name) * * - [4] - Update Lobby Room information * - Update Type: * * [1]: Switch Side * - Room ID * - Room Slot * - Room Is Master * * [2]: * * - [5] - Update Ingame Room information * - Update Type: * * [1]: Score Update (Player Kill/Player Death) * - Room ID * - Room Kills * - Room Deaths * - Room Flags * - Room Points * * [2]: */ } else { // Force a closure of the connection. sender.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId)); } break; } // A player logs out of the server. case PlayerAuthorizationErrorCodes.Logout: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (session.IsActivated) { session.End(); } } break; } default: { // Unused. break; } } } else { Console.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode)); } }
protected override void Process(Entities.Server s) { ushort errorCode = GetUShort(0); if (Enum.IsDefined(typeof(Core.Networking.ErrorCodes), errorCode)) { Core.Networking.ErrorCodes enumErrorCode = (Core.Networking.ErrorCodes)errorCode; uint targetId = GetuInt(1); string username = GetString(3); byte accessLevel = GetByte(4); switch (enumErrorCode) { // A new player logs in. //Raptor 1/6/18: Added more checks just in case someone managed to perform a MiM while another player is choosing server. //That would lead to a registered, not active session which could be stolen if targetId is known case Core.Networking.ErrorCodes.Success: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (!session.IsActivated && session.Name == username && (byte)session.AccessLevel == accessLevel) { session.Activate((byte)s.ID); s.Send(new Packets.Internal.PlayerAuthentication(session)); } else { s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.EntityAlreadyAuthorized, targetId)); } } else { s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.InvalidKeyOrSession, targetId)); } break; } // Update the information of a player. //TODO: DARK INVESTIGATE THIS case Core.Networking.ErrorCodes.Update: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { } else { // Force a closure of the connection. s.Send(new Packets.Internal.PlayerAuthentication(Core.Networking.ErrorCodes.InvalidKeyOrSession, targetId)); } break; } // A player logs out of the server. case Core.Networking.ErrorCodes.EndConnection: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (session.IsActivated) { session.End(); } } break; } default: { // Unused. break; } } } else { Console.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode)); } }
protected override void Process(Entities.Server s) { ushort errorCode = GetUShort(0); if (Enum.IsDefined(typeof(PlayerAuthorizationErrorCodes), errorCode)) { PlayerAuthorizationErrorCodes enumErrorCode = (PlayerAuthorizationErrorCodes)errorCode; uint targetId = GetuInt(1); string username = GetString(3); byte accessLevel = GetByte(4); switch (enumErrorCode) { // A new player logs in. //Raptor 1/6/18: Added more checks just in case someone managed to perform a MiM while another player is choosing server. //That would lead to a registered, not active session which could be stolen if targetId is known case PlayerAuthorizationErrorCodes.Login: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (!session.IsActivated && session.Name == username && session.AccessLevel == accessLevel) { session.Activate((byte)s.ID); s.Send(new Packets.Internal.PlayerAuthorization(session)); ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "Player with ID " + targetId.ToString() + " has been authorized"); } else { s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.SessionAlreadyActivated, targetId)); ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, "Player with ID " + targetId.ToString() + " was not authorized because the session is already active"); } } else { s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId)); ServerLogger.Instance.Append(ServerLogger.AlertLevel.ServerError, "Player with ID " + targetId.ToString() + "rejected because the session is NOT valid"); } break; } // Update the information of a player. //TODO: DARK INVESTIGATE THIS case PlayerAuthorizationErrorCodes.Update: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { /* Packet Structure v2 * * Connection Time * Ping * * [Sub Type] * - 1 - Update Channel * - 2 - Update Session Information * - 3 - Update Action * - 4 - Update Lobby Room information * - 5 - Update Ingame Room information * * [Data Blocks] * - [1] - Update Channel * - Current channel Id * - Channel Slot * * - [2] - Update Session Information * - Session - Kills * - Session - Deaths * - Session - Xp Earned * - Session - Dinar Earned * - Session - Dinar Spend * * - [3] - Update Action * - Update Type: * * [1]: Join Room * - Room ID * - Room Slot * - Room Is Master * * [2]: Leave Room * - Room ID * - Room Old Slot * - Room Was Master? * - New master slot * * [3]: Room Start * - Team * * [4]: Room Stop * - Kills * - Deaths * - Flags * - Points * - Xp Earned * - Dinar Earned * - xp Bonusses (%-Name:%-Name) * - dinar bonusses (%-Name:%-Name) * * - [4] - Update Lobby Room information * - Update Type: * * [1]: Switch Side * - Room ID * - Room Slot * - Room Is Master * * [2]: * * - [5] - Update Ingame Room information * - Update Type: * * [1]: Score Update (Player Kill/Player Death) * - Room ID * - Room Kills * - Room Deaths * - Room Flags * - Room Points * * [2]: */ } else { // Force a closure of the connection. s.Send(new Packets.Internal.PlayerAuthorization(PlayerAuthorizationErrorCodes.InvalidSession, targetId)); } break; } // A player logs out of the server. case PlayerAuthorizationErrorCodes.Logout: { Session session = Managers.SessionManager.Instance.Get(targetId); if (session != null) { if (session.IsActivated) { session.End(); ServerLogger.Instance.Append(ServerLogger.AlertLevel.Information, "Player with ID " + targetId.ToString() + " has logged out"); } } break; } default: { // Unused. break; } } } else { Console.WriteLine(string.Concat("Unknown PlayerAuthorization error: ", errorCode)); } }
/// <summary> /// Execute task. /// </summary> /// <typeparam name="T">Task return type.</typeparam> /// <param name="context">The context of this task.</param> /// <returns> /// Task result. /// </returns> public virtual T Execute <T>(ExecutionContext <T> context) { int i = 0; while (true) { Session session = null; TransactionScope tran = null; bool needBreak = false; Transaction transaction = null; try { T result; SessionScope sessionScope = null; try { try { IsolationLevel isolationLevel = context.IsolationLevel; SystemTransaction currentTransaction = SystemTransaction.Current; if (isolationLevel == IsolationLevel.Unspecified && currentTransaction != null) { isolationLevel = currentTransaction.IsolationLevel; } session = SessionScope.CurrentSession; if (session == null) { session = context.Domain.OpenSession(); sessionScope = session.Activate(); } if (currentTransaction != null && session.Transaction != null) { session.EnsureTransactionIsStarted(); } tran = (currentTransaction != null && currentTransaction.TransactionInformation.DistributedIdentifier != Guid.Empty) || (session.Transaction != null && session.Transaction.IsDisconnected) ? session.OpenTransaction(isolationLevel) : session.OpenTransaction(context.TransactionOpenMode, isolationLevel); transaction = session.Transaction; result = context.Function(session); tran.Complete(); } finally { try { tran.DisposeSafely(); } catch (StorageException e) { if (e.InnerException == null || !(e.InnerException is InvalidOperationException) || e.InnerException.Source != "System.Data") { throw; } if (tran.Transaction.IsNested) { needBreak = true; } } } } finally { sessionScope.DisposeSafely(); if (SessionScope.CurrentSession != session) { session.DisposeSafely(); } } return(result); } catch (Exception e) { if ((SystemTransaction.Current != null && SystemTransaction.Current.TransactionInformation.DistributedIdentifier != Guid.Empty) || (transaction != null && (transaction.State == TransactionState.Active || transaction.IsDisconnected))) { throw; } if (e is RollbackTransactionException) { return(default(T)); } i++; if (needBreak || !HandleException(new ExecuteErrorEventArgs(e, session, transaction, i))) { throw; } } } }