123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using Utilities;
- namespace DiskAccessLibrary
- {
- public class PhysicalDiskHelper
- {
- public static List<PhysicalDisk> GetPhysicalDisks()
- {
- List<PhysicalDisk> result = new List<PhysicalDisk>();
- List<int> diskIndexList = PhysicalDiskUtils.GetPhysicalDiskIndexList();
- foreach (int diskIndex in diskIndexList)
- {
- PhysicalDisk disk;
- try
- {
- disk = new PhysicalDisk(diskIndex);
- }
- catch (DriveNotFoundException)
- {
-
- continue;
- }
- catch (DeviceNotReadyException)
- {
- continue;
- }
- catch (SharingViolationException)
- {
- continue;
- }
- result.Add(disk);
- }
- return result;
- }
- public static bool LockAllOrNone(List<PhysicalDisk> disks)
- {
- bool success = true;
- int lockIndex;
- for(lockIndex = 0; lockIndex < disks.Count; lockIndex++)
- {
- success = disks[lockIndex].ExclusiveLock();
- if (!success)
- {
- break;
- }
- }
-
- if (!success)
- {
- for (int index = 0; index < lockIndex; index++)
- {
- disks[index].ReleaseLock();
- }
- }
- return success;
- }
-
-
-
- public static bool OfflineAllOrNone(List<PhysicalDisk> disks)
- {
- bool success = true;
- int offlineIndex;
- for (offlineIndex = 0; offlineIndex < disks.Count; offlineIndex++)
- {
- success = disks[offlineIndex].SetOnlineStatus(false, false);
- if (!success)
- {
- break;
- }
- }
-
- if (!success)
- {
- for (int index = 0; index < offlineIndex; index++)
- {
- disks[index].SetOnlineStatus(true, false);
- }
- }
- return success;
- }
- }
- }
|