Пример #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);
            }
        }
Пример #2
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);
            }
        }