public GameSession(SessionDataDto data) { Data = ToSessionData(data); if (Data.IsPause) { Pause(); } else { Resume(); } }
public SessionData ToSessionData(SessionDataDto data) { var sessionData = new SessionData { Turn = data.Turn, ScenarioName = data.ScenarioName, IsPause = data.IsPause, Rules = data.Rules, CelestialObjects = data.CelestialObjects, TurnHistory = data.TurnHistory, GameEvents = data.GameEvents }; return(sessionData); }
public SessionDataDto ToSessionTransfer() { var data = new SessionDataDto { Turn = Data.Turn, ScenarioName = Data.ScenarioName, IsPause = IsPause, Rules = Data.Rules.DeepClone(), CelestialObjects = DataProcessing.Convert.VisibilityAreaFilter(this).DeepClone(), TurnHistory = Data.TurnHistory.DeepClone(), GameEvents = Data.GameEvents.DeepClone() }; return(data); }
private SessionDataDto CreateSession(Guid sessionId) { var serviceScope = serviceProvider.CreateScope(); var data = new SessionDataDto { ServiceScope = serviceScope }; sessions.Add(sessionId, data); var sessionIdProvider = serviceScope.ServiceProvider .GetRequiredService <ISessionIdProvider>(); sessionIdProvider.SetSessionId(sessionId); return(data); }
public IActionResult JoinHost(string session_Code, [FromBody] PlayerForUpdateDto player) { if (player == null) { _logger.LogError("Player object sent from client is null."); return(BadRequest("Player object is null")); } if (session_Code == null) { _logger.LogError("Session code sent by client is null."); return(BadRequest("Session code is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Player object sent from client."); return(BadRequest("Invalid model object")); } SessionData sessionData = _repository.SessionData.GetBySessionCodeWithDetails(session_Code); if (sessionData.players.Count() >= 4) { return(Ok("session full")); } // start create new player Player PlayerEntity = _mapper.Map <Player>(player); PlayerEntity.orderNumber = sessionData.players.Count() + 1; PlayerEntity.session_id = sessionData.id; _repository.Player.CreatePlayer(PlayerEntity); _repository.Save(); var session = _repository.SessionData.GetBySessionCodeWithDetails(session_Code); SessionDataDto result = _mapper.Map <SessionDataDto>(session); return(Ok(result)); }
public IActionResult CreateHost([FromBody] PlayerForUpdateDto player) { try { if (player == null) { _logger.LogError("Player object sent from client is null."); return(BadRequest("Player object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Player object sent from client."); return(BadRequest("Invalid model object")); } SessionCodeGenerator generator = new SessionCodeGenerator(); TopicCreator creator = new TopicCreator(); // create new session // start create new session code string session_code = ""; bool inUse = true; while (inUse) { session_code = generator.GenerateSessionCode(); inUse = _repository.SessionData.ValidateIfActive(session_code); } // end create new session code // start create new session SessionData sessionData = new SessionData(); sessionData.session_code = session_code; _repository.SessionData.CreateSession(sessionData); // end create new session // start create new topic TopicData data = creator.CreateNewTopic(session_code); data.sessionCode = session_code; _repository.TopicData.CreateTopic(data); _repository.Save(); // end create new topic // start create new player Player PlayerEntity = _mapper.Map <Player>(player); PlayerEntity.orderNumber = 1; PlayerEntity.session_id = sessionData.id; _repository.Player.CreatePlayer(PlayerEntity); _repository.Save(); // end create new player var session = _repository.SessionData.GetBySessionCodeWithDetails(session_code); SessionDataDto result = _mapper.Map <SessionDataDto>(session); return(Ok(result)); //return CreatedAtRoute("CategoryById", new { id = createdEntity.id }, createdEntity); } catch (Exception ex) { _logger.LogError($"Something went wrong inside CreateArtist action: {ex.Message}"); return(StatusCode(500, "Internal server error")); } }
public void SetBusinessUnit(string businessUnit) { var authenticationResult = LogonService.LogOnAsApplicationUser(_logonName, _passWord); if (authenticationResult.Successful) { if (businessUnit != "") { _businessUnitDto = authenticationResult.BusinessUnitCollection.FirstOrDefault(p => p.Id.ToUpper() == businessUnit.ToUpper()); } if (_businessUnitDto == null || businessUnit == "") { _businessUnitDto = authenticationResult.BusinessUnitCollection.FirstOrDefault(); } currentHeader.UserName = _logonName; currentHeader.Password = _passWord; currentHeader.BusinessUnit = _businessUnitDto.Id; currentHeader.DataSource = authenticationResult.Tenant; currentHeader.UseWindowsIdentity = false; AuthenticationSuccessful = authenticationResult.Successful; } //Set the business unit LogonService.SetBusinessUnit(BusinessUnitDto); bool isAuthenticated, isAuthenticatedSpecified; LogonService.IsAuthenticated(out isAuthenticated, out isAuthenticatedSpecified); if (isAuthenticatedSpecified) { SessionDataDto sessionDataDto = new SessionDataDto(); sessionDataDto.LoggedOnPerson = LogonService.GetLoggedOnPerson(); sessionDataDto.BusinessUnit = BusinessUnitDto; ICollection<DataSourceDto> availableDataSources = LogonService.GetDataSources(); //Select the first one (generally choosen by a user) DataSourceDto dataSource = availableDataSources.FirstOrDefault(); sessionDataDto.DataSource = dataSource; sessionDataDto.AuthenticationType = sessionDataDto.DataSource.AuthenticationTypeOptionDto; sessionDataDto.AuthenticationTypeSpecified = true; LogonService.TransferSession(sessionDataDto); } }