Ejemplo n.º 1
0
        public SelectList SelectListOnlyWith(PlayerAbstract entity)
        {
            entity.IsNullThrowExceptionArgument("entity");
            Person person = null;

            if (entity.Person.IsNull())
            {
                if (entity.PersonId.IsNullOrWhiteSpaceThrowArgumentException("No person"))
                {
                    //error thrown
                }
                else
                {
                    person = PersonBiz.GetPersonForUserId(entity.PersonId);
                }
            }
            else
            {
                person = entity.Person;
            }

            person.IsNullThrowException("No person found for user.");


            var allItems = FindAll().Where(x => x.PersonId == person.Id);

            return(SelectList_Engine(allItems));
        }
Ejemplo n.º 2
0
        public override ICommonWithId Factory()
        {
            //UserId.IsNullOrWhiteSpaceThrowException("You are not logged in");

            //add the default addresses if they are available
            PlayerAbstract playerAbstract = base.Factory() as PlayerAbstract;

            ////get the person so we can get the deafult addresses.
            //Person person = UserBiz.GetPersonFor(UserId);
            //person.IsNullThrowException("User has no person");

            //if (!person.DefaultBillAddressId.IsNullOrWhiteSpace())
            //{
            //    playerAbstract.DefaultBillAddressId = person.DefaultBillAddressId;
            //    playerAbstract.DefaultShipAddressId = person.DefaultBillAddressId;

            //}
            return(playerAbstract as ICommonWithId);
        }
Ejemplo n.º 3
0
        public static Tuple <Color, int, long, long> Game(Board board, PlayerAbstract white, PlayerAbstract black,
                                                          ChessListener listener)
        {
            var i = 0;

            while (true)
            {
                board.Move(white.GetMove());
                listener.MoveEvent(board.Clone());
                if (board.AllPieces1.FindAll(p => p is King && p.InPlay).Count != 2)
                {
                    break;                                                                  //if checkmate
                }
                i++;

                //Check for draw
                if (Rules.CheckDraw(board))
                {
                    return(new Tuple <Color, int, long, long>(Color.NoColor, i, white.Stopwatch.ElapsedMilliseconds,
                                                              black.Stopwatch.ElapsedMilliseconds));
                }

                board.Move(black.GetMove());
                listener.MoveEvent(board.Clone());
                if (board.AllPieces1.FindAll(p => p is King && p.InPlay).Count != 2)
                {
                    break;                                                                  //if checkmate
                }
                if (Rules.CheckDraw(board))
                {
                    return(new Tuple <Color, int, long, long>(Color.NoColor, i, white.Stopwatch.ElapsedMilliseconds,
                                                              black.Stopwatch.ElapsedMilliseconds));
                }
                i++;
            }


            var winner = board.AllPieces1.Find(king => king is King && king.InPlay).Color;

            return(new Tuple <Color, int, long, long>(winner, i, white.Stopwatch.ElapsedMilliseconds,
                                                      black.Stopwatch.ElapsedMilliseconds));
        }
Ejemplo n.º 4
0
        public static Tuple <Color, int, long, long>[] Games(Board board, PlayerAbstract white, PlayerAbstract black,
                                                             int numberOfGames, bool debugPrint = false, bool boardPrint = false)
        {
            var tasks = new List <Task <Tuple <Color, int, long, long> > >();

            for (var i = 0; i < numberOfGames; i++)
            {
                var bC  = board.Clone();
                var wC  = white.Clone(bC);
                var blC = black.Clone(bC);

                tasks.Add(new Task <Tuple <Color, int, long, long> >(() =>
                                                                     Game(bC, wC, blC, boardPrint, debugPrint)));
            }

            tasks.ForEach(task => task.Start());
            while (!tasks.All(task => task.IsCompleted))
            {
            }

            return(tasks.ConvertAll(task => task.Result).ToArray());
        }
Ejemplo n.º 5
0
        public static Tuple <Color, int, long, long> Game(Board board, PlayerAbstract white, PlayerAbstract black,
                                                          bool printBoard = false, bool printDebug = false, bool printGameBNumber = false, int gameNumber = 0)
        {
            var i = 0;

            while (true)
            {
                if (printDebug)
                {
                    Console.WriteLine("Making move " + i);
                }
                board.Move(white.GetMove());
                i++;
                if (printBoard)
                {
                    board.PrintBoardToPrinter();
                }
                if (printGameBNumber)
                {
                    Printer.AddToPrinter(gameNumber + "");
                }
                if (board.AllPieces1.FindAll(p => p is King && p.InPlay).Count != 2)
                {
                    break;                                                                  //if checkmate
                }
                if (printDebug)
                {
                    Console.WriteLine("Making move " + i);
                }
                //Check for draw
                if (Rules.CheckDraw(board))
                {
                    if (printDebug)
                    {
                        Console.WriteLine("White has taken {0} ms and black has taken {1} ms",
                                          white.Stopwatch.ElapsedMilliseconds,
                                          black.Stopwatch.ElapsedMilliseconds);
                    }
                    return(new Tuple <Color, int, long, long>(Color.NoColor, i, white.Stopwatch.ElapsedMilliseconds,
                                                              black.Stopwatch.ElapsedMilliseconds));
                }

                board.Move(black.GetMove());
                if (printBoard)
                {
                    board.PrintBoardToPrinter();
                }
                if (printGameBNumber)
                {
                    Printer.AddToPrinter(gameNumber + "");
                }
                if (board.AllPieces1.FindAll(p => p is King && p.InPlay).Count != 2)
                {
                    break;                                                                  //if checkmate
                }
                i++;
                if (Rules.CheckDraw(board))
                {
                    if (printDebug)
                    {
                        Console.WriteLine("White has taken {0} ms and black has taken {1} ms",
                                          white.Stopwatch.ElapsedMilliseconds,
                                          black.Stopwatch.ElapsedMilliseconds);
                    }
                    return(new Tuple <Color, int, long, long>(Color.NoColor, i, white.Stopwatch.ElapsedMilliseconds,
                                                              black.Stopwatch.ElapsedMilliseconds));
                }
            }

            if (printDebug)
            {
                Console.WriteLine("White has taken {0} ms and black has taken {1} ms",
                                  white.Stopwatch.ElapsedMilliseconds,
                                  black.Stopwatch.ElapsedMilliseconds);
            }
            var winner = board.AllPieces1.Find(king => king is King && king.InPlay).Color;

            return(new Tuple <Color, int, long, long>(winner, i, white.Stopwatch.ElapsedMilliseconds,
                                                      black.Stopwatch.ElapsedMilliseconds));
        }
