public static IVirtualHardDiskSettingData Parse(ManagementScope scope, string embedded)
        {
            IVirtualHardDiskSettingData hardDiskSettingData = VirtualHardDiskSettingData.CreateVirtualHardDiskSettingData(scope);
            XElement         xelement1        = XElement.Parse(embedded);
            ManagementObject managementObject = ((IWMICommon)hardDiskSettingData).Object;

            foreach (XElement xelement2 in xelement1.Elements((XName)"PROPERTY").Where <XElement>((Func <XElement, bool>)(e => e.Attribute((XName)"PROPAGATED") == null)))
            {
                managementObject[xelement2.Attribute((XName)"NAME").Value] = (object)xelement2.Value;
            }
            return(hardDiskSettingData);
        }
Esempio n. 2
0
 public void CreateVirtualDisk(string path, ulong size, string virtualDiskType, ushort format)
 {
     if (File.Exists(path))
     {
         this._Logger.Information(string.Format("Validating existing disk {0}...", (object)path));
         try
         {
             using (IVirtualDisk virtualDisk = this.ValidateVirtualDisk(path))
             {
                 if (virtualDisk != null)
                 {
                     if (virtualDisk.GetCfg().MaxInternalSize >= (long)size)
                     {
                         this._Logger.Information("Existing disk validated.");
                         return;
                     }
                 }
             }
         }
         catch (Exception ex)
         {
             if (this.HandleException(ex))
             {
                 throw;
             }
             else
             {
                 this._Logger.Warning(ex, "Existing disk validation failed");
             }
         }
         this._Logger.Information(string.Format("Deleting existing disk {0}...", (object)path));
         File.Delete(path);
     }
     if ((long)(size % 4096UL) != 0L)
     {
         size += 4096UL - size % 4096UL;
     }
     using (IImageManagementService managementService = ImageManagementService.GetImageManagementService(this._Host))
     {
         using (IVirtualHardDiskSettingData hardDiskSettingData = VirtualHardDiskSettingData.CreateVirtualHardDiskSettingData(this._Host))
         {
             hardDiskSettingData.Path            = path;
             hardDiskSettingData.MaxInternalSize = size;
             if (!(virtualDiskType == "Fixed"))
             {
                 if (!(virtualDiskType == "Dynamic"))
                 {
                     throw new HyperVException("Don't know how to create a disk of type " + virtualDiskType);
                 }
                 hardDiskSettingData.Type = (ushort)3;
             }
             else
             {
                 hardDiskSettingData.Type = (ushort)2;
             }
             hardDiskSettingData.Format             = format;
             hardDiskSettingData.PhysicalSectorSize = 512U;
             managementService.CreateVirtualHardDisk(hardDiskSettingData);
         }
     }
 }
 public static IVirtualHardDiskSettingData CreateVirtualHardDiskSettingData(IComputerSystem host)
 {
     return(VirtualHardDiskSettingData.CreateVirtualHardDiskSettingData(((IWMICommon)host).Scope));
 }