aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Tango.Core/ExtensionMethods
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2018-09-04 17:01:08 +0300
committerRoy Ben-Shabat <Roy@Twine-s.com>2018-09-04 17:01:08 +0300
commit76796ca52a69cfce922be253d6e9207ccbfd09a7 (patch)
tree17b9871d793e6d4b5fbaed297280cf137f009bb8 /Software/Visual_Studio/Tango.Core/ExtensionMethods
parent3473064786b9a1d29a1d1334d1a189d1c8d369bc (diff)
downloadTango-76796ca52a69cfce922be253d6e9207ccbfd09a7.tar.gz
Tango-76796ca52a69cfce922be253d6e9207ccbfd09a7.zip
Started working on Test Studio...
Machine Studio v3.4.42
Diffstat (limited to 'Software/Visual_Studio/Tango.Core/ExtensionMethods')
-rw-r--r--Software/Visual_Studio/Tango.Core/ExtensionMethods/ProcessExtensions.cs44
1 files changed, 44 insertions, 0 deletions
diff --git a/Software/Visual_Studio/Tango.Core/ExtensionMethods/ProcessExtensions.cs b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ProcessExtensions.cs
new file mode 100644
index 000000000..43bf0f5a3
--- /dev/null
+++ b/Software/Visual_Studio/Tango.Core/ExtensionMethods/ProcessExtensions.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+public static class ProcessExtensions
+{
+ private static string FindIndexedProcessName(int pid)
+ {
+ var processName = Process.GetProcessById(pid).ProcessName;
+ var processesByName = Process.GetProcessesByName(processName);
+ string processIndexdName = null;
+
+ for (var index = 0; index < processesByName.Length; index++)
+ {
+ processIndexdName = index == 0 ? processName : processName + "#" + index;
+ var processId = new PerformanceCounter("Process", "ID Process", processIndexdName);
+ if ((int)processId.NextValue() == pid)
+ {
+ return processIndexdName;
+ }
+ }
+
+ return processIndexdName;
+ }
+
+ private static Process FindPidFromIndexedProcessName(string indexedProcessName)
+ {
+ var parentId = new PerformanceCounter("Process", "Creating Process ID", indexedProcessName);
+ return Process.GetProcessById((int)parentId.NextValue());
+ }
+
+ /// <summary>
+ /// Gets the executing process.
+ /// </summary>
+ /// <param name="process">The process.</param>
+ /// <returns></returns>
+ public static Process Parent(this Process process)
+ {
+ return FindPidFromIndexedProcessName(FindIndexedProcessName(process.Id));
+ }
+}