예제 #1
0
        private void RegisterComponent(string component)
        {
            int    startIndexOfComponentArguments = component.IndexOf('(');
            string typeComponent = component.Substring(0, startIndexOfComponentArguments);

            string[] componentArguments = SplitByMultipleChars(
                component.Substring(startIndexOfComponentArguments));

            if (typeComponent.Contains("Hardware"))
            {
                IComponentHardware newHardware = hardwareFactory.CreateHardware(
                    typeComponent, componentArguments[0],
                    int.Parse(componentArguments[1]),
                    int.Parse(componentArguments[2]));

                this.newMachine.AddHardwareItem(newHardware);
            }
            else
            {
                IComponentSoftware newSoftware = softwareFactory.CreateSoftware(typeComponent,
                                                                                componentArguments[1],
                                                                                int.Parse(componentArguments[2]),
                                                                                int.Parse(componentArguments[3]));

                this.newMachine.AddSoftwareItem(componentArguments[0], newSoftware);
            }
        }
예제 #2
0
        private int GetCountOfSpecificSoftwareComponets(IComponentHardware hardware,
                                                        string nameOfSoftware)
        {
            int countSoftware = hardware.SoftwareComponets
                                .Where(x => x.GetType().Name.Contains(nameOfSoftware))
                                .Count();

            return(countSoftware);
        }
예제 #3
0
        public IComponentHardware CreateHardware(string type,
                                                 string name, int capacity, int memory)
        {
            IComponentHardware componentHardware = null;

            switch (type)
            {
            case "PowerHardware":
                return(componentHardware = new PowerHardware(name, capacity, memory, type));

                break;

            case "HeavyHardware":
                return(componentHardware = new HeavyHardware(name, capacity, memory, type));

                break;
            }

            return(componentHardware);
        }
예제 #4
0
 public void AddHardwareItem(IComponentHardware item)
 {
     this.hardwareComponents.Add(item);
 }
예제 #5
0
        public int GetCapacityUsed(IComponentHardware currentHardware)
        {
            int capacity = currentHardware.SoftwareComponets.Sum(x => x.CapacityConsumption);

            return(capacity);
        }
예제 #6
0
        public int GetMemoryUsed(IComponentHardware currentHardware)
        {
            int memory = currentHardware.SoftwareComponets.Sum(x => x.MemoryConsumption);

            return(memory);
        }