internal void Write()
        {
            ForumViewEngine.DrawTextArea(this);
            ForumViewEngine.ShowCursor();

            while (true)
            {
                ConsoleKeyInfo keyInfo = Console.ReadKey(true);
                ConsoleKey     key     = keyInfo.Key;

                if (key == ConsoleKey.Backspace)
                {
                    this.Delete();
                }
                else if (this.Text.Length == this.MaxLength || forbiddenCharacters.Contains(keyInfo.KeyChar))
                {
                    Console.Beep(415, 260);
                    continue;
                }
                else if (key == ConsoleKey.Enter || key == ConsoleKey.Escape)
                {
                    break;
                }
                else
                {
                    this.AddCharacter(keyInfo.KeyChar);
                }
            }

            ForumViewEngine.HideCursor();
        }
Ejemplo n.º 2
0
        public MenuState ExecuteCommand(int index)
        {
            switch ((Command)index)
            {
            case Command.Write:
                TextArea.Write();
                Reply.Content = TextArea.Lines.ToList();
                return(MenuState.AddReply);

            case Command.Submit:
                var replyAdded = PostService.TrySaveReply(Reply, PostView.PostId);
                if (!replyAdded)
                {
                    Error = true;
                    return(MenuState.Rerender);
                }
                return(MenuState.ReplyAdded);

            case Command.Back:
                ForumViewEngine.ResetBuffer();
                return(MenuState.Back);
            }

            throw new InvalidCommandException();
        }
Ejemplo n.º 3
0
        public Engine()
        {
            this.forumViewer = new ForumViewEngine();
            this.controllers = InitializeControllers();

            this.menuController = new MenuController(this.controllers, forumViewer);
        }
Ejemplo n.º 4
0
        public MenuState ExecuteCommand(int index)
        {
            switch ((Command)index)
            {
            case Command.Write:
                this.TextArea.Write();
                this.Reply.Content = this.TextArea
                                     .Lines.ToList();
                return(MenuState.AddReply);

            case Command.Submit:
                bool isReplyAdded = PostService.TryAddReply(this.Post.PostId, this.Reply);
                if (!isReplyAdded)
                {
                    this.Error = true;
                    return(MenuState.Rerender);
                }
                return(MenuState.ReplyAdded);

            case Command.Back:
                ForumViewEngine.ResetBuffer();
                return(MenuState.Back);
            }

            throw new InvalidCommandException();
        }
Ejemplo n.º 5
0
        private void SetBuffer()
        {
            int totalLines = 24 + this.Post.Content.Count;

            if (totalLines > 30)
            {
                ForumViewEngine.SetBufferHeight(totalLines);
            }
        }
Ejemplo n.º 6
0
        public MenuController(IEnumerable <IController> controllers, ForumViewEngine forumViewer)
        {
            this.controllers = controllers.ToArray();
            this.forumViewer = forumViewer;

            this.InitializeControllerHistory();

            this.currentOptionIndex = DEFAULT_INDEX;
        }
Ejemplo n.º 7
0
        public MenuState ExecuteCommand(int index)
        {
            switch ((Command)index)
            {
            case Command.Back:
                ForumViewEngine.ResetBuffer();
                return(MenuState.Back);

            case Command.AddReply:
                return(MenuState.AddReplyToPost);
            }
            throw new InvalidCommandException();
        }
        private void SetBuffer()
        {
            int totalLines = 10 + this.Post.Content.Count;

            foreach (var reply in this.Post.Replies)
            {
                totalLines += 2 + reply.Content.Count;
            }

            if (totalLines > 30)
            {
                ForumViewEngine.SetBufferHeight(totalLines);
            }
        }
        public void Delete()
        {
            if (this.textCursorPosition > 0)
            {
                string stringBefore = this.Text.Substring(0, this.textCursorPosition);
                string stringAfter  = this.Text.Substring(this.textCursorPosition, this.Text.Length - textCursorPosition);

                stringBefore = stringBefore.Substring(0, stringBefore.Length - 1);
                this.Text    = stringBefore + stringAfter;
                this.textCursorPosition--;
                ForumViewEngine.DrawTextArea(this);
            }

            this.lines = StringProcessor.Split(this.Text);
        }
        public bool AddCharacter(char character)
        {
            if (this.Text.Length < this.MaxLength)
            {
                string stringBefore = this.Text.Substring(0, this.textCursorPosition);
                string stringAfter  = this.Text.Substring(this.textCursorPosition, this.Text.Length - this.textCursorPosition);

                this.Text = stringBefore + character + stringAfter;

                this.textCursorPosition++;
                ForumViewEngine.DrawTextArea(this);
                return(true);
            }

            return(false);
        }
Ejemplo n.º 11
0
 public void ReadCategory()
 {
     Post.Category = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }
Ejemplo n.º 12
0
 public void ReadTitle()
 {
     Post.Title = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }
Ejemplo n.º 13
0
 public void ReadUsername()
 {
     this.Username = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }
Ejemplo n.º 14
0
 public void ReadPassword()
 {
     this.Password = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }
Ejemplo n.º 15
0
 private void ReadCategory()
 {
     this.Post.Category = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }
Ejemplo n.º 16
0
 private void ReadTitle()
 {
     this.Post.Title = ForumViewEngine.ReadRow();
     ForumViewEngine.HideCursor();
 }