private static void RegisterExpressSoftware(string info) { string[] componentInfo = info.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries); string hardwareComponentName = componentInfo[0]; bool isHardwareExists = TheSystem.Components.Exists(c => c.Name == hardwareComponentName); if (isHardwareExists) { var hardwareComponent = TheSystem.Components.First(c => c.Name == hardwareComponentName); string name = componentInfo[1]; int capacityConsumption = int.Parse(componentInfo[2]); int memoryConsumption = int.Parse(componentInfo[3]); var expressSoftware = new ExpressSoftware(name, capacityConsumption, memoryConsumption); bool hasEnoughCapacity = hardwareComponent.AvailableCapacity >= expressSoftware.CapacityConsumption; bool hasEnoughMemory = hardwareComponent.AvailableMemory >= expressSoftware.MemoryConsumption; if (hasEnoughCapacity && hasEnoughMemory) { hardwareComponent.AvailableCapacity -= expressSoftware.CapacityConsumption; hardwareComponent.AvailableMemory -= expressSoftware.MemoryConsumption; hardwareComponent.SoftwareComponents.Add(expressSoftware); } } }
private void RegisterExpressSoftware(string hardwareComponentName, string name, int capacityConsumation, int memoryConsumation) { ExpressSoftware expressSoftware = new ExpressSoftware(name, capacityConsumation, memoryConsumation); this.CustomSystem.AddSoftwareToHardware(hardwareComponentName, expressSoftware); }
public void RegisterExpressSoftware(List <Hardware.Hardware> theSystem, string command) { var zwischenspeicher = command.Split('('); var zwischenspeicher2 = zwischenspeicher[1].Substring(0, zwischenspeicher[1].Length - 1); var splitArray = zwischenspeicher2.Split(',').Select(s => s.Trim()).ToArray(); var name = splitArray[0]; var nameHardware = splitArray[1]; var capacity = Convert.ToInt32(splitArray[2]); var memory = Convert.ToInt32(splitArray[3]); if (theSystem.Any(h => h.Name == nameHardware)) { var hardware = theSystem.First(h => h.Name == nameHardware); if (hardware.MaximumCapacity - hardware.UsedCapacity >= capacity && hardware.MaximumMemory - hardware.UsedMemory >= memory) { var software = new ExpressSoftware(name, nameHardware, capacity, memory); hardware.ListOfInstalledSoftware.Add(software); hardware.UsedCapacity += software.CapacityConsumption; hardware.UsedMemory += software.MemoryConsumption; } } }
public void RegisterExpressSoftware(string hardwareComponentName, string name, int capacity, int memory) { var software = new ExpressSoftware(name, capacity, memory); if (Components.ContainsKey(hardwareComponentName)) { Components[hardwareComponentName].AddSoftware(software); } }
private static string CreateExpressSoftware(string[] dataSystem, out Software esSoft) { string elHName = dataSystem[0]; string esName = dataSystem[1]; int esCapacity = int.Parse(dataSystem[2]); int esMemory = int.Parse(dataSystem[3]); esSoft = new ExpressSoftware(esName, esCapacity, esMemory); return(elHName); }
public void RegisterExpressSoftware(string[] arr) { string hardwareComponentName = arr[1]; string name = arr[2]; int cap = int.Parse(arr[3]); int mem = int.Parse(arr[4]); Hardware CurrHardware = this.HardwereComponentsLis.FirstOrDefault(se => se.Name == hardwareComponentName); if (CurrHardware != null) { Software software = new ExpressSoftware(name, cap, mem); bool passed = CurrHardware.AddSoftwere(software); } }
private static void RegisterExpressSoftwareCommand( string[] inputArgs, List <Software> software, List <Hardware> hardware) { var hardwareComponentName = inputArgs[1]; var esName = inputArgs[2]; var esCapacityConsumption = int.Parse(inputArgs[3]); var esMemoryConsumption = int.Parse(inputArgs[4]); var expressSoftware = new ExpressSoftware(esName, esCapacityConsumption, esMemoryConsumption); var targetHardware = hardware.FirstOrDefault(h => h.Name == hardwareComponentName); if (targetHardware != null && targetHardware.CanRunSoftware(expressSoftware)) { targetHardware.RegisterSoftwareComponent(expressSoftware); software.Add(expressSoftware); } }
private static void CreateExpressSoftware(Match match, List <Hardware> components) { string[] tokens = match.Groups[2].Value.Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries); string hardwareName = tokens[0]; var hardware = components.FirstOrDefault(x => x.Name == hardwareName); if (hardware != null) { string name = tokens[1]; int capacity = int.Parse(tokens[2]); int memory = int.Parse(tokens[3]); var newComponent = new ExpressSoftware(hardware, name, capacity, memory); if (hardware.IsCapacityCapable(newComponent) && hardware.IsMemoryCapable(newComponent)) { hardware.SoftwareComponents.Add(newComponent); } } }
public IComponentSoftware CreateSoftware(string type, string name, int capacity, int memory) { IComponentSoftware componentSoftware = null; switch (type) { case "LightSoftware": return(componentSoftware = new LightSoftware(name, capacity, memory)); break; case "ExpressSoftware": return(componentSoftware = new ExpressSoftware(name, capacity, memory)); break; } return(componentSoftware); }
static void Main(string[] args) { string pattern = @"(\w+)(\((.*?)\))?"; string inputLine = Console.ReadLine(); Regex regex = new Regex(pattern); while (inputLine != "System Split") { Match matcher = regex.Match(inputLine); if (matcher.Groups[1].Value == "RegisterPowerHardware") { string hardwareType = "Power"; string[] hardwareData = matcher.Groups[3].Value.Split(','); string hardwareName = hardwareData[0].Trim(); int hardwareCapacity = int.Parse(hardwareData[1].Trim()); int hardwareMemory = int.Parse(hardwareData[2].Trim()); Hardware hardware = new PowerHardware(hardwareName, hardwareType, hardwareCapacity, hardwareMemory); MySystem.RegisterHardware(hardware); } else if (matcher.Groups[1].Value == "RegisterHeavyHardware") { string hardwareType = "Heavy"; string[] hardwareData = matcher.Groups[3].Value.Split(','); string hardwareName = hardwareData[0].Trim(); int hardwareCapacity = int.Parse(hardwareData[1].Trim()); int hardwareMemory = int.Parse(hardwareData[2].Trim()); Hardware hardware = new HeavyHardware(hardwareName, hardwareType, hardwareCapacity, hardwareMemory); MySystem.RegisterHardware(hardware); } else if (matcher.Groups[1].Value == "RegisterExpressSoftware") { string softwareType = "ExpressSoftware"; string[] softwareData = matcher.Groups[3].Value.Split(','); string hardwareComponentName = softwareData[0].Trim(); string softwareName = softwareData[1].Trim(); int softwareCapacityConsumption = int.Parse(softwareData[2].Trim()); int softwareMemoryconsumption = int.Parse(softwareData[3].Trim()); Software software = new ExpressSoftware(softwareName, softwareType, softwareCapacityConsumption, softwareMemoryconsumption); MySystem.RegisterSoftware(hardwareComponentName, software); } else if (matcher.Groups[1].Value == "RegisterLightSoftware") { string softwareType = "LightSoftware"; string[] softwareData = matcher.Groups[3].Value.Split(','); string hardwareComponentName = softwareData[0].Trim(); string softwareName = softwareData[1].Trim(); int softwareCapacityConsumption = int.Parse(softwareData[2].Trim()); int softwareMemoryconsumption = int.Parse(softwareData[3].Trim()); Software software = new LightSoftware(softwareName, softwareType, softwareCapacityConsumption, softwareMemoryconsumption); MySystem.RegisterSoftware(hardwareComponentName, software); } else if (matcher.Groups[1].Value == "ReleaseSoftwareComponent") { string[] dataForSoftwareRelease = matcher.Groups[3].Value.Split(','); string hardwareComponentName = dataForSoftwareRelease[0].Trim(); string softwareComponentName = dataForSoftwareRelease[1].Trim(); MySystem.ReleaseSoftowareComponent(hardwareComponentName, softwareComponentName); } else if (matcher.Groups[1].Value == "Analyze") { MySystem.Analyze(); } inputLine = Console.ReadLine(); } MySystem.SystemSplit(); }
protected SoftwareComponent CreateExpressSoftware(string[] data) { SoftwareComponent expressSoftwareComponent = new ExpressSoftware(data[1], int.Parse(data[2]), int.Parse(data[3]), data[0]); return(expressSoftwareComponent); }