public HttpResponseMessage Authenticate([FromBody] AuthObj obj) { bool isAuthenticated = BLPlayer.Authenticate(obj); if (!isAuthenticated) { return(Request.CreateResponse <bool>(HttpStatusCode.Forbidden, false)); } else { IDatabase db = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(db); var player = dao.FindByNickname(obj.Nickname); var token = Authentication.getInstance().newAuthentication(obj.Nickname); ResponseObject r = new ResponseObject(token.Token, player); return(Request.CreateResponse <ResponseObject>(HttpStatusCode.Created, r)); //return new HttpResponseMessage(HttpStatusCode.OK); } }
public HttpResponseMessage PostImage([FromBody] byte[] file, int playerId) { IPlayerDao playerDAO = DalFactory.CreatePlayerDao(database); Player player = playerDAO.FindById(playerId); try { using (MemoryStream ms = new MemoryStream(file)) { Image.FromStream(ms); } } catch (ArgumentException) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } string absolutePath = ConfigurationManager.AppSettings["ImageFolder"].ToString() + "\\" + player.PhotoPath; try { File.WriteAllBytes(absolutePath, file); return(Request.CreateResponse(HttpStatusCode.OK)); } catch { return(Request.CreateResponse(HttpStatusCode.BadGateway)); } }
public HttpResponseMessage GetImage(int playerId) { IPlayerDao playerDAO = DalFactory.CreatePlayerDao(database); Player player = playerDAO.FindById(playerId); string absolutePath = ConfigurationManager.AppSettings["ImageFolder"].ToString() + "\\"; HttpResponseMessage response = new HttpResponseMessage(); Byte[] b; if (player == null || !File.Exists(absolutePath + player.PhotoPath)) { b = (File.ReadAllBytes(absolutePath + "default.png")); } else { absolutePath = absolutePath + player.PhotoPath; b = (File.ReadAllBytes(absolutePath)); } response.Content = new ByteArrayContent(b); response.Content.LoadIntoBufferAsync(b.Length).Wait(); response.Content.Headers.ContentType = new MediaTypeHeaderValue("image/png"); return(response); }
public HttpResponseMessage GetAll() { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IStatisticDao StatisticDao = DalFactory.CreateStatisticDao(database); IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); var retList = new List <Serialize>(); int i = 0; foreach (Player p in PlayerDao.FindAll().OrderByDescending(s => s.Skills)) { if (i < 5) { var list = StatisticDao.FindAll().Where(s => { return(s.PlayerID == p.ID); }).ToList(); retList.Add(new Serialize(p, list)); } i++; } return(Request.CreateResponse <List <Serialize> >(HttpStatusCode.OK, retList)); //} //else //{ // return Request.CreateResponse(HttpStatusCode.Forbidden); //} }
public PlayerController(IPlayerDao dao) { Dao = dao; _playersById = new ConcurrentDictionary <int, Player>(); _playerNamesById = new ConcurrentDictionary <int, string>(); _playersByName = new ConcurrentDictionary <string, Player>(); }
public static void Initialize(TestContext context) { database = DalFactory.CreateDatabase(); dao = DalFactory.CreatePlayerDao(database); Assert.IsNotNull(database); }
public HttpResponseMessage GetAll() { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); return(Request.CreateResponse <IList <Player> >(HttpStatusCode.OK, PlayerDao.FindAll())); //} //else //{ // return Request.CreateResponse(HttpStatusCode.Forbidden); //} }
public void Decay() { IDatabase database = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(database); Player p = dao.FindByNickname("Alex"); BLPlayer.Decay(); Player p1 = dao.FindByNickname("Alex"); Assert.IsFalse(p1.Skills < p.Skills); }
public HttpResponseMessage FindByNickname(string nickname) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); return(Request.CreateResponse <Player>(HttpStatusCode.OK, PlayerDao.FindByNickname(nickname))); //} //else //{ // return new HttpResponseMessage(HttpStatusCode.Forbidden); //} }
public HttpResponseMessage DeleteById(int id) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); return(Request.CreateResponse <bool>(HttpStatusCode.OK, PlayerDao.DeleteById(id))); //} //else //{ // return new HttpResponseMessage(HttpStatusCode.Forbidden); //} }
public HttpResponseMessage GetPlayerByDay(DateTime day) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); return(Request.CreateResponse <IEnumerable <Player> >(HttpStatusCode.OK, BLPlayer.GetPlayerByDay(day, PlayerDao.FindAll()))); //} //else //{ // return new HttpResponseMessage(HttpStatusCode.Forbidden); //} }
public void UpdateElo() { IDatabase database = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(database); var plist = dao.FindAll(); Player p1 = new Player(); Player p2 = new Player(); Player p3 = new Player(); Player p4 = new Player(); int i = 0; Assert.IsTrue(plist.Count >= 4); foreach (Player pl in plist) { switch (i) { case 1: p1 = pl; break; case 2: p2 = pl; break; case 3: p3 = pl; break; case 4: p4 = pl; break; } i++; } int p1S = p1.Skills; int p2S = p2.Skills; int p3S = p3.Skills; int p4S = p4.Skills; BLPlayer.UpdateElo(p1, p2, p3, p4); Assert.IsTrue(p1.Skills > p1S); Assert.IsTrue(p2.Skills > p2S); Assert.IsTrue(p3.Skills < p3S); Assert.IsTrue(p4.Skills < p4S); }
public void Insert() { IDatabase db = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(db); IStatisticDao sdao = DalFactory.CreateStatisticDao(db); var p = dao.FindByNickname("Alex"); int a = sdao.FindAll().Count; BLStatistic.Insert(p.ID, 100); int b = sdao.FindAll().Count; Assert.IsTrue(a < b); }
public static bool Authenticate(AuthObj obj) { IDatabase database = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(database); string nickname = obj.Nickname; string password = obj.HashedPassword; Player p = dao.FindByNickname(nickname); if (p == null) { return(false); } return(BLAuthentication.Verify(password, p.Password)); }
public void Update(Match match) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IMatchDao MatchDao = DalFactory.CreateMatchDao(database); IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); if (match.Finished) { Player w1; Player w2; Player v1; Player v2; if (match.ResultPointsPlayer1 > match.ResultPointsPlayer2) { w1 = PlayerDao.FindById(match.Team1Player1); w2 = PlayerDao.FindById(match.Team1Player2); v1 = PlayerDao.FindById(match.Team2Player1); v2 = PlayerDao.FindById(match.Team2Player2); } else { w1 = PlayerDao.FindById(match.Team2Player1); w2 = PlayerDao.FindById(match.Team2Player2); v1 = PlayerDao.FindById(match.Team1Player1); v2 = PlayerDao.FindById(match.Team1Player2); } BLPlayer.UpdateElo(w1, w2, v1, v2); BLStatistic.Insert(w1.ID, w1.Skills); BLStatistic.Insert(w2.ID, w2.Skills); BLStatistic.Insert(v1.ID, v1.Skills); BLStatistic.Insert(v2.ID, v2.Skills); PlayerDao.Update(w1); PlayerDao.Update(w2); PlayerDao.Update(v1); PlayerDao.Update(v2); } MatchDao.Update(match); //} }
public void GetPlayerByDay() { IDatabase database = DalFactory.CreateDatabase(); IPlayerDao dao = DalFactory.CreatePlayerDao(database); for (int i = 0; i < 6; i++) { IEnumerable <Player> p = BLPlayer.GetPlayerByDay(DateTime.Now.Date.AddDays(i), dao.FindAll()); foreach (Player pl in p) { switch (DateTime.Now.DayOfWeek) { case DayOfWeek.Monday: Assert.IsTrue(pl.isMonday); break; case DayOfWeek.Tuesday: Assert.IsTrue(pl.isTuesday); break; case DayOfWeek.Wednesday: Assert.IsTrue(pl.isWednesday); break; case DayOfWeek.Thursday: Assert.IsTrue(pl.isThursday); break; case DayOfWeek.Friday: Assert.IsTrue(pl.isFriday); break; case DayOfWeek.Saturday: Assert.IsTrue(pl.isSaturday); break; } } } }
public static void Decay() { IDatabase database = DalFactory.CreateDatabase(); IPlayerDao pDao = DalFactory.CreatePlayerDao(database); IStatisticDao sDao = DalFactory.CreateStatisticDao(database); List <Player> pList = pDao.FindAll().Where(p => { var statList = sDao.FindByPlayer(p.ID); if (!statList.Any()) { return(false); } var maxdate = statList.Max(s => s.Timestamp); return(DateTime.Now.AddDays(-60) < maxdate); }).ToList(); foreach (Player p in pList) { p.Skills = (int)(p.Skills * 0.98); pDao.Update(p); } }
public HttpResponseMessage Insert([FromBody] Player player) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); player.Password = BLAuthentication.Hash(player.Password); int id = PlayerDao.Insert(player); if (id == -1) { return(new HttpResponseMessage(HttpStatusCode.Conflict)); } else { return(Request.CreateResponse <int>(HttpStatusCode.OK, id)); } //} //else //{ // return new HttpResponseMessage(HttpStatusCode.Forbidden); //} }
public HttpResponseMessage Update([FromBody] Player player, int playerId) { //if (Authentication.getInstance().isAuthenticateWithHeader(Request)) //{ IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); Player pl = PlayerDao.FindById(player.ID); Player p = new Player(playerId, player.isAdmin, player.FirstName, player.LastName, player.Nickname, player.Skills, pl.PhotoPath, player.Password, player.isMonday, player.isTuesday, player.isWednesday, player.isThursday, player.isFriday, player.isSaturday); var boo = PlayerDao.Update(p); if (boo) { return(new HttpResponseMessage(HttpStatusCode.OK)); } else { return(Request.CreateResponse(HttpStatusCode.Conflict)); } //} }
public PlayerService(IPlayerDao playerDao) { _playerDao = playerDao; _players = new List <Player>(); }
public HttpResponseMessage GetRanks() { IPlayerDao PlayerDao = DalFactory.CreatePlayerDao(database); return(Request.CreateResponse <IOrderedEnumerable <Player> >(PlayerDao.FindAll().OrderByDescending(s => s.Skills))); }
public PlayerLogic(IPlayerDao playerDao) { _playerDao = playerDao; }