Пример #1
0
        /// <summary>
        /// FromJson is static method convert from Json to Statues
        /// </summary>
        /// <param name="s">is the string represented at Json</param>
        /// <returns>the Statues</returns>
        public static Statues FromJson(string s)
        {
            // split the string
            char[]   spliters = { '|', ':' };
            string[] members  = s.Split(spliters);
            Statues  statues  = new Statues();
            // parse the status back
            Status status  = (Status)Enum.Parse(typeof(Status), members[1]);
            string message = "";

            // build the string
            for (int i = 3; i < members.Length; i++)
            {
                message += members[i];
            }
            statues.SetStatues(status, message);
            return(statues);
        }
Пример #2
0
        /// <summary>
        /// execute commands
        /// </summary>
        /// <param name="commandLine">command received from the user</param>
        /// <param name="client">that requested the command</param>
        /// <returns>the status returned from the command executed</returns>
        public Status ExecuteCommand(string commandLine, TcpClient client)
        {
            // split command
            string[] arr        = commandLine.Split(' ');
            string   commandKey = arr[0];

            // check that the command is valid
            if (!commands.ContainsKey(commandKey))
            {
                Statues stat = new Statues();
                stat.SetStatues(Status.Disconnect, "Command not found");
                view.SendToClient(stat.ToJson(), client);
                return(Status.Disconnect);
            }
            // get command and execute it
            string[] args    = arr.Skip(1).ToArray();
            ICommand command = commands[commandKey];

            return(command.Execute(args, client));
        }
Пример #3
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="m">model</param>
 /// <param name="ic">view</param>
 protected Command(IModel m, IClientHandler ic)
 {
     model   = m;
     handler = ic;
     statues = new Statues();
 }