Пример #1
0
        /// <summary>
        /// Gets a string of the full stack trace of a process or of some of its threads
        /// </summary>
        /// <param name="args">
        ///	*required*	args[0] = process id
        ///	*optional*  args[1]	= list of thread ids seperated by commas ex. 222,323,2322,1212
        /// </param>
        /// <returns>false if arguments are incorrect</returns>
        private string GetStackTraceString(int processId, List <int> threadIDs)
        {
            string stackTrace = "";
            ProcessInfoCollection processCollection = ProcessInfoCollection.SingleProcessCollection;
            ProcessInfo           procInfo          = null;

            try
            {
                procInfo    = processCollection[processId];
                stackTrace += String.Format(CultureInfo.CurrentCulture.NumberFormat, "{3}{2} {0} [PID: {1}] {3}", procInfo.ShortName, procInfo.ProcessId, mainStrings.GetString("stackTraceFor"), Environment.NewLine);
                List <string> stackList = new List <string>(procInfo.GetDisplayStackTrace(threadIDs, stackDepth));
                foreach (string line in stackList)
                {
                    stackTrace += line;
                }
            }
            catch (COMException ex)
            {
                if (procInfo != null)
                {
                    procInfo.Dispose();
                }
                Debug.WriteLine(ex.ToString());

                errorMessage = mainStrings.GetString("Error") + ": " + mainStrings.GetString("invalidProcOrThread");
                return("");
            }
            catch (NullReferenceException)
            {
                errorMessage = mainStrings.GetString("Error") + ": " + mainStrings.GetString("invalidProcOrThread");
                return("");
            }
            return(stackTrace);
        }
Пример #2
0
        public void GetProcessInfoCollectionTest()
        {
            ProcessInfoCollection expected = null;
            ProcessInfoCollection actual;

            actual = ProcessInfoCollection.SingleProcessCollection;

            Assert.AreNotEqual(expected, actual, "Microsoft.Mse.Library.ProcessInfoCollection.GetProcessInfoCollection did not return the expected value.");
        }
Пример #3
0
        public void RefreshProcessListTest()
        {
            ProcessInfoCollection target = ProcessInfoCollection.SingleProcessCollection;

            target.RefreshProcessList();
            if (target.ProccessHash.Count <= 0)
            {
                Assert.Fail("Microsoft.Mse.Library.ProcessInfoCollection.RefreshProcessListTest failed.");
            }
        }
Пример #4
0
        public void ItemTest()
        {
            ProcessInfoCollection target = ProcessInfoCollection.SingleProcessCollection;

            target.RefreshProcessList();
            ProcessInfo val   = TestEnvironment.testProcessInfo;
            int         value = val.ProcessId;

            Assert.AreEqual(target[value].ProcessId, value, "Microsoft.Mse.Library.ProcessInfoCollection.ItemTest did not return the expected value.");
        }
Пример #5
0
 public Run( Profiler p, ProjectInfo pi )
 {
     _p = p;
     _dtStart = DateTime.Now;
     _dtEnd = DateTime.MaxValue;
     _rs = RunState.Initializing;
     _pic = new ProcessInfoCollection();
     _pi = pi;
     _rmcMessages = new RunMessageCollection();
     _bSuccess = false;
 }
Пример #6
0
        public void GetProcessTest()
        {
            ProcessInfoCollection target = ProcessInfoCollection.SingleProcessCollection;

            target.RefreshProcessList();
            ProcessInfo expected = TestEnvironment.testProcessInfo;
            ProcessInfo actual   = target.GetProcess(expected.ProcessId);

            Assert.AreEqual(expected.ProcessId, actual.ProcessId, "Microsoft.Mse.Library.ProcessInfoCollection.GetProcess did not return the expecte" +
                            "d value.");
        }
Пример #7
0
        public void GetEnumeratorTest()
        {
            ProcessInfoCollection target   = ProcessInfoCollection.SingleProcessCollection;
            IEnumerator           expected = null;
            IEnumerator           actual;

            actual = target.GetEnumerator();

            Assert.AreNotEqual(expected, actual, "Microsoft.Mse.Library.ProcessInfoCollection.GetEnumerator did not return the expe" +
                               "cted value.");
        }
Пример #8
0
 public Run(Profiler p, ProjectInfo pi)
 {
     _p           = p;
     _dtStart     = DateTime.Now;
     _dtEnd       = DateTime.MaxValue;
     _rs          = RunState.Initializing;
     _pic         = new ProcessInfoCollection();
     _pi          = pi;
     _rmcMessages = new RunMessageCollection();
     _bSuccess    = false;
 }
Пример #9
0
 /// <summary>
 /// Kill a process
 /// </summary>
 /// <param name="args">
 ///  *required*	args[0] = process id
 /// </param>
 /// <returns>false if arguments are incorrect</returns>
 private bool KillProcess(int processId)
 {
     try
     {
         ProcessInfoCollection processCollection = ProcessInfoCollection.SingleProcessCollection;
         processCollection[processId].Kill();
     }
     catch (NullReferenceException)
     {
         errorMessage = mainStrings.GetString("Error") + ": " + mainStrings.GetString("killIdError") + " \"" + processId + "\"";
         return(false);
     }
     return(true);
 }
        /// <summary>
        /// Gets the running processes.
        /// </summary>
        private void GetRunningProcesses()
        {
            ProcessInfoCollection.Clear();

            foreach (Process currentProcess in Process.GetProcesses())
            {
                try {
                    ProcessInfoCollection.Add(new ProcessInformation()
                    {
                        ProcessId   = currentProcess.Id,
                        ProcessName = currentProcess.ProcessName,
                        Icon        = DataExchange.ExtractIcon(currentProcess.MainModule.FileName)
                    });
                } catch (Exception) {
                }
            }
        }
