Example #1
0
        public static void ListProcesses()
        {
            ConsoleSpinner spinIt = new ConsoleSpinner();

            spinIt.Delay = 200;
            while (true)
            {
                if (!Console.KeyAvailable)
                {
                    Dictionary <string, long> keyValuePairs = new Dictionary <string, long>();
                    Process[] processes = Process.GetProcesses();
                    foreach (Process process in processes)
                    {
                        if (keyValuePairs.ContainsKey(process.ProcessName))
                        {
                            keyValuePairs[process.ProcessName] += process.WorkingSet64;
                        }
                        else
                        {
                            keyValuePairs.Add(process.ProcessName, process.WorkingSet64);
                        }
                    }


                    var myList = keyValuePairs.ToList();
                    myList.Sort((pair1, pair2) => pair1.Value.CompareTo(pair2.Value));

                    for (int i = myList.Count - 1; i >= myList.Count - 10; i--)
                    {
                        Console.Write("{0} | {1}", myList[i].Key, (Convert.ToDouble(myList[i].Value) / (1024 * 1024)).ToString("N4") + " MB\n");
                    }
                    Console.WriteLine();
                    spinIt.Turn("Workin In Online Mode boi ", 0);
                    Console.SetCursorPosition(0, Console.CursorTop - 11);
                }
                else
                {
                    Console.Clear();
                    break;
                }
            }
        }
Example #2
0
        public void doIt(int idx)
        {
            ConsoleSpinner load = new ConsoleSpinner();

            load.Delay = 350;

            try
            {
                string file2open = path + names[idx - 1];
                for (int i = 0; i < 8; i++)
                {
                    load.Turn("Loadin ", 6);
                }
                Console.WriteLine();

                ProcessCollection processes = null;
                string            xmlPath   = file2open;

                XmlSerializer serializer = new XmlSerializer(typeof(ProcessCollection));

                StreamReader reader = new StreamReader(xmlPath);
                processes = (ProcessCollection)serializer.Deserialize(reader);
                reader.Close();
                Diplay.PrintLine();
                for (int i = 0; i < processes.Process.Length; i++)
                {
                    Diplay.PrintRow(new string[] { processes.Process[i].Name, processes.Process[i].ID, processes.Process[i].Memory });
                    Diplay.PrintLine();
                }
            }
            catch (ArgumentOutOfRangeException)
            {
                for (int i = 0; i < 8; i++)
                {
                    load.Turn("Loadin ", 7);
                }
                Console.WriteLine("Reason: No Id like that");
            }
        }
Example #3
0
        static void Main(string[] args)
        {
            string ls = null;

            string[] commands = new string[] { "ls - List all processes", "ls -l - List the first 10 processes in online mode",
                                               "kill - kill a process by ID", "save - save the listed session", "load - Load one of the previously saved sessions", "cls - Clear Console", "q - Quit" };

            while (ls != "q")
            {
                //Comands "commands xd"
                Console.Write("User@win10> ");
                ls = Console.ReadLine();
                if (ls == "ls")
                {
                    listAll();
                    Console.WriteLine("Comment? (Y/N)");
                    wannaComment(Console.ReadLine());
                }

                if (ls == "ls -l")
                {
                    //Parallel.Invoke(() => ListProcessesByRam.ListProcesses(), () => spin());
                    Console.Clear();
                    ListProcessesByRam.ListProcesses();
                }

                if (ls == "cls")
                {
                    Console.Clear();
                }

                if (ls == "kill")
                {
                    listAll();
                    Console.WriteLine("who you wanna kill dawg?");
                    Console.Write("ID: ");
                    string idToKill = null;
                    idToKill = Console.ReadLine();
                    var  processlist = allProcesses();
                    bool haveID      = false;

                    try
                    {
                        foreach (Process process in processlist)
                        {
                            if (Convert.ToInt32(idToKill) == process.Id)
                            {
                                haveID = true;
                            }
                            else
                            {
                                haveID = false;
                            }
                        }

                        ConsoleSpinner killAnimation = new ConsoleSpinner();
                        killAnimation.Delay = 500;

                        Process killable = Process.GetProcessById(Convert.ToInt32(idToKill));
                        Console.WriteLine("Are you sure u wanna kill {0} (y/n)?", killable.ProcessName);
                        string ans = Console.ReadLine();
                        if (ans == "Y" || ans == "y")
                        {
                            killable.Kill();
                            for (int i = 0; i < 8; i++)
                            {
                                killAnimation.Turn("I'm killin it m8  ", 5);
                            }
                            Console.WriteLine();
                            Console.WriteLine("i think he dieded");
                        }
                        else
                        {
                            Console.WriteLine("{0} survives this time", killable.ProcessName);
                        }
                    }
                    catch (FormatException)
                    {
                        Console.WriteLine("id's in windows are integer numbers m8");
                    }
                    catch (Exception) when(haveID == false)
                    {
                        Console.WriteLine("Nah m8 go fck urself no id like that");
                    }
                }

                if (ls == "save")
                {
                    listAll();
                    Console.WriteLine("Save this session to an XML? (y/n)");
                    string ans = Console.ReadLine();
                    if (ans == "Y" || ans == "y")
                    {
                        Xml.saveXml(saveSession());
                        Console.WriteLine("saved!");
                    }
                }

                if (ls == "load")
                {
                    LoadSession test = new LoadSession();
                    for (int i = 0; i < test.names.Count; i++)
                    {
                        Console.WriteLine("{0}. \t{1} -- \tCreated on {2}.{3}.{4} at {5}:{6}:{7}", i + 1, test.names[i], test.year[i], test.month[i], test.day[i], test.hour[i], test.minute[i], test.second[i]);
                    }
                    Console.Write("Load: ");
                    int choice;
                    try
                    {
                        choice = Convert.ToInt32(Console.ReadLine());
                        //Console.WriteLine(choice);
                        test.doIt(choice);
                    }

                    catch (FormatException)
                    {
                        Console.WriteLine("the id must be a numba");
                    }
                }

                else
                {
                    Console.WriteLine();
                    for (int i = 0; i < commands.Length; i++)
                    {
                        Console.WriteLine(commands[i]);
                    }
                    Console.WriteLine();
                }
            }
        }