コード例 #1
0
        public virtual bool RemoveSoftware(string softwareName)
        {
            SoftwareComponent software = null;

            if (this.SoftwareComponentsByName.TryGetValue(softwareName, out software))
            {
                this.CurrentCapacity -= software.CapacityConsumation;
                this.CurrentMemory   -= software.MemoryConsumation;

                this.SoftwareComponentsByName.Remove(softwareName);

                if (software.Type == "Express")
                {
                    this.ExpressSoftwareCount--;
                }
                else
                {
                    this.LightSoftwareCount--;
                }

                return(true);
            }

            return(false);
        }
コード例 #2
0
        public override string ToString()
        {
            int           expressCount  = 0;
            int           lightCount    = 0;
            List <string> softwareNames = new List <string>();

            foreach (string key in this.softwareComponentsByName.Keys)
            {
                SoftwareComponent software = this.softwareComponentsByName[key];

                if (software.Type == "Express")
                {
                    expressCount++;
                }
                else
                {
                    lightCount++;
                }

                softwareNames.Add(software.Name);
            }

            string softwareComponents = softwareNames.Count > 0 ? string.Join(", ", softwareNames) : "None";

            StringBuilder builder = new StringBuilder();

            builder.AppendLine($"Hardware Component - {this.Name}");

            builder.AppendLine($"Express Software Components - {expressCount}");
            builder.AppendLine($"Light Software Components - {lightCount}");
            builder.AppendLine($"Memory Usage: {this.CurrentMemory} / {this.MaxMemory}");
            builder.AppendLine($"Capacity Usage: {this.CurrentCapacity} / {this.MaxCapacity}");
            builder.AppendLine($"Type: {this.Type}");
            builder.Append($"Software Components: {softwareComponents}");

            return(builder.ToString());
        }
コード例 #3
0
        public virtual bool AddSoftware(SoftwareComponent software)
        {
            if (this.MaxCapacity < (this.CurrentCapacity + software.CapacityConsumation) ||
                this.MaxMemory < (this.CurrentMemory + software.MemoryConsumation))
            {
                return(false);
            }

            this.CurrentCapacity += software.CapacityConsumation;
            this.CurrentMemory   += software.MemoryConsumation;

            this.SoftwareComponentsByName.Add(software.Name, software);

            if (software.Type == "Express")
            {
                this.ExpressSoftwareCount++;
            }
            else
            {
                this.LightSoftwareCount++;
            }

            return(true);
        }