コード例 #1
0
        public ToDoController(
            IConfigService configService,
            TaskList taskList,
            string archiveFilePath,
            IDictionary <string, ITodoCommand> commands,
            ITaskListView taskListView)
        {
            _configService   = configService;
            _commands        = commands;
            _taskListView    = taskListView;
            _archiveFilePath = archiveFilePath;

            _context = new CommandContext()
            {
                TaskList    = taskList,
                DebugLevel  = Int32.Parse(configService.GetValue("debug_level")),
                GroupByType = DotNetExtensions.ParseEnum <GroupByType>(configService.GetValue(ConfigService.GROUP_BY_TYPE_KEY), GroupByType.None),
                SortType    = DotNetExtensions.ParseEnum <SortType>(configService.GetValue(ConfigService.SORT_TYPE_KEY), SortType.Project),
                Filter      = new TaskFilter(configService.GetValue(ConfigService.FILTER_TEXT_KEY)),
            };

            Console.WriteLine($"Command context: DebugLevel: {_context.DebugLevel}, GroupByType: {_context.GroupByType.ToString()}, SortType: {_context.SortType.ToString()}, Filter: {_context.Filter}");

            bool listOnStart;

            if (Boolean.TryParse(configService.GetValue("list_on_start"), out listOnStart))
            {
                _context.ListOnStart = listOnStart;
            }

            bool listAfterCommand;

            if (Boolean.TryParse(configService.GetValue("list_after_command"), out listAfterCommand))
            {
                _context.ListAfterCommand = listAfterCommand;
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: lamronby/todotxtconsole
        /*
         * Options:
         *  f|TodoFile
         *      Specify the todo file.
         *  a|ArchiveFile
         *      Specify the archive file.
         *  s|SortBy
         *      Specify a sort. Default is ?, valid values are none, alphabetical,
         *      completed, context, duedate, priority, project.
         *  g|GroupBy
         *      Specify a grouping. Default is none, valid values are none, context,
         *      project, or priority.
         */
        static void Main(string[] args)
        {
            var configService = new ConfigService();

            var showHelp = false;
            var p        = new OptionSet()
            {
                { "f|TodoFile=", "The todo file", f => configService.SetValue(ConfigService.FILE_PATH_KEY, f) },
                { "a|ArchiveFile=", "The archive file", a => configService.SetValue(ConfigService.ARCHIVE_FILE_PATH_KEY, a) },
                { "s|SortBy=", "Specify a sort.", s => configService.SetValue(ConfigService.SORT_TYPE_KEY, DotNetExtensions.ParseEnum <SortType>(s, SortType.None).ToString()) },
                { "g|GroupBy=", "Specify a grouping.", g => configService.SetValue(ConfigService.GROUP_BY_TYPE_KEY, DotNetExtensions.ParseEnum <GroupByType>(g, GroupByType.Project).ToString()) },
                { "h|help", "Display help", v => showHelp = v != null },
            };

            List <string> extra;

            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.Write("ToDoConsole: ");
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `ToDoConsole help' for help.");
                return;
            }

            if (showHelp)
            {
                ShowHelp(p);
                return;
            }

            foreach (var e in extra)
            {
                Console.WriteLine(e);
            }

            var filePath = configService.GetValue("file_path");

            if (string.IsNullOrEmpty(filePath))
            {
                Console.WriteLine("Cannot continue, FilePath not configured.");
                return;
            }

            var archiveFilePath = configService.GetValue("archive_file_path");

            if (string.IsNullOrEmpty(archiveFilePath))
            {
                // Don't use an archive file, just archive within the main file
                Console.WriteLine($"Archive file not specified, will archive into {filePath}");
                archiveFilePath = filePath;
            }

            // TODO Create file if it doesn't exist.
            if (!File.Exists(filePath))
            {
                throw new ArgumentException($"Todo file path does not exist: {filePath}");
            }

            if (!File.Exists(archiveFilePath))
            {
                throw new ArgumentException($"Archive file path does not exist: {archiveFilePath}");
            }
            var taskList = LoadTasks(filePath);

            var commands = LoadCommands();

            IToDoController controller = new ToDoController(configService, taskList, archiveFilePath, commands, new TaskListView());

            controller.Run();
        }