Exemple #1
0
        public VirtualMachine GetVm(string emulatorName)
        {
            var wmiFactory = new XdeWmiFactory();
            var fullName   = emulatorName + "." + Environment.UserName.ToLowerInvariant();
            IXdeVirtualMachine vm;
            var cacheHit = this.cache.TryGetValue(fullName, out vm);

            if (!cacheHit || vm.EnabledState == VirtualMachineEnabledState.Unknown)
            {
                Logger.Info("Emulator '{0}' not found in cache. Requesting WMI.", fullName);
                vm = wmiFactory.GetVirtualMachine(fullName);
                this.cache[fullName] = vm;
            }
            else
            {
                Logger.Info("Emulator '{0}' found in cache. Using cached VM.", fullName);
            }

            if (vm == null)
            {
                throw new XdeVirtualMachineException(string.Format("Emulator '{0}' not found.", fullName));
            }

            if (vm.EnabledState != VirtualMachineEnabledState.Enabled)
            {
                throw new XdeVirtualMachineException(string.Format("Emulator '{0}' is not running.", fullName));
            }

            return(new VirtualMachine(vm));
        }
        public VirtualMachine GetVm(string emulatorName)
        {
            var wmiFactory = new XdeWmiFactory();
            var fullName = emulatorName + "." + Environment.UserName.ToLowerInvariant();
            IXdeVirtualMachine vm;
            var cacheHit = this.cache.TryGetValue(fullName, out vm);
            if (!cacheHit || vm.EnabledState == VirtualMachineEnabledState.Unknown)
            {
                Logger.Info("Emulator '{0}' not found in cache. Requesting WMI.", fullName);
                vm = wmiFactory.GetVirtualMachine(fullName);
                this.cache[fullName] = vm;
            }
            else
            {
                Logger.Info("Emulator '{0}' found in cache. Using cached VM.", fullName);
            }

            if (vm == null)
            {
                throw new XdeVirtualMachineException(string.Format("Emulator '{0}' not found.", fullName));
            }

            if (vm.EnabledState != VirtualMachineEnabledState.Enabled)
            {
                throw new XdeVirtualMachineException(string.Format("Emulator '{0}' is not running.", fullName));
            }

            return new VirtualMachine(vm);
        }
        private static IXdeVirtualMachine GetEmulatorVm(string emulatorName)
        {
            var factory = new XdeWmiFactory();
            var vm = factory.GetVirtualMachine(emulatorName + "." + Environment.UserName);
            if (vm.EnabledState != VirtualMachineEnabledState.Enabled)
            {
                throw new XdeVirtualMachineException("Emulator is not running. ");
            }

            return vm;
        }