Beispiel #1
0
        public static int procCounter(ProcLister listOfProcs)
        {
            int count = 0;

            foreach (RunProc item in listOfProcs.ListedProcs)
            {
                count++;
            }
            return(count);
        }
Beispiel #2
0
        public static void XmlWriter(ProcLister procList)
        {
            //ProcLister listOfProcs = new ProcLister(RunProc.processCreate());

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

            using (TextWriter writer = new StreamWriter("comment.xml"))
            {
                serializer.Serialize(writer, procList);
            }
        }
Beispiel #3
0
 public ProcLister procCommenter(ProcLister listOfProcs, string id, string comment)
 {
     foreach (RunProc proc in listOfProcs.ListedProcs)
     {
         if (proc.ProcId.ToString().Equals(id))
         {
             proc.Comment = comment;
         }
     }
     return(listOfProcs);
 }
Beispiel #4
0
 public bool procSearch(ProcLister listOfProcs, string id)
 {
     foreach (RunProc proc in listOfProcs.ListedProcs)
     {
         if (proc.ProcId.ToString().Equals(id))
         {
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Beispiel #5
0
 public void procPrinter(ProcLister procList)
 {
     //ProcLister procList = new ProcLister(RunProc.processCreate());
     int[] wordLength = new int[] { 0, 0, 0, 0 };
     foreach (RunProc proc in procList.ListedProcs)
     {
         if (proc.ProcId.ToString().Length > wordLength[0])
         {
             wordLength[0] = proc.ProcId.ToString().Length;
         }
         if (proc.ProcName.Length > wordLength[1])
         {
             wordLength[1] = proc.ProcName.Length;
         }
         if (proc.RunningTime.ToString().Length > wordLength[2])
         {
             wordLength[2] = proc.RunningTime.ToString().Length;
         }
         try
         {
             if (proc.Comment.Length > wordLength[3])
             {
                 wordLength[3] = proc.Comment.Length;
             }
         }
         catch (NullReferenceException)
         {
             if (wordLength[3] < 1)
             {
                 wordLength[3] = 1;
             }
         }
     }
     foreach (RunProc proc in procList.ListedProcs)
     {
         Console.WriteLine(string.Format("|{0}|{1}|{2}|{3}|", centeredString(proc.ProcId.ToString(), wordLength[0]), centeredString(proc.ProcName, wordLength[1]), centeredString(proc.RunningTime.ToString(), wordLength[2]), centeredString(proc.Comment, wordLength[3])));
         //Console.WriteLine($"{{0,{wordLength[0]}}} {{1,{wordLength[1]}}} {{2,{wordLength[2]}}} {{3,{wordLength[3]}}}", proc.ProcId,proc.ProcName,proc.RunningTime,proc.Comment);
         //Console.WriteLine(string.Format($"{{0,{wordLength[0]}}} {2,{3}} {4,{5}} {6,{7}}", proc.ProcId.ToString(), proc.ProcName, wordLength[1], proc.RunningTime.ToString(), wordLength[2], proc.Comment, wordLength[3]));
         //Console.WriteLine(proc.ProcId + " " + proc.ProcName + " " + proc.RunningTime + " " + proc.Comment);
     }
 }
Beispiel #6
0
        public void start()
        {
            string[] menupoints = new string[]
            {
                "Running processes",
                "Realtime running processes",
                "System usage",
                "Saving running processes to file",
                "Saving data to file with comments",
                "Read data from file"
            };


            while (true)
            {
                showMenu(menupoints);
                Console.WriteLine("Type in your choice: ");
                int choice = int.Parse(Console.ReadLine());
                switch (choice)
                {
                case 1:
                {
                    Console.Clear();
                    Console.WriteLine("Currently running processes: ");
                    ProcLister listOfProcs  = new ProcLister(RunProc.processCreate());
                    ProcLister listFromFile = new ProcLister();
                    listFromFile = XmlHandler.XmlReader();
                    foreach (RunProc proc1 in listOfProcs.ListedProcs)
                    {
                        foreach (RunProc proc2 in listFromFile.ListedProcs)
                        {
                            if (proc1.ProcId.Equals(proc2.ProcId) && proc1.ProcName.Equals(proc2.ProcName))
                            {
                                proc1.Comment = proc2.Comment;
                            }
                        }
                    }
                    listOfProcs.procPrinter(listOfProcs);
                    Console.WriteLine("Press enter to exit!");
                    Console.ReadLine();
                    Console.Clear();
                    break;
                }

                case 2:
                {
                    while (true)
                    {
                        Console.Clear();
                        if (Console.KeyAvailable && Console.ReadKey(true).Key == ConsoleKey.X)
                        {
                            break;
                        }
                        Console.WriteLine("Press x to exit. Currently running processes: ");
                        ProcLister listOfProcs  = new ProcLister(RunProc.processCreate());
                        ProcLister listFromFile = new ProcLister();
                        listFromFile = XmlHandler.XmlReader();
                        foreach (RunProc proc1 in listOfProcs.ListedProcs)
                        {
                            foreach (RunProc proc2 in listFromFile.ListedProcs)
                            {
                                if (proc1.ProcId.Equals(proc2.ProcId) && proc1.ProcName.Equals(proc2.ProcName))
                                {
                                    proc1.Comment = proc2.Comment;
                                }
                            }
                        }
                        listOfProcs.procPrinter(listOfProcs);
                        Thread.Sleep(5000);
                    }
                    break;
                }

                case 3:
                {
                    Console.Clear();

                    Console.WriteLine("Press x to exit. ");
                    SystemUsage.getCurrentCpuUsage();

                    break;
                }

                case 4:
                {
                    Console.Clear();
                    ProcLister listOfProcs = new ProcLister(RunProc.processCreate());
                    XmlHandler.XmlWriter(listOfProcs);
                    Console.WriteLine("Data saved!");
                    break;
                }

                case 5: {
                    Console.Clear();
                    ProcLister asd = new ProcLister(RunProc.processCreate());
                    asd.procPrinter(asd);

                    while (true)
                    {
                        char writeChoice;
                        Console.WriteLine("Do you want to write a comment y/n ?");
                        writeChoice = char.Parse(Console.ReadLine());
                        if (writeChoice == 'y' || writeChoice == 'Y')
                        {
                            string processId;
                            Console.WriteLine("Which process do you want to comment on? Type in process id: ");
                            processId = Console.ReadLine();
                            if (asd.procSearch(asd, processId) == false)
                            {
                                Console.WriteLine("There is no process running with this ID.");
                            }
                            else
                            {
                                Console.WriteLine("Type in your comment: ");
                                string comment = Console.ReadLine();
                                asd.procCommenter(asd, processId, comment);
                            }
                        }
                        else if (writeChoice == 'n' || writeChoice == 'N')
                        {
                            break;
                        }
                        else
                        {
                            Console.WriteLine("Answer with 'y' or 'n' character!");
                        }
                    }


                    XmlHandler.XmlWriter(asd);
                    Console.Clear();
                    break;
                }

                case 6:
                {
                    Console.Clear();

                    Console.WriteLine();
                    ProcLister asd = XmlHandler.XmlReader();
                    asd.procPrinter(asd);
                    Console.WriteLine("Press enter to exit!");
                    Console.ReadLine();

                    Console.Clear();
                    break;
                }

                case 0:
                {
                    Environment.Exit(0);
                    break;
                }
                }
            }
        }