예제 #1
0
 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);
     }
 }
예제 #2
0
 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);
     }
 }
예제 #3
0
        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;
                }
            }
        }
예제 #4
0
        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;
                }
            }
        }