Exemplo n.º 1
0
 public GetRecentQuestionsConsoleAdapter(JsonStore store, IWebRequester web, SingleStore <Action <string[]> > currentQuestion)
 {
     _store           = store;
     _throttle        = new ThrottleChecker(_store);
     _web             = web;
     _currentQuestion = currentQuestion;
 }
Exemplo n.º 2
0
        public static void Main(string[] args)
        {
            _currentQuestion = new SingleStore <Action <string[]> >();
            _store           = new JsonStore(new HardDrive(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
                                                           + "\\StackoverflowRecentQuestions"));
            var web = new WebRequester();

            _questionGetter    = GetRecentQuestionsConsoleAdapter.Create(_store, web, _currentQuestion);
            _intervalQuestions = IntervalQuestionsPresenter.Create(_questionGetter, _store);

            Add("ViewSettings", (_) => { Console.WriteLine(_store.Read <Options>("Options").ToString()); },
                "Syntax: ViewSettings", "Writes the current settings to the console");
            Add("SetIntervalForQuestions", _intervalQuestions.SetInterval, "Syntax: SetIntervalForQuestions <Minutes>",
                "Sets the interval for when you are presented questions",
                "Syntax: SetIntervalForQuestions",
                "Disables automatic presentation of questions");
            Add("EnableReminder", (_) => _intervalQuestions.EnableReminder(), "Syntax: EnableReminder",
                "Makes the program play a sound when you are presented questions");
            Add("DisableReminder", (_) => _intervalQuestions.DisableReminder(), "Syntax: DisableReminder",
                "Makes the program no longer play a sound when you are presented questions");
            Add("SetDefaultTags", _questionGetter.SetDefaultTags, "Syntax: SetDefaultTags [<Tag1>] [<Tag2>]...",
                "Sets the default tags used in queries");
            Add("SetDefaultSite", _questionGetter.SetDefaultSite, "Syntax: SetDefaultSite <Site>",
                "Sets the default site used in queries");
            Add("SetDefaultAmountOfQuestions", _questionGetter.SetDefaultAmountOfQuestions, "Syntax: SetDefaultSite <Number of questions>",
                "Sets the default amount of questions. The number has to within 1 and 100");
            Add("GetRecentQuestions", async(s) => await _questionGetter.Get(s),
                "Syntax: GetRecentQuestions [<Within Last X Days>] [<Page>]",
                "Gets questions within the specified time with the default tags, and site",
                "Syntax: GetRecentQuestions <Within Last X Days> <Page> <Site> [<Tag1>] [<Tag2>]...",
                "Gets questions within the specified time with any of the specified tags if any, and the site");

            Add("Exit", (_) => Quiting = true, "Syntax: Exit", "Exits the program");
            Add("Quit", (_) => Quiting = true, "Syntax: Quit", "Exits the program");
            Add("Clear", (_) => Console.Clear(), "Syntax: Clear", "Clears the console");
            Add("Help", (s) =>
            {
                if (s.Length == 0)
                {
                    Console.WriteLine("Valid Commands:");
                    foreach (var help in _commandsHelp)
                    {
                        WriteHelpSection(help);
                    }
                }
                else
                {
                    foreach (var command in s)
                    {
                        if (_commands.ContainsKey(command.ToUpper()))
                        {
                            WriteHelpSection(new KeyValuePair <string, string[]>(command.ToUpper(), _commandsHelp[command.ToUpper()]));
                        }
                        else
                        {
                            Console.WriteLine(command + " not recognized");
                        }
                    }
                }
            }, "Syntax: Help", "Writes the help section of each command",
                "Syntax: Help <Command> [<Command>] [<Command>]...", "Writes the help section of those commands");

            if (args.Length == 0)
            {
                Console.WriteLine("Type commands. Use the Help command for information about commands");
                while (!Quiting)
                {
                    ResolveCommand(ReadCommandLineArgs(Console.ReadLine()));
                }
            }
            else
            {
                ResolveCommand(ReadCommandLineArgs(string.Join(" ", args)));
            }
            Environment.Exit(Environment.ExitCode);
        }
Exemplo n.º 3
0
        public static GetRecentQuestionsConsoleAdapter Create(JsonStore store, IWebRequester web, SingleStore <Action <string[]> > currentQuestion)
        {
            var getter = new GetRecentQuestionsConsoleAdapter(store, web, currentQuestion);

            getter.Initialize();
            return(getter);
        }