Ejemplo n.º 6
0
        public ApplicationUser GetUserForEntityrWhoIsNotAdminFor(string entityId)
        {
            //get the entity
            TEntity entity = Find(entityId);

            entity.IsNullThrowException("Entity not found");

            PlayerAbstract playerAbstract = entity as PlayerAbstract;

            playerAbstract.IsNullThrowException("playerAbstract");

            string personId = entity.PersonId;

            personId.IsNullOrWhiteSpaceThrowArgumentException("personId");
            Person person = PersonBiz.Find(personId);

            person.IsNullThrowException("No person found");

            //Now get the user. Here we can get multiple users if person is being impersonated by admin.
            //we have to deal with that.

            List <ApplicationUser> usersForPerson = UserBiz.FindAll().Where(x => x.PersonId == personId).ToList();

            usersForPerson.IsNullOrEmptyThrowException("Person not found");

            //if it is the admininistrators own account, there will be only one person and the item will get thru
            if (usersForPerson.Count() == 1)
            {
                return(usersForPerson[0]);
            }


            //Getting rid of administrators

            //if more than 1 person has been found then the admin is impersonating this person
            //at this time.
            //get rid of all administrators.

            //find all administrators
            List <ApplicationUser> allAdminList = UserBiz.GetAllAdmin();

            //create a duplicate list of usersForPerson we will use for itteration
            List <ApplicationUser> duplicate_usersForPerson = new List <ApplicationUser>();;

            foreach (ApplicationUser user in usersForPerson)
            {
                duplicate_usersForPerson.Add(user);
            }

            //now itterate thru duplicate_usersForPerson and remove admins from usersForPerson
            foreach (var user in duplicate_usersForPerson)
            {
                if (allAdminList.Contains(user))
                {
                    usersForPerson.Remove(user);
                }
            }

            //all administrators are now gone from usersForPerson
            usersForPerson.IsNullOrEmptyThrowException("Person not found");
            if (usersForPerson.Count() > 1)
            {
                throw new Exception("There is more than one person for the user. This is a data error.");
            }
            return(usersForPerson[0]);
        }
Ejemplo n.º 7
0
        public override void Fix(ControllerCreateEditParameter parm)
        {
            //UserId.IsNullOrWhiteSpaceThrowException("You are not logged in!");
            base.Fix(parm);

            PlayerAbstract playerAbstract = PlayerAbstract.UnboxPlayerAbstract(parm);

            if (playerAbstract.Name.IsNullOrWhiteSpace())
            {
                if (playerAbstract.Person.IsNull())
                {
                    if (playerAbstract.PersonId.IsNull())
                    {
                        throw new Exception("No person");
                    }
                    else
                    {
                        Person person = PersonBiz.Find(playerAbstract.PersonId);
                        person.IsNullThrowException();
                        playerAbstract.Person = person;
                    }
                }
                playerAbstract.Name = playerAbstract.Person.Name;
            }


            //if (!playerAbstract.PersonId.IsNullOrWhiteSpace())
            //{
            //    //we need to add a person Id
            //    Person person = PersonBiz.Find(playerAbstract.PersonId);
            //    person.IsNullThrowException();

            //    playerAbstract.PersonId = person.Id;
            //    playerAbstract.Person = person;
            //}
            //else
            //{
            //    throw new Exception("No person found");
            //}



            //if (playerAbstract.Person.IsNull())
            //    playerAbstract.Person = PersonBiz.Find(playerAbstract.PersonId);

            //playerAbstract.Person.IsNullThrowException("No Person");

            //the user name


            //if (playerAbstract.Name.IsNullOrWhiteSpace())
            //    playerAbstract.Name = playerAbstract.Person.Name;

            if (playerAbstract.DefaultBillAddressId.IsNullOrWhiteSpace())
            {
                playerAbstract.DefaultBillAddressId = null;
            }

            if (playerAbstract.DefaultShipAddressId.IsNullOrWhiteSpace())
            {
                playerAbstract.DefaultShipAddressId = null;
            }
        }