Esempio n. 1
0
        // All of these async method will periodically execute instructions to the underlying database
        //  For that reasons, they all take some optional action parameters


        // populate a list of DiskDriveInfoEx with information about the actual drives connected to the computer
        // pass in an Action that will populate a storage location with the information
        public async Task PopulateDiskInfoExs(IEnumerable <int?> diskNumbers, CrudType cRUD, Action <IEnumerable <DiskDriveInfoEx> > storeDiskInfoExs, Action <DiskDriveInfoEx> storePartitionInfoExs)
        {
            Log.Debug($"starting PopulateDiskInfoExs: cRUD = {cRUD.ToString()}, diskNumbers = {diskNumbers.Dump()}");
            var diskInfoExs = new List <DiskDriveInfoEx>();

            foreach (var d in diskNumbers)
            {
                var diskInfoEx = new DiskDriveInfoEx();
                // ToDo: get from current ComputerInventory
                diskInfoEx.DriveNumber    = d;
                diskInfoEx.DiskDriveMaker = DiskDriveMaker.Generic;                      // ToDo: read disk diskDriveMaker via WMI
                diskInfoEx.DiskDriveType  = DiskDriveType.Generic;                       // ToDo: read disk diskDriveType via WMI
                diskInfoEx.SerialNumber   = "DummyDiskSerialNumber";                     // ToDo: read disk serial number via WMI
                await PopulatePartitionInfoExs(cRUD, diskInfoEx, storePartitionInfoExs); // wait for the

                diskInfoExs.Add(diskInfoEx);
            }

            // Store the information using the Action delegate
            storeDiskInfoExs.Invoke(diskInfoExs);
            // Todo: see if the DiskDriveMaker and SerialNumber already exist in the DB
            // async (cRUD, diskInfoEx) => { await Task.Yield(); }
            // Task< DiskDriveInfoEx> t = await DBFetch.Invoke(cRUD, diskInfoEx);
            // diskInfoEx = await DBFetch.Invoke(cRUD, diskInfoEx);
            Log.Debug($"leaving PopulateDiskInfoExs");
        }
Esempio n. 2
0
        // populate a list of PartitionInfoEx with information about the actual partitions on a DiskDrive
        // pass in an Action that will populate a storage location with the information
        public async Task PopulatePartitionInfoExs(CrudType cRUD, DiskDriveInfoEx diskInfoEx, Action <DiskDriveInfoEx> storePartitionInfoExs)
        {
            Log.Debug($"starting PopulatePartitionInfoExs: cRUD = {cRUD.ToString()}, diskInfoEx = {diskInfoEx.Dump()}");

            // ToDo: Get the list of partitions from the Disk hardware
            await new Task(() => Thread.Sleep(500));
            // Until real partitions are available, mock up the current laptop configuration as of 4/15/19
            // No partitions on drives 0 and 1, and one partition on drive 2, one drive letter E
            var partitionInfoExs = new List <PartitionInfoEx>();

            switch (diskInfoEx.DriveNumber)
            {
            case 2: {
                var partitionInfoEx = new PartitionInfoEx()
                {
                    PartitionDbId = new Id <PartitionInfoEx>(),
                    DriveLetters  = new List <string>()
                    {
                        "E"
                    }
                };
                partitionInfoExs.Add(partitionInfoEx);
                break;
            }

            default:
                break;
            }
            storePartitionInfoExs.Invoke(diskInfoEx);
            // ToDo: see if the disk already has partitions in the DB
            var dBPartitions = new List <PartitionInfoEx>();

            Log.Debug($"leaving PopulatePartitionInfoExs");
        }
Esempio n. 3
0
        // Extension methods to populate a ComputerHardware object
        public static ATAP.Utilities.ComputerInventory.ComputerHardware FromComputerName(this ATAP.Utilities.ComputerInventory.ComputerHardware me, string computerName)
        {
            ATAP.Utilities.ComputerInventory.ComputerHardware lCH;
            switch (computerName.Trim().ToLowerInvariant())
            {
            //ToDo: read actual HW, currently specific for laptop
            case "localhost":
                // create the partitions COD for drive 2
                //Log.Debug("in ComputerHardware.FromComputerName initializer");
                var             partitionInfoExs = new PartitionInfoExs();
                PartitionInfoEx PIE1             = new PartitionInfoEx()
                {
                    DriveLetters = new List <string>()
                    {
                        "E"
                    }, Exceptions = new List <Exception>(), PartitionDbId = new Id <PartitionInfoEx>(Guid.Empty), PartitionId = new Id <PartitionInfoEx>(Guid.NewGuid()), Size = 1000000000000
                };
                partitionInfoExs.PartitionInfoExCOD.Add(PIE1.PartitionId, PIE1);
                DiskDriveInfoEx DDIE0 = new DiskDriveInfoEx()
                {
                    DiskDriveId      = new Id <DiskDriveInfoEx>(Guid.NewGuid()),
                    DiskDriveDbId    = new Id <DiskDriveInfoEx>(Guid.Empty),
                    DiskDriveMaker   = DiskDriveMaker.Generic,
                    DiskDriveType    = DiskDriveType.SSD,
                    SerialNumber     = "123",
                    PartitionInfoExs = partitionInfoExs,
                    Exceptions       = new List <Exception>()
                };
                var diskDriveInfoExs = new DiskDriveInfoExs();
                diskDriveInfoExs.DiskDriveInfoExCOD.Add(DDIE0.DiskDriveId, DDIE0);
                lCH = new ComputerHardware(new MainBoard(MainBoardMaker.Generic, CPUSocket.Generic), new List <CPUMaker> {
                    CPUMaker.Intel
                }, diskDriveInfoExs.DiskDriveInfoExCOD, new TimeBlock(DateTime.UtcNow, true));
                break;

            default:
                throw new NotImplementedException($"cannot populate ComputerHardware object from computerName = {computerName}");
            }

            return(lCH);
        }