context: using Halsign.DWM.Framework;
  using System;
  using System.Collections.Generic;
  using System.Data;
  using System.Text;
  using System.Threading;
  namespace Halsign.DWM.Domain
  {
  	public class DwmVirtualMachine : DwmBase
  	{
  		internal const long ONE_GIGA_BYTE = 1073741824L;
  		private string _classification;
  		private string _poolUuid;
  		private string _poolName;
  		private OptimizationMode _poolOptMode;
  		private bool _isControlDomain;
  		private bool _active;
  		private bool _isAgile;
  		private bool _driversUpToDate;
  		private DwmHost _affinityHost;
  		private string _affinityHostUuid;
  		private int _affinityHostId;
  		private int _runningOnHostId;
  		private string _runningOnHostName;
  		private string _runningOnHostUuid;
  		private long _minimumStaticMemory;
  		private long _maximumStaticMemory;
  		private long _minimumDynamicMemory;
  		private long _maximumDynamicMemory;
  		private long _targetMemory;
  		private long _memoryOverhead;
  		private long _requiredMemory;
  		private int _minimumCpus;
  		private double _hvMemoryMultipler = 1.0;
  		private DwmStorageRepositoryCollection _requiredStorage;
  		private DwmVbdCollection _blockDevices;
  		private DwmVifCollection _networkInterfaces;
  		private DwmVmAverageMetric _metrics;
  		private static Dictionary<string, int> _uuidCache = new Dictionary<string, int>();
  		private static Dictionary<string, int> _nameCache = new Dictionary<string, int>();
  		private static object _uuidCacheLock = new object();
  		private static object _nameCacheLock = new object();
  		public string Classification
  		{
  			get
  			{
  				return this._classification;
  			}
  			set
  			{
  				this._classification = value;
  			}
  		}
  		public bool IsControlDomain
  		{
  			get
  			{
  				return this._isControlDomain;
  			}
  			set
  			{
  				this._isControlDomain = value;
  			}
  		}
  		public bool Active
  		{
  			get
  			{
  				return this._active;
  			}
  			set
  			{
  				this._active = value;
  			}
  		}
  		public DwmHost AffinityHost
  		{
  			get
  			{
  				return this._affinityHost;
  			}
  			set
  			{
  				this._affinityHost = value;
  				if (value != null)
  				{
  					this._affinityHostId = this._affinityHost.Id;
  					this._affinityHostUuid = this._affinityHost.Uuid;
  				}
  				else
  				{
  					this._affinityHostId = 0;
  					this._affinityHostUuid = null;
  				}
  			}
  		}
  		public int AffinityHostId
  		{
  			get
  			{
  				return this._affinityHostId;
  			}
  			set
  			{
  				this._affinityHostId = value;
  				if (this._affinityHost != null && this._affinityHost.Id != this._affinityHostId)
  				{
  					this._affinityHost = null;
  				}
  			}
  		}
  		public int RunningOnHostId
  		{
  			get
  			{
  				return this._runningOnHostId;
  			}
  			internal set
  			{
  				this._runningOnHostId = value;
  			}
  		}
  		public string RunningOnHostName
  		{
  			get
  			{
  				return this._runningOnHostName;
  			}
  			internal set
  			{
  				this._runningOnHostName = value;
  			}
  		}
  		public string RunningOnHostUuid
  		{
  			get
  			{
  				return this._runningOnHostUuid;
  			}
  			internal set
  			{
  				this._runningOnHostUuid = value;
  			}
  		}
  		public long MinimumStaticMemory
  		{
  			get
  			{
  				return this._minimumStaticMemory;
  			}
  			set
  			{
  				this._minimumStaticMemory = value;
  			}
  		}
  		public long MaximumStaticMemory
  		{
  			get
  			{
  				return this._maximumStaticMemory;
  			}
  			set
  			{
  				this._maximumStaticMemory = value;
  			}
  		}
  		public long MinimumDynamicMemory
  		{
  			get
  			{
  				return this._minimumDynamicMemory;
  			}
  			set
  			{
  				this._minimumDynamicMemory = value;
  			}
  		}
  		public long MaximumDynamicMemory
  		{
  			get
  			{
  				return this._maximumDynamicMemory;
  			}
  			set
  			{
  				this._maximumDynamicMemory = value;
  			}
  		}
  		public long TargetMemory
  		{
  			get
  			{
  				return this._targetMemory;
  			}
  			set
  			{
  				this._targetMemory = value;
  			}
  		}
  		public long MemoryOverhead
  		{
  			get
  			{
  				return this._memoryOverhead;
  			}
  			set
  			{
  				this._memoryOverhead = value;
  			}
  		}
  		public long RequiredMemory
  		{
  			get
  			{
  				return this._requiredMemory;
  			}
  			internal set
  			{
  				this._requiredMemory = value;
  			}
  		}
  		public int MinimumCpus
  		{
  			get
  			{
  				return this._minimumCpus;
  			}
  			set
  			{
  				this._minimumCpus = value;
  			}
  		}
  		public double HvMemoryMultiplier
  		{
  			get
  			{
  				if (this._hvMemoryMultipler <= 0.0)
  				{
  				}
  				return this._hvMemoryMultipler;
  			}
  			set
  			{
  				if (value <= 0.0)
  				{
  					throw new DwmException("HvMemoryMultiplier cannot be less than or equal to 0", DwmErrorCode.InvalidParameter, null);
  				}
  				this._hvMemoryMultipler = value;
  			}
  		}
  		public string PoolUuid
  		{
  			get
  			{
  				return this._poolUuid;
  			}
  			internal set
  			{
  				this._poolUuid = value;
  			}
  		}
  		public string PoolName
  		{
  			get
  			{
  				return this._poolName;
  			}
  			internal set
  			{
  				this._poolName = value;
  			}
  		}
  		public OptimizationMode PoolOptMode
  		{
  			get
  			{
  				return this._poolOptMode;
  			}
  			internal set
  			{
  				this._poolOptMode = value;
  			}
  		}
  		public DwmHost OptimalHost
  		{
  			get
  			{
  				if (base.Id > 0)
  				{
  					return DwmAEVirtualMachine.GetOptimalHost(base.Id, 0);
  				}
  				throw new DwmException("The VM must be saved before the optimal host can be determined", DwmErrorCode.InvalidOperation, null);
  			}
  		}
  		public bool IsAgile
  		{
  			get
  			{
  				return this._isAgile;
  			}
  			set
  			{
  				this._isAgile = value;
  			}
  		}
  		public bool DriversUpToDate
  		{
  			get
  			{
  				return this._driversUpToDate;
  			}
  			set
  			{
  				this._driversUpToDate = value;
  			}
  		}
  		public DwmStorageRepositoryCollection RequiredStorage
  		{
  			get
  			{
  				return DwmBase.SafeGetItem<DwmStorageRepositoryCollection>(ref this._requiredStorage);
  			}
  			internal set
  			{
  				this._requiredStorage = value;
  			}
  		}
  		public DwmVbdCollection BlockDevices
  		{
  			get
  			{
  				return DwmBase.SafeGetItem<DwmVbdCollection>(ref this._blockDevices);
  			}
  		}
  		public DwmVifCollection NetworkInterfaces
  		{
  			get
  			{
  				return DwmBase.SafeGetItem<DwmVifCollection>(ref this._networkInterfaces);
  			}
  		}
  		public DwmVmAverageMetric Metrics
  		{
  			get
  			{
  				return DwmBase.SafeGetItem<DwmVmAverageMetric>(ref this._metrics);
  			}
  			internal set
  			{
  				this._metrics = value;
  			}
  		}
  		public DwmVirtualMachine(string uuid, string name, int poolId) : base(uuid, name)
  		{
  			base.PoolId = poolId;
  			if (!string.IsNullOrEmpty(uuid))
  			{
  
gt: 				base.Id = DwmVirtualMachine.UuidToId(uuid, base.PoolId);