public override void Shutdown(ShutdownOptions options)
        {
            if (!options.PowerOff)
            {
                TraceFactory.Logger.Debug("{0} Power Off option not set, returning...".FormatWith(_machine.Name));
                return;
            }

            if (!_machine.IsPoweredOn())
            {
                TraceFactory.Logger.Debug("{0} not powered on, returning...".FormatWith(_machine.Name));
                return;
            }

            Action shutdownAction = new Action(() =>
            {
                switch (options.PowerOffOption)
                {
                case VMPowerOffOption.PowerOff:
                    try
                    {
                        _machine.Shutdown(wait: true);
                    }
                    catch (SoapException ex)
                    {
                        TraceFactory.Logger.Warn("{0} Failed graceful shutdown.  Attempting power off: {1}".FormatWith(_machine.Name, ex.Message));
                        _machine.PowerOff();
                    }
                    break;

                case VMPowerOffOption.RevertToSnapshot:
                    _machine.Revert(wait: true);
                    break;

                default:
                    throw new NotSupportedException("Unsupported shutdown type: " + options.PowerOffOption);
                }
            });

            try
            {
                MachineStop.Run(_machine.Name, shutdownAction);
                TraceFactory.Logger.Debug("Shutdown completed for {0}".FormatWith(_machine.Name));
            }
            catch (Exception ex)
            {
                TraceFactory.Logger.Error("Error shutting down machine, continuing...", ex);
            }
        }
Пример #2
0
 private void CleanupAssetHostsHandler(DeviceSimulator simulatorMachine)
 {
     using (var machine = new ManagedMachine(simulatorMachine.VirtualMachine, ManagedMachineType.WindowsVirtual))
     {
         try
         {
             MachineStop.Run(machine.Name, () =>
             {
                 if (machine.IsPoweredOn())
                 {
                     machine.Shutdown(wait: true);
                 }
             });
         }
         catch (Exception ex)
         {
             TraceFactory.Logger.Error(ex.Message);
         }
     }
 }
Пример #3
0
        private void CleanupResourceHostsHandler(VirtualMachine machine)
        {
            using (var managedMachine = new ManagedMachine(machine.Name, EnumUtil.GetByDescription <ManagedMachineType>(machine.MachineType)))
            {
                TraceFactory.Logger.Debug("Resetting resource host {0}".FormatWith(managedMachine));

                try
                {
                    MachineStop.Run(managedMachine.Name, () =>
                    {
                        managedMachine.Revert(wait: true);
                        managedMachine.ReleaseReservation();
                    });
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Error(ex);
                }
            }
        }