Esempio n. 1
0
        public async Task <Result <IEnumerable <Computer> > > GetPhysicalComputersAsync()
        {
            try
            {
                var result = await Task.Run(() => _componentRepo.Get <Win32_ComputerSystem>());

                var output = result.Select(x => ComputerMapper.From(x)).ToList();

                return(Result <IEnumerable <Computer> > .Ok(output));
            }
            catch (Exception e)
            {
                return(Result <IEnumerable <Computer> > .Fail(e));
            }
        }
Esempio n. 2
0
        public async Task <Result <IEnumerable <GPU> > > GetPhysicalGPUsAsync()
        {
            try
            {
                var result = await Task.Run(() => _componentRepo.Get <Win32_VideoController>());

                var output = result.Select(x => GPUMapper.From(x));

                return(Result <IEnumerable <GPU> > .Ok(output));
            }
            catch (Exception e)
            {
                return(Result <IEnumerable <GPU> > .Fail(e));
            }
        }
Esempio n. 3
0
        public async Task <Result <IEnumerable <Storage> > > GetPhysicalStoragesAsync()
        {
            var output = new List <Storage>();

            var win32DiskDrives = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskDrive>());

            if (!win32DiskDrives.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(win32DiskDrives.Exception));
            }

            var win32DiskPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskPartition>());

            if (!win32DiskPartitions.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(win32DiskPartitions.Exception));
            }

            var win32DiskDriveToDiskPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_DiskDriveToDiskPartition>());

            if (!win32DiskDriveToDiskPartitions.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(win32DiskDriveToDiskPartitions.Exception));
            }

            var win32LogicalDiscsToPartitions = await GetPhysicalData(() => _componentRepo.Get <Win32_LogicalDiskToPartition>());

            if (!win32LogicalDiscsToPartitions.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(win32LogicalDiscsToPartitions.Exception));
            }

            var win32LogicalDiscs = await GetPhysicalData(() => _componentRepo.Get <Win32_LogicalDisk>());

            if (!win32LogicalDiscs.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(win32LogicalDiscs.Exception));
            }

            var msftPhysicalDiscs = await GetPhysicalData(() => _componentRepo.Get <MSFT_PhysicalDisk>());

            if (!msftPhysicalDiscs.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(msftPhysicalDiscs.Exception));
            }

            var mappings = RelateObjects(win32DiskDriveToDiskPartitions.Output, win32LogicalDiscsToPartitions.Output);

            if (!mappings.IsSuccess)
            {
                return(Result <IEnumerable <Storage> > .Fail(mappings.Exception));
            }

            try
            {
                foreach (var mapGroup in mappings.Output.GroupBy(x => x.DiskDrive).ToList())
                {
                    var diskDrive        = win32DiskDrives.Output.First(x => x.DeviceID == mapGroup.Key);
                    var msftPhysicalDisk = msftPhysicalDiscs.Output.First(x => x.Model == diskDrive.Model);

                    var diskPartitions = new List <Partition>();

                    foreach (var mapping in mapGroup)
                    {
                        var diskPartition = win32DiskPartitions.Output.First(x => x.DeviceID == mapping.DiskPartition);
                        var logicalDisk   = win32LogicalDiscs.Output.FirstOrDefault(x => x.DeviceID == mapping.LogicalDisk);

                        diskPartitions.Add(PartitionMapper.From(diskPartition, logicalDisk));
                    }

                    output.Add(StorageMapper.From(diskDrive, msftPhysicalDisk, diskPartitions));
                }

                return(Result <IEnumerable <Storage> > .Ok(output));
            }
            catch (Exception e)
            {
                return(Result <IEnumerable <Storage> > .Fail(e));
            }
        }