Ejemplo n.º 1
0
        public static Tuple <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(new Tuple <double, double>(freeGB, totalGB));
            }
            catch
            {
                return(new Tuple <double, double>(0, 0));
            }
        }
Ejemplo n.º 2
0
        public static async Task <Device> Create(string deviceID, string orgID)
        {
            OSPlatform platform = OSUtils.GetPlatform();

            var systemDrive = DriveInfo.GetDrives().FirstOrDefault(x =>
                                                                   x.IsReady &&
                                                                   x.RootDirectory.FullName.Contains(Path.GetPathRoot(Environment.SystemDirectory ?? Environment.CurrentDirectory)));

            var device = new Device()
            {
                ID             = deviceID,
                DeviceName     = Environment.MachineName,
                Platform       = platform.ToString(),
                ProcessorCount = Environment.ProcessorCount,
                OSArchitecture = RuntimeInformation.OSArchitecture,
                OSDescription  = RuntimeInformation.OSDescription,
                Is64Bit        = Environment.Is64BitOperatingSystem,
                IsOnline       = true,
                Drives         = DriveInfo.GetDrives().Where(x => x.IsReady).Select(x => new Drive()
                {
                    DriveFormat   = x.DriveFormat,
                    DriveType     = x.DriveType,
                    Name          = x.Name,
                    RootDirectory = x.RootDirectory.FullName,
                    FreeSpace     = x.TotalSize > 0 ? x.TotalFreeSpace / x.TotalSize : 0,
                    TotalSize     = x.TotalSize > 0 ? Math.Round((double)(x.TotalSize / 1024 / 1024 / 1024), 2) : 0,
                    VolumeLabel   = x.VolumeLabel
                }).ToList(),
                OrganizationID = orgID,
                CurrentUser    = DeviceInformation.GetCurrentUser()
            };

            if (systemDrive != null && systemDrive.TotalSize > 0 && systemDrive.TotalFreeSpace > 0)
            {
                device.TotalStorage = Math.Round((double)(systemDrive.TotalSize / 1024 / 1024 / 1024), 2);
                device.UsedStorage  = Math.Round((double)((systemDrive.TotalSize - systemDrive.TotalFreeSpace) / 1024 / 1024 / 1024), 2);
            }


            var(usedMemory, totalMemory) = GetMemoryInGB();
            device.UsedMemory            = usedMemory;
            device.TotalMemory           = totalMemory;

            device.CpuUtilization = await GetCpuUtilization();

            if (File.Exists("Remotely_Agent.dll"))
            {
                device.AgentVersion = FileVersionInfo.GetVersionInfo("Remotely_Agent.dll")?.FileVersion?.ToString()?.Trim();
            }

            return(device);
        }
Ejemplo n.º 3
0
 public static string GetCurrentUser()
 {
     try
     {
         if (OSUtils.IsWindows)
         {
             return(Win32Interop.GetActiveSessions().LastOrDefault()?.Username);
         }
         else if (OSUtils.IsLinux)
         {
             var users = OSUtils.StartProcessWithResults("users", "");
             return(users?.Split()?.FirstOrDefault()?.Trim());
         }
         throw new Exception("Unsupported operating system.");
     }
     catch
     {
         return("Error Retrieving");
     }
 }
Ejemplo n.º 4
0
 public static string GetCurrentUser()
 {
     try
     {
         if (OSUtils.IsWindows)
         {
             var session        = CimSession.Create(null);
             var computerSystem = session.EnumerateInstances("root\\cimv2", "CIM_ComputerSystem");
             var username       = computerSystem.FirstOrDefault().CimInstanceProperties["UserName"].Value ?? "";
             return(username as string);
         }
         else if (OSUtils.IsLinux)
         {
             var users    = OSUtils.StartProcessWithResults("users", "");
             var username = users?.Split()?.FirstOrDefault()?.Trim();
             return($"{Environment.UserDomainName}\\{username}");
         }
         throw new Exception("Unsupported operating system.");
     }
     catch
     {
         return("Error Retrieving");
     }
 }