Esempio n. 1
0
 /// <summary>
 /// Add a new Game to DB using the Wcf Service
 /// </summary>
 /// <param name="IP"></param>
 /// <param name="user"></param>
 public void addGame(String IP, UserWcf user)
 {
     DAL dal = new DAL();
     Game game = dal.AddGame(IP, user.Username);
     WcfServiceCallback update = OperationContext.Current.GetCallbackChannel<WcfServiceCallback>();
     update.updateGames("add",gameToWCF(game));
 }
Esempio n. 2
0
 private static void testConn(DAL conn)
 {
     foreach (Game item in conn.GetGames())
     {
         Console.WriteLine("ID:" + item.ID + " IP:" + item.IP + " FirstUser:"******"ID:" + item.ID + " username:"******" password:"******" money:" + item.money);
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Updated the user in the DB using the UserWcf Repreansanataion 
 /// </summary>
 /// <param name="u"></param>
 /// <returns></returns>
 public bool updateUser(UserWcf u)
 {
     DAL dal = new DAL();
     User dbUser = dal.GetUser(u.ID);
     if (dbUser != null)
     {
         dbUser.money = u.money;
         dbUser.numOfGames = u.numOfGames;
         dal.UpdateDB(dbUser);
         return true; // again no exception handling
     }
     return false; // should handle exception better;
 }
Esempio n. 4
0
 /// <summary>
 /// login without a callback
 /// </summary>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns>UserWcf object with the correct user or null if the authentication was unsuccessfull</returns>
  public UserWcf loginWeb(string username, string password)
  {
      DAL dal = new DAL();
      User u = dal.GetUser(username); //verify that there is such a user
      if (u != null && u.password == password) // verify the password
      {
          UserWcf user = new UserWcf();
          user.ID = u.ID;
          user.Username = u.username;
          user.money = u.money;
          if (u.numOfGames != null)
              user.numOfGames = (int)u.numOfGames; // somehow this became in? instead of int
          user.isAdmin = u.isAdmin;
          return user;
      }
      return null;
  }
Esempio n. 5
0
 static void Main(string[] args)
 {
     DAL conn = new DAL();
     
     Console.WriteLine("starting tests:");
     //testConn(conn);
     //conn.AddUser("john2", "pass", 1000);
     //conn.AddUser("john", "pass", 1000);
     //testConn(conn);
     Game g = conn.GetGame("153");
     User u = conn.GetUser("john");
     u.money = 5000;
     Console.WriteLine("lucky users is  ID:" + u.ID + " username:"******" password:"******" money:" + u.money);
     //conn.UpdateDB(u);
     testConn(conn);
     Console.WriteLine("delete tests");
     
     //conn.deleteAllUsers();
     //conn.deleteAllGames();
     Console.WriteLine("end");
 }
Esempio n. 6
0
 /// <summary>
 /// Remove game of a user
 /// </summary>
 /// <param name="user"></param>
 /// <returns></returns>
 public bool RemoveGameByUser(UserWcf user) 
 {
     DAL dal = new DAL();
     User dbUser = dal.GetUser(user.ID);
     if (dbUser != null)
     {
         Game game = dal.GetGame(dbUser);
         if(game != null)
         {
             dal.removeGame(game);
             return true;
         }
     }
     return false;
 }
Esempio n. 7
0
 /// <summary>
 ///  Get all users from DB
 /// </summary>
 /// <returns></returns>
 public UserWcf[] getUsers()
 {
     DAL dal = new DAL();
     List<UserWcf> ret = new List<UserWcf>();
     foreach (User u in dal.GetUsers())
     {
         ret.Add(userToWCF(u));
     }
     return ret.ToArray();
 }
Esempio n. 8
0
 /// <summary>
 /// Creating a new user in DB 
 /// not very secure
 /// </summary>
 /// <param name="user"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public bool addUser(UserWcf user,string password)
 {
     DAL dal = new DAL();
     dal.AddUser(user.Username, password);
     return true;
 }
Esempio n. 9
0
 /// <summary>
 /// Get specific user
 /// </summary>
 /// <param name="username"></param>
 /// <returns></returns>
 public UserWcf getUser(string username)
 {
     DAL dal = new DAL();
     User user = dal.GetUser(username);
     if (user != null)
         return userToWCF(user);
     return null;
 }
Esempio n. 10
0
        /// <summary>
        /// Get Games 
        /// </summary>
        /// <returns></returns>
        public GameWcf[] GetGames()
        {

            DAL dal = new DAL();
            List<GameWcf> ret = new List<GameWcf>();
            foreach (Game g in dal.GetGames())
            {
                ret.Add(gameToWCF(g));
            }
            return ret.ToArray();
        }
Esempio n. 11
0
        /// <summary>
        /// remove game specified by IP
        /// </summary>
        /// <param name="IP"></param>
        public void RemoveGameByIP(String IP)
        {
            DAL dal = new DAL();
            Game game = dal.GetGame(IP);
            if(game != null)
                {
                    dal.removeGame(game);
                    WcfServiceCallback update = OperationContext.Current.GetCallbackChannel<WcfServiceCallback>();
                    update.updateGames("remove", gameToWCF(game)); // this should notify the cients that the lsit has been updatd
                }

        }