Esempio n. 1
0
        public void Invoke(string[] args)
        {
            var options = new OptionSet();

            options.Add(
                "?|help",
                "Show help information.",
                x =>
            {
                HelpUtility.WriteHelpInformation(
                    this.CommandResult,
                    this.Name,
                    this.Parameters,
                    this.Description,
                    options
                    );
            }
                );

            if (args == null)
            {
                this.CommandResult.ScrollToBottom = false;
                this.CommandResult.CommandContext.Deactivate();
                this.CommandResult.ClearScreen = true;
                this.CommandResult.WriteLine(DisplayMode.Inverted | DisplayMode.DontType, "Available Discussion Boards");
                var boards = _boardRepository.GetBoards(this.CommandResult.CurrentUser.IsModerator || this.CommandResult.CurrentUser.IsAdministrator);
                foreach (var board in boards)
                {
                    this.CommandResult.WriteLine();
                    var displayMode = DisplayMode.DontType;
                    if (board.ModsOnly || board.Hidden)
                    {
                        displayMode |= DisplayMode.Dim;
                    }
                    long topicCount = board.BoardID == 0
                        ? _topicRepository.AllTopicsCount()
                        : board.TopicCount(this.CommandResult.CurrentUser.IsModerator);

                    this.CommandResult.WriteLine(displayMode, "{{{0}}} {1}{2}{3}{4}{5} | {6} topics",
                                                 board.BoardID == 7 ? board.BoardID.ToString().PadLeft(3, '0') : board.BoardID.ToString(),
                                                 board.Hidden ? "[HIDDEN] " : string.Empty,
                                                 board.ModsOnly ? "[MODSONLY] " : string.Empty,
                                                 board.Locked ? "[LOCKED] " : string.Empty,
                                                 board.Anonymous ? "[ANON] " : string.Empty,
                                                 board.Name,
                                                 topicCount);

                    if (!board.Description.IsNullOrEmpty())
                    {
                        this.CommandResult.WriteLine(displayMode, "{0}", board.Description);
                    }
                }
                if (boards.Count() == 0)
                {
                    this.CommandResult.WriteLine("There are no discussion boards.");
                }
            }
            else
            {
                try
                {
                    options.Parse(args);
                }
                catch (OptionException ex)
                {
                    this.CommandResult.WriteLine(ex.Message);
                }
            }
        }