Ejemplo n.º 1
0
        internal static bool TryReadEnvironFile(int pid, out IDictionary <string, string> environ, Func <KeyValuePair <string, string>, bool> predicate,
                                                SpecificDelimiterTextReader delimiterTextReader)
        {
            try
            {
                using (var source = new FileStream(GetEnvironFilePathForProcess(pid), FileMode.Open, FileAccess.Read,
                                                   FileShare.Read,
                                                   1, false))
                {
                    var query = delimiterTextReader.ReadLines(source)
                                .Select(_ => ToKeyValue(_, '='));
                    if (predicate != null)
                    {
                        query = query.Where(predicate);
                    }
                    environ = query.ToDictionary(_ => _.Key, _ => _.Value);

                    return(true);
                }
            }
            catch (Exception e)
            {
                environ = new Dictionary <string, string>();
                Debug.WriteLine(e);
                return(false);
            }
        }
        public IDictionary <string, string> GetEnvironmentVariables(int pid, Func <KeyValuePair <string, string>, bool> predicate)
        {
            var specificDelimiterReader = new SpecificDelimiterTextReader();

            ProcFs.TryReadEnvironFile(pid, out var environmentVariables, predicate, specificDelimiterReader);
            return(environmentVariables);
        }
        public List <string> GetCmdLine(int pid)
        {
            var specificDelimiterReader = new SpecificDelimiterTextReader();

            ProcFs.TryReadCommandLine(pid, out var cmdLine, specificDelimiterReader);
            return(cmdLine);
        }
Ejemplo n.º 4
0
        internal static bool TryReadCommandLine(int pid, out List <string> cmdLine,
                                                SpecificDelimiterTextReader delimiterTextReader)
        {
            try
            {
                using (var source = new FileStream(GetCmdLineFilePathForProcess(pid), FileMode.Open, FileAccess.Read,
                                                   FileShare.Read,
                                                   1, false))
                {
                    cmdLine = delimiterTextReader.ReadLines(source).ToList();
                }

                return(true);
            }
            catch (Exception e)
            {
                cmdLine = default(List <string>);
                Debug.WriteLine(e);
                return(false);
            }
        }