public static void Destroy(List <HardwareComponent> dump, string command) { if (dump.Any(h => h.Name == command)) { HardwareComponent hardware = dump.Where(h => h.Name == command).First(); dump.Remove(hardware); } }
public static void Restore(List <HardwareComponent> computer, List <HardwareComponent> dump, string command) { if (dump.Any(h => h.Name == command)) { HardwareComponent hardware = dump.Where(h => h.Name == command).First(); dump.Remove(hardware); computer.Add(hardware); } }
public static void ReleaseSoftwareComponent(List <HardwareComponent> computer, string command) { string[] tokens = command.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); string hardwareName = tokens[0]; string softwareName = tokens[1]; if (computer.Any(h => h.Name == hardwareName)) { HardwareComponent hardware = computer.Where(h => h.Name == hardwareName).First(); if (hardware.SeeSoftware().Any(s => s.Name == softwareName)) { SoftwareComponent software = hardware.SeeSoftware().Where(s => s.Name == softwareName).First(); hardware.RemoveSoftwareComponent(software); hardware.UsedCapacity -= software.CapacityConsumption; hardware.UsedMemory -= software.MemoryConsumption; } } }
public static void RegisterLightSoftware(List <HardwareComponent> computer, string command) { string[] tokens = command.Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray(); string hardwareName = tokens[0]; string softwareName = tokens[1]; long capacity = long.Parse(tokens[2]); long memory = long.Parse(tokens[3]); if (computer.Any(h => h.Name == hardwareName)) { HardwareComponent hardware = computer.Where(h => h.Name == hardwareName).First(); if (hardware.MaximumCapacity - hardware.UsedCapacity >= capacity && hardware.MaximumMemory - hardware.UsedMemory >= memory) { SoftwareComponent software = new LightSoftwareComponent(softwareName, capacity, memory); hardware.AddSoftwareComponent(software); hardware.UsedCapacity += software.CapacityConsumption; hardware.UsedMemory += software.MemoryConsumption; } } }