// 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"); }
// 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"); }
// C/R/U/D a list of DiskDriveInfoEx with data in a DB // pass in an Action that will interact with the DB public async Task DiskInfoExsToDB(List <DiskDriveInfoEx> diskInfoExs, CrudType cRUD, Func <CrudType, DiskDriveInfoEx, Task> interact) { Log.Debug($"starting DiskInfoExsToDB: cRUD = {cRUD.ToString()}, diskInfoExs = {diskInfoExs.Dump()}"); foreach (var diskInfoEx in diskInfoExs) { // invoke the Action delegate to C/R/U/D each DiskDriveInfoEx to the DB await interact.Invoke(cRUD, diskInfoEx); } Log.Debug($"leaving DiskInfoExsToDB"); }