Example #1
0
        public static void RegisterExpressSoftware(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 ExpressSoftwareComponent(softwareName, capacity, memory);
                    hardware.AddSoftwareComponent(software);
                    hardware.UsedCapacity += software.CapacityConsumption;
                    hardware.UsedMemory   += software.MemoryConsumption;
                }
            }
        }
Example #2
0
        public static void RegisterExpressSoftware(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 ExpressSoftwareComponent(softwareName, capacity, memory);
                    hardware.AddSoftwareComponent(software);
                    hardware.UsedCapacity += software.CapacityConsumption;
                    hardware.UsedMemory += software.MemoryConsumption;
                }
            }
        }