public IExecutable ManageCommand(string[] inputArgs)
        {
            IExecutable command = null;

            string commandType = inputArgs[0];

            switch (commandType)
            {
                case "create":
                    command = new CreateCommand(this.Engine, inputArgs[1], int.Parse(inputArgs[2]), int.Parse(inputArgs[3]),
                        (BehaviorTypes)Enum.Parse(typeof(BehaviorTypes), inputArgs[4]), (AttackTypes)Enum.Parse(typeof(AttackTypes), inputArgs[5]));
                    break;
                case "attack":
                    command = new AttackCommand(this.Engine, inputArgs[1], inputArgs[2]);
                    break;
                case "pass":
                    command = new PassCommand();
                    break;
                case "status":
                    command = new StatusCommand(this.Engine);
                    break;
                case "drop":
                    command = new DropCommand();
                    break;
            }

            return command;
        }
        public IExecutable ManageCommand(string[] inputArgs)
        {
            IExecutable command = null;

            string commandType = inputArgs[0];

            switch (commandType)
            {
            case "create":
                command = new CreateCommand(this.Engine, inputArgs[1], int.Parse(inputArgs[2]), int.Parse(inputArgs[3]),
                                            (BehaviorTypes)Enum.Parse(typeof(BehaviorTypes), inputArgs[4]), (AttackTypes)Enum.Parse(typeof(AttackTypes), inputArgs[5]));
                break;

            case "attack":
                command = new AttackCommand(this.Engine, inputArgs[1], inputArgs[2]);
                break;

            case "pass":
                command = new PassCommand();
                break;

            case "status":
                command = new StatusCommand(this.Engine);
                break;

            case "drop":
                command = new DropCommand();
                break;
            }

            return(command);
        }
Ejemplo n.º 3
0
 private void RaiseCommandsChanged()
 {
     GetHintCommand.RaiseCanExecuteChanged();
     PassCommand.RaiseCanExecuteChanged();
     PressedCommand.RaiseCanExecuteChanged();
     ResignCommand.RaiseCanExecuteChanged();
     UndoCommand.RaiseCanExecuteChanged();
 }
Ejemplo n.º 4
0
        public void GetAndUseDelegate()
        {
            ICommand body = new PassCommand();

            DefinedFunction func = new DefinedFunction("foo", null, body, null);
            var             type = typeof(ThreadStart);
            //Activator.CreateInstance(typeof(ThreadStart), func.DoFunction);
        }
        public void ValuesInFunction()
        {
            ICommand body = new PassCommand();

            DefinedFunction func = new DefinedFunction("foo", null, body, null);

            func.SetValue("__doc__", "foo function");

            Assert.IsFalse(func.HasValue("bar"));
            Assert.IsTrue(func.HasValue("__doc__"));
            Assert.AreEqual("foo function", func.GetValue("__doc__"));
        }
Ejemplo n.º 6
0
        public void Run()
        {
            IExecutable command = null;
            string line = reader.ReadLine();
            while (line != "drop")
            {
                string[] tokens = line.Split();

                switch (tokens[0])
                {
                    case "create":
                        command = new CreateCommand(
                            db,
                            tokens[1],
                            int.Parse(tokens[2]),
                            int.Parse(tokens[3]),
                            tokens[4],
                            tokens[5]);
                        break;
                    case "pass":
                        command = new PassCommand(db);
                        break;
                    case "status":
                        command = new StatusCommand(db);
                        break;
                    case "attack":

                    default:
                        throw new NotImplementedException("Uncnoun command.");
                }

                try
                {
                    this.writer.Print(command.Execute());
                }
                catch (Exception e)
                {
                    this.writer.Print(e.Message);
                }
                finally
                {
                    line = reader.ReadLine();
                }

            }
        }
Ejemplo n.º 7
0
        protected void UpdateCanPassAndUndo()
        {
            if (IsTimelineInPast)
            {
                CanUndo = false;
                CanPass = false;
                return;
            }

            CanPass = (this.Game?.Controller?.TurnPlayer?.IsHuman ?? false) ? true : false;
            // TODO (future work)  Petr this allows to undo before the beginning of the game and causes exception
            if (this.Game?.Controller?.GameTree == null)
            {
                // Game not yet initialized.
                CanUndo = false;
            }
            else if (this.Game.Controller.Players.Any(pl => pl.IsHuman))
            {
                if (Game.Controller.GameTree.LastNode.Equals(Game.Controller.GameTree.GameTreeRoot))
                {
                    CanUndo = false;
                }
                else
                {
                    bool undoPossible = this.Game.Controller.GameTree.PrimaryMoveTimeline.Any(
                        move =>
                    {
                        if (move.WhoMoves == StoneColor.None)
                        {
                            return(false);
                        }
                        return(this.Game.Controller.Players[move.WhoMoves].IsHuman);
                    });

                    CanUndo = undoPossible;
                }
            }
            else
            {
                // No player is a local human.
                CanUndo = false;
            }

            PassCommand.RaiseCanExecuteChanged();
            UndoCommand.RaiseCanExecuteChanged();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Authenticates this instance.
        /// </summary>
        /// <remarks>A successful execution of this method will result in a Current State of Transaction.
        /// Unsuccessful USER or PASS commands can be reattempted by resetting the Username or Password
        /// properties and re-execution of the methods.</remarks>
        /// <exception cref="Pop3Exception">
        /// If the Pop3Server is unable to be connected.
        /// If the User command is unable to be successfully executed.
        /// If the Pass command is unable to be successfully executed.
        /// </exception>
        public void Authenticate()
        {
            //Connect();

            //execute the user command.
            using (UserCommand userCommand = new UserCommand(_clientStream, Username))
            {
                ExecuteCommand <Pop3Response, UserCommand>(userCommand);
            }

            //execute the pass command.
            using (PassCommand passCommand = new PassCommand(_clientStream, Password))
            {
                ExecuteCommand <Pop3Response, PassCommand>(passCommand);
            }

            CurrentState = Pop3State.Transaction;
        }
        public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
        {
            context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
            var data = await context.Request.ReadFormAsync();

            var param    = data.Where(x => x.Key == "mst").Select(x => x.Value).FirstOrDefault();
            var userName = context.UserName.Replace("-", "");
            var mst      = param[0].Replace("-", "");
            var passWord = context.Password;

            if (string.IsNullOrEmpty(mst) || string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(passWord))
            {
                context.SetError("error", "Nhập đủ thông tin đăng nhập");
                return;
            }
            var traCuu = new TracuuHDDTContext();
            var user   = traCuu.inv_users.FirstOrDefault(x => x.username.Replace("-", "").Equals(userName.Replace("-", "")) & x.mst.Replace("-", "").Equals(mst.Replace("-", "")));

            if (user == null)
            {
                context.SetError("error_login", $"Tài khoản {context.UserName} không tồn tại");
                return;
            }
            PassCommand crypt = new PassCommand(user.password);

            if (!crypt.CheckPassword(passWord))
            {
                context.SetError("error_login", "Mật khẩu không chính xác");
                return;
            }
            var identity = new ClaimsIdentity(context.Options.AuthenticationType);

            identity.AddClaim(new Claim("username", context.UserName));
            identity.AddClaim(new Claim("ma_dt", user.ma_dt));
            identity.AddClaim(new Claim("mst", mst));
            context.Validated(identity);
        }