Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 12899c8b

Přidáno uživatelem Jakub Šilhavý před asi 2 roky(ů)

re #9570 - Commented IProcessDetection.cs, IProcessUtils.cs, ProcessDetection.cs, and ProcessUtils.cs

Zobrazit rozdíly:

ld_client/LDClient/detection/ProcessUtils.cs
6 6
using System.Threading.Tasks;
7 7

  
8 8
namespace LDClient.detection {
9
    public class ProcessUtils : IProcessUtils{
9
    
10
    /// <summary>
11
    /// This class implements the IProcessUtils interface.
12
    /// It implements methods that are used when dealing with processes.
13
    /// </summary>
14
    public class ProcessUtils : IProcessUtils {
10 15

  
16
        /// <summary>
17
        /// Checks if a process is running or not.
18
        /// </summary>
19
        /// <param name="name">Name of the process</param>
20
        /// <returns>True, if the process is running. False otherwise.</returns>
11 21
        public bool IsProcessRunning(string name) {
12 22
            return Process.GetProcessesByName(name).Length > 0;
13 23
        }
14

  
15

  
24
        
25
        /// <summary>
26
        /// Executes a new process (t32rem.exe) with arguments which are passed in
27
        /// as a parameter of the method.
28
        /// </summary>
29
        /// <param name="fileName">Path to the .exe file</param>
30
        /// <param name="argument">Arguments passed into the .exe file</param>
31
        /// <param name="timeout">Timeout used when waiting for the process to terminate</param>
32
        /// <param name="desiredExitCode">Status code indicating a successful termination of the process.</param>
33
        /// <returns>True, if the command was executed successfully. False otherwise.</returns>
16 34
        public bool ExecuteNewProcess(string fileName, string argument, int timeout, int desiredExitCode) {
17

  
35
            // Create a new process.
18 36
            var t32RemProcess = new Process();
19 37
            t32RemProcess.StartInfo.FileName = fileName;
20 38
            t32RemProcess.StartInfo.Arguments = argument;
39
            
21 40
            try {
41
                // Execute the process and wait until it terminates or until the timeout is up.
22 42
                t32RemProcess.Start();
23 43
                if (!t32RemProcess.WaitForExit(timeout)) {
24 44
                    Program.DefaultLogger.Error($"Execution has not terminated within a predefined timeout of {timeout} ms");
25 45
                    return false;
26 46
                }
47
                
48
                // Check if the process terminated successfully.
27 49
                if (t32RemProcess.ExitCode != desiredExitCode) {
28 50
                    Program.DefaultLogger.Error($"Execution terminated with an error code of {t32RemProcess.ExitCode}");
29 51
                    return false;
......
32 54
                Program.DefaultLogger.Error($"Failed to run {fileName} {argument}. {exception.Message}");
33 55
                return false;
34 56
            }
35

  
36 57
            return true;
37 58
        }
38

  
39 59
    }
40 60
}

Také k dispozici: Unified diff