public static RES_LOG_IN Process(REQ_LOG_IN requestPacket) { var responseResult = new RES_LOG_IN(); var result = DB.UserAccount.CheckUserAuthAsync(requestPacket.ID, requestPacket.PW); if (result.Result == false) { responseResult.Result = (short)ERROR_ID.LOG_IN_PW; return(responseResult); } var sessionInfo = new DB.DBUserSession() { CV = 1, CDV = 1, }; var token = DB.Session.SaveAuthInfoAsync(requestPacket.ID, sessionInfo); var reqLock = new RequestLock(requestPacket.ID); reqLock.SetInit(); responseResult.AuthToken = token.Result; responseResult.Result = (short)ERROR_ID.NONE; return(responseResult); }
public static async Task <RES_LOAD_USER_GAME_DATA> Process2(REQ_LOAD_USER_GAME_DATA requestPacket) { var responseResult = new RES_LOAD_USER_GAME_DATA(); using (var reqLock = new RequestLock(requestPacket.ID)) { var error = await reqLock.요청_처리중인가(); if (error != ERROR_ID.NONE) { responseResult.Result = (short)error; return(responseResult); } var isAuthOk = await DB.Session.CheckAuthInfoAsync(requestPacket.ID, requestPacket.AuthToken); if (isAuthOk == false) { responseResult.Result = (short)ERROR_ID.LOAD_USER_GAME_DATA_AUTH; return(responseResult); } } responseResult.Result = (short)ERROR_ID.NONE; return(responseResult); }
/// <summary> /// Acquires a lock of the specified type and returns an opaque lock object /// that will release the lock when disposed. /// /// <code>using (blocks.AcquireLock(RequestLock.Read)) {}</code> /// </summary> /// <returns>An opaque lock object that will release lock on disposal.</returns> public IDisposable AcquireLock(RequestLock requestLock) { // Acquire the lock based on the requested type. IDisposable acquiredLock; switch (requestLock) { case RequestLock.Read: acquiredLock = new NestableReadLock(accessLock); break; case RequestLock.UpgradableRead: acquiredLock = new NestableUpgradableReadLock(accessLock); break; case RequestLock.Write: acquiredLock = new NestableWriteLock(accessLock); break; default: throw new InvalidOperationException( "Could not acquire lock with unknown type: " + requestLock); } // Return the resulting lock. return(acquiredLock); }
/// <summary> /// Acquires a read lock on both the block and the block collection. /// </summary> /// <param name="collectionLock">The lock on the block collection.</param> /// <param name="blockLock">The lock object used to acquire the lock.</param> /// <param name="requestLock"></param> public BlockLock( IDisposable collectionLock, ReaderWriterLockSlim accessLock, RequestLock requestLock) { // Keep track of the collection lock so we can release it. this.collectionLock = collectionLock; // Acquire the lock based on the requested type. switch (requestLock) { case RequestLock.Read: blockLock = new NestableReadLock(accessLock); break; case RequestLock.UpgradableRead: blockLock = new NestableUpgradableReadLock(accessLock); break; case RequestLock.Write: blockLock = new NestableWriteLock(accessLock); break; default: throw new InvalidOperationException( "Could not acquire lock with unknown type: " + requestLock); } }
/// <summary> /// Acquires a lock on the collection, of the requested type, and also a lock /// on the block referenced by the index. /// </summary> /// <param name="blockIndex">The index of the block to lock.</param> /// <param name="block">The block retrieved by the index.</param> /// <param name="requestedBlockLock"></param> /// <returns>An opaque lock object that will release the lock on disposal.</returns> public IDisposable AcquireBlockLock( RequestLock requestedBlockLock, int blockIndex, out Block block) { return AcquireBlockLock( RequestLock.Read, requestedBlockLock, blockIndex, out block); }
public IDisposable AcquireBlockLock( RequestLock requestedBlockLock, BlockKey blockKey, out Block block) { return(AcquireBlockLock( RequestLock.Read, requestedBlockLock, blockKey, out block)); }
public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock) { IDisposable acquiredLock = Blocks.AcquireBlockLock( requestedCollectionLock, requestedBlockLock, this); return(acquiredLock); }
public RequestGuard(RequestLock rl) { _lock = rl; if (_lock.locked) { // someone else has it! } else { this.locked = true; _lock.locked = true; } }
public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock, Block block) { // Start by getting a read lock on the collection itself. IDisposable collectionLock = AcquireLock(requestedCollectionLock); // Get a read lock on the block and then return it. IDisposable blockLock = block.AcquireLock(collectionLock, requestedBlockLock); return(blockLock); }
public void setUp() { Random random = new Random(); long randomRequestInt1 = random.Next(10000000, 100000000); long randomRequestInt2 = random.Next(10000000, 100000000); long randomUserInt1 = random.Next(10000000, 100000000); long randomUserInt2 = random.Next(10000000, 100000000); // Create new Request Directly in DB _rmc.create(new RequestContent { patientLName = randomRequestInt1.ToString()}); // Create new Request Directly in DB _rmc.create(new RequestContent { patientLName = randomRequestInt2.ToString()}); // Create new UserProfile Directly in DB _dc.UserProfiles.InsertOnSubmit(new UserProfile { UserName = PREPENDOR + randomUserInt1.ToString()}); _dc.UserProfiles.InsertOnSubmit(new UserProfile { UserName = PREPENDOR + randomUserInt2.ToString()}); _dc.SubmitChanges(); _urq = _dc.Requests.FirstOrDefault( request => request.PatientLName == randomRequestInt1.ToString()); _lrq = _dc.Requests.FirstOrDefault( request => request.PatientLName == randomRequestInt2.ToString()); _up1 = _dc.UserProfiles.FirstOrDefault( userProfile => userProfile.UserName == (PREPENDOR + randomUserInt1.ToString())); _up2 = _dc.UserProfiles.FirstOrDefault( userProfile => userProfile.UserName == (PREPENDOR + randomUserInt2.ToString())); _rl = new RequestLock { RequestID = _lrq.RequestID, UserID = _up2.UserId, StartTime = DateTime.Now }; _dc.RequestLocks.InsertOnSubmit(_rl); _dc.SubmitChanges(); }
/// <summary> /// Acquires a lock on the collection, of the requested type, and also a lock /// on the block referenced by the index. /// </summary> /// <param name="requestedCollectionLock"></param> /// <param name="blockIndex">The index of the block to lock.</param> /// <param name="block">The block retrieved by the index.</param> /// <param name="requestedBlockLock"></param> /// <returns>An opaque lock object that will release the lock on disposal.</returns> public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock, int blockIndex, out Block block) { // Start by getting a read lock on the collection itself. IDisposable collectionLock = AcquireLock(requestedCollectionLock); // Grab the block via the index. block = this[blockIndex]; // Get a read lock on the block and then return it. IDisposable blockLock = block.AcquireLock(collectionLock, requestedBlockLock); return(blockLock); }
public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock, Block block) { // Start by getting a read lock on the collection itself. IDisposable collectionLock = AcquireLock(requestedCollectionLock); // Get a read lock on the block and then return it. IDisposable blockLock = block.AcquireLock(collectionLock, requestedBlockLock); return blockLock; }
/// <summary> /// Acquires a lock on a block while using the given opaque lock object for /// the collection lock. When the block's lock is disposed, so will the /// collection lock. /// /// <code>using (blocks.AcquireLock(accessLock)) {}</code> /// </summary> /// <returns>An opaque lock object that will release lock on disposal.</returns> public IDisposable AcquireLock( IDisposable collectionLock, RequestLock requestedLock) { return new BlockLock(collectionLock, accessLock, requestedLock); }
public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock) { IDisposable acquiredLock = Blocks.AcquireBlockLock( requestedCollectionLock, requestedBlockLock, this); return acquiredLock; }
public IDisposable AcquireBlockLock(RequestLock requestedBlockLock) { return AcquireBlockLock(RequestLock.Read, requestedBlockLock); }
/// <summary> /// Acquires a lock on a block while using the given opaque lock object for /// the collection lock. When the block's lock is disposed, so will the /// collection lock. /// /// <code>using (blocks.AcquireLock(accessLock)) {}</code> /// </summary> /// <returns>An opaque lock object that will release lock on disposal.</returns> public IDisposable AcquireLock( IDisposable collectionLock, RequestLock requestedLock) { return(new BlockLock(collectionLock, accessLock, requestedLock)); }
public IDisposable AcquireBlockLock(RequestLock requestedBlockLock) { return(AcquireBlockLock(RequestLock.Read, requestedBlockLock)); }
public async Task <RES_DATA> RequestWorldExtension(REQ_DATA request) { try { //var preCheck = ServerLogic.ClientRequestPrepare.CheckServerStatus(); //if(preCheck != ERROR_CODE.NONE) //{ //return new RES_DATA { Result = (short)preCheck }; //} var jsonObject = DecryptRequestData <REQ_WORLD_EXTENSION>(request.LSeq, request.Data); if (string.IsNullOrEmpty(jsonObject.ID) || string.IsNullOrEmpty(request.ID)) { return(new RES_DATA { Result = (short)ERROR_CODE.REQUEST_JSON_PARSE_OR_ID_NULL }); } var userID = jsonObject.ID; var loginSeq = jsonObject.LSeq; var authToken = jsonObject.AT; if (userID != request.ID || loginSeq != request.LSeq) { return(new RES_DATA { Result = (short)ERROR_CODE.DISCORDANCE_ID_LSEQ }); } var authUserInfo = await CommonServer.LocalCache.UserAuthCache.GetAuthInfo(userID); if (authUserInfo.err != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)authUserInfo.err }); } var checkResult = authUserInfo.Check(loginSeq, userID, authToken); if (checkResult != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)checkResult }); } if (ServerLogic.ClientRequestPrepare.CompareClientDataVer(authUserInfo.CDV) == false) { return(new RES_DATA { Result = (short)ERROR_CODE.FAIL_CLIENT_DATA_VERSION }); } { checkResult = await RequestLock.Lock(userID, authToken); if (checkResult != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)checkResult }); } var userGameData = await DBUserGameData.GetSmallBasicGameData(authUserInfo.UserID); if (userGameData.IsValid == false) { await RequestLock.UnLock(userID); return(new RES_DATA { Result = (short)ERROR_CODE.FAIL_LOAD_SMALL_USER_BASIC_GAME_DATA }); } if (userGameData.TSeq != Loader.DBTutorialDataInst.TUTORIAL_COUNT) { await RequestLock.UnLock(userID); return(new RES_DATA { Result = (short)ERROR_CODE.TUTORIAL_DONT_COMPLETED }); } if (Request.Function.IsBusinessSimulationing(userGameData.PBSTurn)) { await RequestLock.UnLock(userID); return(new RES_DATA { Result = (short)ERROR_CODE.ALREADY_BUSINESS_SIMULATIONING }); } var result = await Request.WorldExtension.Process(jsonObject, authUserInfo, userGameData); await RequestLock.UnLock(userID); return(EncryotResponseData <RES_WORLD_EXTENSION>(request.LSeq.ToString(), result)); } } catch (Exception ex) { return(ResponseException <RES_DATA>(ex.ToString())); } }
public async Task <RES_DATA> RequestLoadUserData(REQ_DATA request) { try { //var preCheck = ServerLogic.ClientRequestPrepare.CheckServerStatus(); //if(preCheck != ERROR_CODE.NONE) //{ //return new RES_DATA { Result = (short)preCheck }; //} var jsonObject = DecryptRequestData <REQ_USER_DATA>(request.LSeq, request.Data); if (string.IsNullOrEmpty(jsonObject.ID) || string.IsNullOrEmpty(request.ID)) { return(new RES_DATA { Result = (short)ERROR_CODE.REQUEST_JSON_PARSE_OR_ID_NULL }); } var userID = jsonObject.ID; var loginSeq = jsonObject.LSeq; var authToken = jsonObject.AT; if (userID != request.ID || loginSeq != request.LSeq) { return(new RES_DATA { Result = (short)ERROR_CODE.DISCORDANCE_ID_LSEQ }); } var authUserInfo = await CommonServer.LocalCache.UserAuthCache.GetAuthInfo(userID); if (authUserInfo.err != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)authUserInfo.err }); } var checkResult = authUserInfo.Check(loginSeq, userID, authToken); if (checkResult != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)checkResult }); } if (ServerLogic.ClientRequestPrepare.CompareClientDataVer(authUserInfo.CDV) == false) { return(new RES_DATA { Result = (short)ERROR_CODE.FAIL_CLIENT_DATA_VERSION }); } { checkResult = await RequestLock.Lock(userID, authToken); if (checkResult != ERROR_CODE.NONE) { return(new RES_DATA { Result = (short)checkResult }); } var result = await Request.LoadUserData.Process(jsonObject, authUserInfo); await RequestLock.UnLock(userID); return(EncryotResponseData <RES_USER_DATA>(request.LSeq.ToString(), result)); } } catch (Exception ex) { return(ResponseException <RES_DATA>(ex.ToString())); } }
/// <summary> /// Acquires a lock on the collection, of the requested type, and also a lock /// on the block referenced by the index. /// </summary> /// <param name="requestedCollectionLock"></param> /// <param name="blockIndex">The index of the block to lock.</param> /// <param name="block">The block retrieved by the index.</param> /// <param name="requestedBlockLock"></param> /// <returns>An opaque lock object that will release the lock on disposal.</returns> public IDisposable AcquireBlockLock( RequestLock requestedCollectionLock, RequestLock requestedBlockLock, int blockIndex, out Block block) { // Start by getting a read lock on the collection itself. IDisposable collectionLock = AcquireLock(requestedCollectionLock); // Grab the block via the index. block = this[blockIndex]; // Get a read lock on the block and then return it. IDisposable blockLock = block.AcquireLock(collectionLock, requestedBlockLock); return blockLock; }
/// <summary> /// Acquires a lock of the specified type and returns an opaque lock object /// that will release the lock when disposed. /// /// <code>using (blocks.AcquireLock(RequestLock.Read)) {}</code> /// </summary> /// <returns>An opaque lock object that will release lock on disposal.</returns> public IDisposable AcquireLock(RequestLock requestLock) { // Acquire the lock based on the requested type. IDisposable acquiredLock; switch (requestLock) { case RequestLock.Read: acquiredLock = new NestableReadLock(accessLock); break; case RequestLock.UpgradableRead: acquiredLock = new NestableUpgradableReadLock(accessLock); break; case RequestLock.Write: acquiredLock = new NestableWriteLock(accessLock); break; default: throw new InvalidOperationException( "Could not acquire lock with unknown type: " + requestLock); } // Return the resulting lock. return acquiredLock; }
public IDisposable AcquireBlockLock( RequestLock requestedBlockLock, BlockKey blockKey, out Block block) { return AcquireBlockLock( RequestLock.Read, requestedBlockLock, blockKey, out block); }