Beispiel #1
0
        static void Main(string[] args)
        {
#if DEBUG
            limiter = new Limiter(false);
#else
            //limiter = new Limiter(true);
#endif
            LoadGroups();

            Delegate nullAction = new Action(() => { });

            editGroupMenu = new Menu(Console.Out, Console.In, true);
            Action <Group> initEditGroupMenu = new Action <Group>((g) =>
            {
                editGroupMenu.Clear();
                editGroupMenu.AddItem(new MenuLabel("=== Editing group: " + g.Name + " ==="));
                editGroupMenu.AddItem('l', "Display group summary", new Action(() => dispGroup(g)));
                editGroupMenu.AddItem('p', "Add process to group", new Action(() => addProcToGroup(g)));
                editGroupMenu.AddItem('x', "Remove process from group", new Action(() => rmvProcFromGroup(g)));
                editGroupMenu.AddItem('d', "Add directory to group", new Action(() => addDirToGroup(g)));
                editGroupMenu.AddItem('m', "Remove directory from group", new Action(() => rmvDirFromGroup(g)));
                editGroupMenu.AddItem('t', "Set group time limit", new Action(() => setGroupTimeLimit(g)));
                editGroupMenu.AddItem('a', "Set group start time", new Action(() => setGroupStartTime(g)));
                editGroupMenu.AddItem('b', "Set group end time", new Action(() => setGroupEndTime(g)));
                editGroupMenu.AddItem('s', "Show currently running processes", new Action(() => dispGroupRunningProcs(g)));
                editGroupMenu.AddItem('u', "Update the group status", new Action(() => updateGroup(g)));
                editGroupMenu.AddItem('r', "Reset the group's timers", new Action(() => resetGroupTime(g)));
                editGroupMenu.AddItem('q', "Finish editing", new Action(() => { SaveGroups(); editGroupMenu.CloseSelf(); }));
            });

            groupMenu = new Menu(Console.Out, Console.In, true);
            Action initGroupMenu = new Action(() =>
            {
                LoadGroups();
                groupMenu.Clear();
                groupMenu.AddItem('l', "List groups", new Action(listGroups));
                groupMenu.AddItem('a', "Add group", new Action(() => { initEditGroupMenu(addGroup()); editGroupMenu.Run(); }));
                groupMenu.AddItem('e', "Edit group", new Action(() =>
                {
                    for (int i = 0; i < groups.Count; i++)
                    {
                        groupMenu.PrintLine(i + ". " + groups[i].Name);
                    }
                    int g = groupMenu.RequestIntInRange(0, groups.Count, -1);
                    initEditGroupMenu(groups[g]);
                    editGroupMenu.Run();
                }));
                groupMenu.AddItem('d', "Delete group", new Action(rmvGroup));
                groupMenu.AddItem('q', "Return to main menu", groupMenu.CloseSelf);
                SaveGroups();
            });

            procMenu = new Menu(Console.Out, Console.In, true);
            Action initProcMenu = new Action(() =>
            {
                procMenu.Clear();
                procMenu.AddItem('s', "Show available processes", new Action(dispRunningProcs));
                procMenu.AddItem('l', "List used processes", new Action(listProcs));
                procMenu.AddItem('q', "Return to main menu", procMenu.CloseSelf);
            });

            Menu mainMenu = new Menu(Console.Out, Console.In, true);
#if DEBUG
            mainMenu.AddItem('t', "Check status of limiter service", new Action(() => mainMenu.PrintLine(limiter.Status)));
            mainMenu.AddItem('s', "Start limiter service", new Action(limiter.StartThreaded));
            mainMenu.AddItem('x', "Stop limiter service", new Action(limiter.StopThreaded));
            mainMenu.AddItem('r', "Refresh limiter service settings", new Action(() => limiter.Command(LIMITER_COMMAND.REFRESH)));
#endif
            mainMenu.AddItem('g', "Edit group settings", new Action(() => { initGroupMenu(); groupMenu.Run(); }));
            mainMenu.AddItem('p', "Edit process settings", new Action(() => { initProcMenu(); procMenu.Run(); }));
            mainMenu.AddItem('q', "Quit Process Limiter Manager", mainMenu.CloseSelf);

#if DEBUG
            limiter.StartThreaded();
            mainMenu.Run();
            limiter.StopThreaded();
#else
            mainMenu.Run();
#endif
        }