Beispiel #1
0
        public static void AddItem(TodoListItem todoListItem, Stack <ImmutableList <TodoListItem> > _stackItems)
        {
            var foundList = _stackItems.TryPeek(out var currentListItems); //check if list exists. return the list

            if (foundList == false)
            {
                _stackItems.Push(ImmutableList.Create(todoListItem));
                return;
            }
            var updatedList = currentListItems.Add(todoListItem); //add item to list

            _stackItems.Push(updatedList);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var initialReadline = Console.ReadLine();
            //var command = "";
            var pagination            = 0;
            var historyCommandPointer = 0;

            var command = _GetFromReadline(initialReadline);

            while (command.Method != CommandMethod.stop)
            {
                switch (command.Method)
                {
                case CommandMethod.add:
                {
                    var todoListItem = TodoListItem.Create(command.Instructions);
                    TodoListItem.AddItem(todoListItem, _stackItems);
                    break;
                }

                case CommandMethod.list:
                {
                    TodoListItem.ListItems(_stackItems);
                    break;
                }

                case CommandMethod.status:
                {
                    // command status items,newStatus
                    var splitString = command.Instructions.Split(",");
                    var itemList    = _stackItems.Peek();  // find list
                    TodoListItem.SetStatus(splitString, itemList, _stackItems);
                    break;
                }

                case CommandMethod.search:
                {
                    var splitString = command.Instructions.Split(" ");
                    var itemList    = _stackItems.Peek();
                    TodoListItem.Search(splitString, itemList);
                    break;
                }

                case CommandMethod.next:
                {
                    var itemList = _stackItems.Peek();
                    TodoListItem.Pagination(itemList, pagination);
                    break;
                }

                case CommandMethod.sublist:
                {
                    var splitStringSublist = command.Instructions.Split(":");
                    var itemList           = _stackItems.Peek();
                    TodoListItem.AddToSubList(splitStringSublist, itemList, _stackItems);
                    break;
                }

                case CommandMethod.mistype:
                {
                    Console.WriteLine(command.Instructions);
                    break;
                }

                case CommandMethod.unknown:
                {
                    Console.WriteLine(command.Instructions);
                    break;
                }

                case CommandMethod.undo:
                {
                    var topList = _stackItems.Pop();
                    _stackUndoItems.Push(topList);
                    break;
                }

                case CommandMethod.redo:
                {
                    var topList = _stackUndoItems.Pop();
                    _stackItems.Push(topList);
                    break;
                }
                }

                var newInstructions = Console.ReadLine();
                command = _GetFromReadline(newInstructions);
            }
        }