示例#1
0
        private void HandleSessionCommunication(IHomeSession homeSession)
        {
            using (homeSession.getOnMessageRecievedObservable().Subscribe(
                onNext: msg =>
                    {
                        var commandParser = new CommandParser(mDeviceRepository, mUserRepository, homeSession);
                        var commandExecutor = new CommandExecutor(commandParser);
                        var resp = commandExecutor.ExecuteCommand(homeSession, msg);

                        homeSession.Write(resp);
                    },
                 onError: (error) => { Console.WriteLine("error occured: " + error); }))
            {

            }
        }
示例#2
0
        public string ExecuteCommand(IHomeSession homeSession, string message)
        {
            ICommand command;

            try
            {
                command = mCommandParser.Parse(message);
            }
            catch (CommandParsingExecption execption)
            {
                return execption.Message;
            }

            if (!homeSession.IsLoggedIn() && command.GetType() != typeof (Login))
            {
                return "Not Logged In";
            }

            //homeSession.Write(command.CanExecute() ? command.Execute() : "Cannot Execute Command");
            return (command.CanExecute() ? command.Execute() : "Cannot Execute Command");
        }