/// <summary> /// Retrieves the simulators listed in table Assets and if available what their reservations are. /// </summary> private void GetMasterList() { _masterList = new SimReservedList(); using (AssetInventoryContext aie = DbConnect.AssetInventoryContext()) { var matches = (from ds in aie.Assets.OfType <DeviceSimulator>() join ar in aie.AssetReservations on ds.AssetId equals ar.AssetId into mgtGroup from item in mgtGroup.DefaultIfEmpty() select new { ds.AssetId, ds.Product, ds.Address, ds.VirtualMachine, SessionId = item.SessionId == null ? "" : item.SessionId, ReservedFor = item.ReservedFor == null ? "" : item.ReservedFor }); foreach (var m in matches) { SimReserved ent = new SimReserved(); ent.AssetId = m.AssetId; ent.Product = m.Product; ent.HostAddress = m.Address; ent.VirtualMachine = m.VirtualMachine; ent.SessionId = m.SessionId; ent.ReservedFor = m.ReservedFor; _masterList.Add(ent); } } }
private void Revert(SimReserved simulator) { Thread.CurrentThread.SetName(simulator.AssetId); UpdateItemStatus(simulator, "Reverting..."); VMController.Revert(simulator.VirtualMachine); UpdateItemStatus(simulator, "Revert complete."); }
private void Launch(SimReserved simulator) { Thread.CurrentThread.SetName(simulator.AssetId); PowerOn(simulator); if (!JediSimulatorManager.IsSimulatorReady(simulator.HostAddress)) { UpdateItemStatus(simulator, "Launching Simulator..."); JediSimulatorManager.LaunchSimulator(simulator.VirtualMachine, simulator.Product, simulator.HostAddress); UpdateItemStatus(simulator, "Launch complete."); } else { UpdateItemStatus(simulator, "Simulator is already running."); } }
private void PowerOn(SimReserved simulator) { Thread.CurrentThread.SetName(simulator.AssetId); UpdateItemStatus(simulator, "Checking power status..."); if (VMController.IsPoweredOn(simulator.VirtualMachine)) { UpdateItemStatus(simulator, "Already powered on."); } else { UpdateItemStatus(simulator, "Powering On VM..."); VMController.PowerOnMachine(simulator.VirtualMachine); VMInventoryManager.SetInUse(simulator.VirtualMachine); CancellationTokenSource task = new CancellationTokenSource(); VMController.WaitOnMachineAvailable(simulator.VirtualMachine, task.Token); UpdateItemStatus(simulator, "Power On complete."); } }
private void PowerOff(SimReserved simulator) { Thread.CurrentThread.SetName(simulator.AssetId); UpdateItemStatus(simulator, "Checking power status..."); if (VMController.IsPoweredOn(simulator.VirtualMachine)) { if (JediSimulatorManager.IsSimulatorReady(simulator.HostAddress)) { UpdateItemStatus(simulator, "Shutting down simulator..."); JediSimulatorManager.ShutdownSimulator(simulator.VirtualMachine); UpdateItemStatus(simulator, "Simulator Shutdown complete."); } UpdateItemStatus(simulator, "Powering Off VM..."); VMController.Shutdown(simulator.VirtualMachine); UpdateItemStatus(simulator, "Power Off complete."); } else { UpdateItemStatus(simulator, "Already powered off."); } }
private void UpdateItemStatus(SimReserved item, string message) { item.Status = message; RefreshGrid(null, EventArgs.Empty); }