Exemplo n.º 1
0
        private static (double, double) GetLinxMemoryInGB()
        {
            try
            {
                var results    = OSUtils.StartProcessWithResults("cat", "/proc/meminfo");
                var resultsArr = results.Split("\n".ToCharArray());
                var freeKB     = resultsArr
                                 .FirstOrDefault(x => x.Trim().StartsWith("MemAvailable"))
                                 .Trim()
                                 .Split(" ".ToCharArray(), 2)
                                 .Last() // 9168236 kB
                                 .Trim()
                                 .Split(' ')
                                 .First(); // 9168236

                var totalKB = resultsArr
                              .FirstOrDefault(x => x.Trim().StartsWith("MemTotal"))
                              .Trim()
                              .Split(" ".ToCharArray(), 2)
                              .Last() // 16637468 kB
                              .Trim()
                              .Split(' ')
                              .First(); // 16637468

                var freeGB  = Math.Round(double.Parse(freeKB) / 1024 / 1024, 2);
                var totalGB = Math.Round(double.Parse(totalKB) / 1024 / 1024, 2);

                return(totalGB - freeGB, totalGB);
            }
            catch
            {
                return(0, 0);
            }
        }
Exemplo n.º 2
0
        public static string GetCurrentUser()
        {
            try
            {
                if (OSUtils.IsWindows)
                {
                    return(Win32Interop.GetActiveSessions().LastOrDefault()?.Username);
                }

                if (OSUtils.IsLinux)
                {
                    var users = OSUtils.StartProcessWithResults("users", "");
                    return(users?.Split()?.FirstOrDefault()?.Trim());
                }

                throw new Exception("Unsupported operating system.");
            }
            catch
            {
                return("Error Retrieving");
            }
        }