Exemplo n.º 1
0
        public async Task <IEnumerable <IPhysicalDrive> > GetPhysicalDrives()
        {
            if (!OperatingSystem.IsLinux())
            {
                throw new NotSupportedException("Linux physical drive manager is not running on Linux environment");
            }

            var lsBlkJson = await GetLsBlkJson();

            var lsBlk = LsBlkReader.ParseLsBlk(lsBlkJson);

            if (lsBlk.BlockDevices == null)
            {
                return(Enumerable.Empty <IPhysicalDrive>());
            }

            var diskBlockDevices =
                lsBlk.BlockDevices.Where(x =>
                                         !string.IsNullOrWhiteSpace(x.Type) &&
                                         x.Type.Equals("disk", StringComparison.OrdinalIgnoreCase) &&
                                         x.Removable).ToList();

            return(diskBlockDevices.Select(x =>
                                           new GenericPhysicalDrive(x.Path, x.Type, string.Concat(x.Vendor, " ", x.Model), x.Size ?? 0)));
        }
        public IPhysicalDriveManager Create()
        {
            if (OperatingSystem.IsWindows())
            {
                return(new WindowsPhysicalDriveManager(this.loggerFactory.CreateLogger <WindowsPhysicalDriveManager>()));
            }

            if (OperatingSystem.IsMacOs())
            {
                return(new MacOsPhysicalDriveManager(this.loggerFactory.CreateLogger <MacOsPhysicalDriveManager>()));
            }

            if (OperatingSystem.IsLinux())
            {
                return(new LinuxPhysicalDriveManager(this.loggerFactory.CreateLogger <LinuxPhysicalDriveManager>()));
            }

            throw new NotSupportedException("Unsupported operating system");
        }