public ProjectViewModel(Project project) : this() { ProjectId = project.ProjectId; ProjectName = project.ProjectName; foreach (var vm in project.VirtualMachines) { var vmView = new VirtualMachineViewModel(vm); if (vm.Status == VirtualMachine.PENDING) PendingVMs.Add(vmView); else if (vm.Status == VirtualMachine.ARCHIVED) ArchivedVMs.Add(vmView); else if (vm.IsPendingArchive) PendingArchiveVMs.Add(vmView); else RegisteredVMs.Add(vmView); } }
private void InitializeDataContext() { var registeredImages = RegisteredVirtualMachineService.GetRegisteredVMImagePaths(); foreach (var image in registeredImages) { int startIndex = image.IndexOf("] ") + "] ".Length; int length = image.IndexOf('/', startIndex) - startIndex; string projectName = image.Substring(startIndex, length); var service = new RegisteredVirtualMachineService(image); if (!dataDB.Projects.Select(p => p.ProjectName).Contains(projectName)) { var project = new Project(projectName); dataDB.Projects.Add(project); dataDB.SaveChanges(); } startIndex = image.LastIndexOf('/') + 1; length = image.LastIndexOf('.') - startIndex; string machineName = image.Substring(startIndex, length); VirtualMachine vm; try { vm = dataDB.VirtualMachines.Single(v => v.MachineName == machineName); } catch (Exception) { vm = new VirtualMachine(); dataDB.VirtualMachines.Add(vm); } //PowerOn(vm, service); vm.MachineName = machineName; vm.ImagePathName = image; vm.Status = service.GetStatus(); //TODO reset //vm.Hostname = "test-hostname"; vm.Hostname = service.GetHostname(); vm.IP = service.GetIP(); vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName); dataDB.SaveChanges(); } }
public void ReinitializeAllRegisteredVirtualMachines() { var imagePathNames = RegisteredVirtualMachineService.GetRegisteredVMImagePaths(); foreach (var image in imagePathNames) { int startIndex = image.IndexOf("] ") + "] ".Length; int length = image.IndexOf('/', startIndex) - startIndex; string projectName = image.Substring(startIndex, length); var service = new RegisteredVirtualMachineService(image); if (!dataDB.Projects.Select(p => p.ProjectName).Contains(projectName)) { var project = new Project(projectName); dataDB.Projects.Add(project); dataDB.SaveChanges(); } startIndex = image.LastIndexOf('/') + 1; length = image.LastIndexOf('.') - startIndex; string machineName = image.Substring(startIndex, length); if (!dataDB.VirtualMachines.Select(v => v.MachineName).Contains(machineName)) { VirtualMachine vm = new VirtualMachine(); vm.MachineName = machineName; vm.ImagePathName = image; vm.Status = service.GetStatus(); vm.Hostname = service.GetHostname(); vm.IP = service.GetIP(); vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName); dataDB.VirtualMachines.Add(vm); dataDB.SaveChanges(); } } }
public void CreateVirtualMachine(VirtualMachine vm, string projectName) { try { vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName); } catch (InvalidOperationException) { var project = new Project(projectName); dataDB.Projects.Add(project); vm.Project = project; } dataDB.VirtualMachines.Add(vm); dataDB.SaveChanges(); }
public void CreateProject(Project proj) { dataDB.Projects.Add(proj); }