DiskImageCreator.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. namespace DiskAccessLibrary
  3. {
  4. public static class DiskImageCreator
  5. {
  6. public static DiskImage CreateImage(DiskImageFormat format, DiskImageType type, string imagePath, long imageSize, string snapshotPath, int blockSize)
  7. {
  8. switch (format)
  9. {
  10. case DiskImageFormat.BlockDifferencingDiskImage:
  11. switch (type)
  12. {
  13. case DiskImageType.Differencing:
  14. return BlockDifferencingDiskImage.Create(imagePath, snapshotPath, blockSize);
  15. case DiskImageType.Dynamic:
  16. return BlockDifferencingDiskImage.Create(snapshotPath, imageSize, blockSize);
  17. default:
  18. throw new ArgumentOutOfRangeException(nameof(type), type, null);
  19. }
  20. case DiskImageFormat.RawDiskImage:
  21. if (type != DiskImageType.Fixed) throw new NotSupportedException();
  22. return RawDiskImage.Create(imagePath, imageSize);
  23. case DiskImageFormat.VirtualHardDisk:
  24. switch (type)
  25. {
  26. case DiskImageType.Differencing:
  27. throw new NotSupportedException();
  28. case DiskImageType.Dynamic:
  29. return VirtualHardDisk.CreateDynamicDisk(imagePath, imageSize);
  30. case DiskImageType.Fixed:
  31. return VirtualHardDisk.CreateFixedDisk(imagePath, imageSize);
  32. default:
  33. throw new ArgumentOutOfRangeException(nameof(type), type, null);
  34. }
  35. default:
  36. throw new ArgumentOutOfRangeException(nameof(format), format, null);
  37. }
  38. }
  39. }
  40. }