Ejemplo n.º 1
0
        private static void ModifyWatchedItems(ItemContext context)
        {
            var menu = new ConsoleMenu("Select an option:");

            menu.AddOption('a', new ConsoleMenu.MenuOption()
            {
                Description = "Add watched items by a search pattern",
                Action      = () =>
                {
                    Console.WriteLine("Enter a search pattern:");
                    var pattern = Console.ReadLine();

                    try
                    {
                        context.AddWatchedItems(pattern);
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            });
            menu.AddOption('c', new ConsoleMenu.MenuOption()
            {
                Description = "Clear watched items",
                Action      = () => context.ClearWatchedItems()
            });
            menu.AddOption('r', new ConsoleMenu.MenuOption()
            {
                Description = "Remove watched item by a search pattern",
                Action      = () =>
                {
                    Console.WriteLine("Enter a search pattern:");
                    var pattern = Console.ReadLine();

                    try
                    {
                        context.RemoveWatchedItems(pattern);
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            });
            menu.AddOption('m', new ConsoleMenu.MenuOption()
            {
                Description = "Remove watched item by an exact match",
                Action      = () =>
                {
                    Console.WriteLine("Enter the name of the watched item to remove:");
                    var name = Console.ReadLine();

                    try
                    {
                        context.RemoveWatchedItem(name);
                    }
                    catch (InvalidOperationException e)
                    {
                        Console.WriteLine(e.Message);
                    }
                }
            });

            menu.Display();
        }