Exemple #1
0
 public void Disconnect()
 {
     using (IVirtualSystemManagementService managmentService = VirtualSystemManagementService.GetVirtualSystemManagmentService(this._Host))
     {
         using (IVirtualSystemSettingData systemSettingData = this._Vm.GetVirtualSystemSettingData())
         {
             using (IEthernetPortAllocationSettingData allocationSettingData = EthernetPortAllocationSettingData.GetRelated(systemSettingData).Where <IEthernetPortAllocationSettingData>((Func <IEthernetPortAllocationSettingData, bool>)(e => e.Parent == ((IWMICommon)this._AdapterSettingData).Object.Path.Path)).FirstOrDefault <IEthernetPortAllocationSettingData>())
             {
                 if (allocationSettingData == null)
                 {
                     NIC.tracer.TraceInformation("Did not find connection to remove.");
                 }
                 else
                 {
                     using (IResourceAllocationSettingData fromObject = ResourceAllocationSettingData.CreateFromObject(((IWMICommon)allocationSettingData).Object))
                     {
                         NIC.tracer.TraceInformation("Found connection to remove.");
                         managmentService.RemoveResourceSettings(new IResourceAllocationSettingData[1]
                         {
                             fromObject
                         });
                     }
                 }
             }
         }
     }
 }
        public static IResourceAllocationSettingData GetDefaultSyntheticDVDDrive(IComputerSystem host)
        {
            IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Synthetic DVD Drive' and Primordial = True").FirstOrDefault <IResourcePool>();

            Invariant.ArgumentNotNull((object)resource, "Synthetic DVD Drive not found");
            using (resource)
                return(ResourceAllocationSettingData.GetDefaultFromResourcePool(resource));
        }
        public static IResourceAllocationSettingData GetDefaultEmulatedIDEController(IComputerSystem host)
        {
            IResourcePool resource = ResourcePool.Query(host, "ResourceSubType = 'Microsoft:Hyper-V:Emulated IDE Controller' and Primordial = True").FirstOrDefault <IResourcePool>();

            Invariant.ArgumentNotNull((object)resource, "Emulated IDE Controller");
            using (resource)
                return(ResourceAllocationSettingData.GetDefaultFromResourcePool(resource));
        }
Exemple #4
0
        public IEnumerable <IResourceAllocationSettingData> AddResourceSettings(IVirtualSystemSettingData affectedConfiguration, string[] resourceSettings)
        {
            ManagementBaseObject inParams = this._Instance.GetMethodParameters(nameof(AddResourceSettings));

            try
            {
                inParams["AffectedConfiguration"] = (object)affectedConfiguration.Object.Path.Path;
                inParams["ResourceSettings"]      = (object)resourceSettings;
                ManagementBaseObject result = this._Instance.InvokeAndWait(nameof(AddResourceSettings), inParams);
                try
                {
                    if (result["ResultingResourceSettings"] != null)
                    {
                        string[] strArray = (string[])result["ResultingResourceSettings"];
                        for (int index = 0; index < strArray.Length; ++index)
                        {
                            yield return(ResourceAllocationSettingData.CreateFromPath(strArray[index], this.Scope));
                        }
                        strArray = (string[])null;
                    }
                    else if (result["Job"] != null)
                    {
                        foreach (ManagementObject o in ((ManagementObject)result["Job"]).GetRelated((string)null, "Msvm_AffectedJobElement", (string)null, (string)null, (string)null, (string)null, false, (EnumerationOptions)null))
                        {
                            yield return(ResourceAllocationSettingData.CreateFromObject(o));
                        }
                    }
                }
                finally
                {
                    if (result != null)
                    {
                        result.Dispose();
                    }
                }
                result = (ManagementBaseObject)null;
            }
            finally
            {
                if (inParams != null)
                {
                    inParams.Dispose();
                }
            }
            inParams = (ManagementBaseObject)null;
        }