Permalink
Browse files

Added error handling for missing info in VMs

  • Loading branch information...
1 parent f8b1d50 commit ae8bf795b2d13b76c0b2ddfcaabf2ff44863fd69 Calvin Mlynarczyk committed Mar 26, 2012
Showing with 10 additions and 7 deletions.
  1. +0 −1 VMAT/Models/VirtualMachine.cs
  2. +10 −6 VMAT/Models/VirtualMachineRepository.cs
@@ -28,7 +28,6 @@ public abstract class VirtualMachine
public string BaseImageName { get; set; }
[DisplayName("Operating System")]
- [RegularExpression("[a-zA-Z0-9 ]")]
public string OS { get; set; }
[DisplayName("Hostname")]
@@ -44,13 +44,19 @@ private void InitializeDataContext()
string machineName = image.Substring(startIndex, length);
bool vmExists = true;
- RegisteredVirtualMachine vm = dataDB.VirtualMachines.Single(
- v => v.MachineName == machineName) as RegisteredVirtualMachine;
- if (vm == null)
+ RegisteredVirtualMachine vm;
+
+ try
+ {
+ vm = dataDB.VirtualMachines.Single(v => v.MachineName == machineName)
+ as RegisteredVirtualMachine;
+ }
+ catch (Exception)
{
vmExists = false;
vm = new RegisteredVirtualMachine();
+ dataDB.VirtualMachines.Add(vm);
}
vm.MachineName = machineName;
@@ -60,9 +66,7 @@ private void InitializeDataContext()
vm.Hostname = service.GetHostname();
vm.IP = service.GetIP();
vm.Project = dataDB.Projects.Single(p => p.ProjectName == projectName);
-
- if (!vmExists)
- dataDB.VirtualMachines.Add(vm);
+
dataDB.SaveChanges();
}

0 comments on commit ae8bf79

Please sign in to comment.