Пример #11
0
        /// <summary>
        /// Print the list of processes
        /// </summary>
        /// <param name="args">
        /// *optional*	args[0] = true mean show all details
        /// </param>
        /// <returns>false if arguments are incorrect</returns>
        private bool PrintProcessList()
        {
            try
            {
                ProcessInfoCollection processCollection = ProcessInfoCollection.SingleProcessCollection;
                processCollection.RefreshProcessList();
                //print all the managed processes

                StringBuilder processListSb = new StringBuilder();
                string        columnHead    = String.Format(CultureInfo.CurrentCulture.NumberFormat, "{0,-10}{1}{2}", "PID", mainStrings.GetString("processName"), Environment.NewLine);
                if (!String.IsNullOrEmpty(saveTo))
                {
                    processListSb.Append(columnHead);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.Write(columnHead);
                    Console.ResetColor();
                }
                foreach (ProcessInfo procInf in processCollection)
                {
                    processListSb.AppendFormat(CultureInfo.CurrentCulture.NumberFormat, "{0,-10}{1}{2}", procInf.ProcessId, procInf.ShortName, Environment.NewLine);
                }

                if (!String.IsNullOrEmpty(saveTo))
                {
                    PrintToFile(processListSb.ToString(), false);
                }
                else
                {
                    Console.Write(processListSb.ToString());
                }
            }
            catch (COMException ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            catch (NullReferenceException ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(true);
        }
Пример #12
0
        /// <summary>
        /// Print all the managed threads of a process
        /// </summary>
        /// <param name="args">
        /// *required*	args[0] = process id
        /// </param>
        /// <returns>false if arguments are incorrect</returns>
        private bool PrintThreadList(int processId)
        {
            StringBuilder threadListSb = new StringBuilder();
            ProcessInfo   procInfo     = null;

            try
            {
                ProcessInfoCollection processCollection = ProcessInfoCollection.SingleProcessCollection;
                procInfo = processCollection[processId];
                procInfo.RefreshProcessInfo();

                threadListSb.AppendFormat(CultureInfo.CurrentCulture.NumberFormat, "{3}{2} {0} [PID: {1}] {3}", procInfo.GeneralProcessInfo.ProcessName, procInfo.ProcessId, mainStrings.GetString("threadsOf"), Environment.NewLine);
                foreach (ThreadInfo threadInfo in procInfo.Threads)
                {
                    threadListSb.AppendFormat(CultureInfo.CurrentCulture.NumberFormat, "{1}# {0}{2}", threadInfo.ThreadId, mainStrings.GetString("threadWord"), Environment.NewLine);
                }

                if (!String.IsNullOrEmpty(saveTo))
                {
                    PrintToFile(threadListSb.ToString(), false);
                }
                else
                {
                    Console.Write(threadListSb.ToString());
                }
            }
            catch (COMException ex)
            {
                if (procInfo != null)
                {
                    procInfo.Dispose();
                }
                Debug.WriteLine(ex.ToString());
            }
            catch (NullReferenceException ex)
            {
                Debug.WriteLine(ex.ToString());
            }

            return(true);
        }
Пример #13
0
        /// <summary>
        /// Display info and data regarding the given process
        /// </summary>
        /// <param name="processId">Process to display info of</param>
        /// <returns></returns>
        private bool PrintProcessInfo(int processId)
        {
            ProcessInfoCollection processCollection = ProcessInfoCollection.SingleProcessCollection;
            ProcessInfo           procInfo          = null;

            try
            {
                procInfo = processCollection[processId];
                processData.ChangeDataInstance(procInfo);

                string dataString = String.Format(CultureInfo.CurrentCulture.NumberFormat, "{0} {1} [PID: {2}]{3}", mainStrings.GetString("processInfoFor"), procInfo.ShortName, processId, Environment.NewLine);
                foreach (string key in processData.ProcessData.Keys)
                {
                    dataString += String.Format(CultureInfo.CurrentCulture.NumberFormat, "{0,-25}{1}{2}", key + ":", processData.ProcessData[key](), Environment.NewLine);
                }

                if (!String.IsNullOrEmpty(saveTo))
                {
                    PrintToFile(dataString, false);
                }
                else
                {
                    Console.WriteLine(dataString);
                }
            }
            catch (COMException ex)
            {
                Debug.WriteLine(ex.ToString());
            }
            catch (ArgumentNullException)
            {
                errorMessage = mainStrings.GetString("Error") + ": " + mainStrings.GetString("processIdError") + " \"" + processId + "\"";
                return(false);
            }

            return(true);
        }
Пример #14
0
 public Run()
 {
     _rmcMessages = new RunMessageCollection();
     _pic = new ProcessInfoCollection();
 }
Пример #15
0
 public Run()
 {
     _rmcMessages = new RunMessageCollection();
     _pic         = new ProcessInfoCollection();
 }