Beispiel #1
0
        /// <summary>
        /// Run application
        /// </summary>
        /// <returns>Returns false if user presses 'q' otherwise true</returns>
        public bool Run()
        {
            //Instructions. Only visible when app starts
            if (_isIntroductionVisible)
            {
                _view.ShowIntroduction();
                _isIntroductionVisible = false;
            }

            var input = _view.UserInput();

            //Quit application
            if (input.ToLower() == "q")
            {
                return(false);
            }

            //Send message to server
            if (Validate.IsValid(input))
            {
                try
                {
                    _view.ShowSendingConfirmation();
                    var response = _sender.Post(input);

                    if (response == HttpStatusCode.OK)
                    {
                        _view.ShowSuccessfullySent();
                    }
                    else
                    {
                        _view.ErrorMessage();
                    }
                }
                catch (WebException ex)
                {
                    _view.ErrorMessage(ex);
                }
            }
            else
            {
                _view.NotValidErrorMessage();
            }


            return(true);
        }