Пример #1
0
        public void AddHardware(HardwareComponent hardware)
        {
            this.MaxCapacity += hardware.MaxCapacity;
            this.MaxMemory   += hardware.MaxMemory;

            this.hardwareByName.Add(hardware.Name, hardware);
        }
Пример #2
0
        private void RegisterHardware(string[] inputLine)
        {
            HardwareComponent newPowerComponent =
                this.hardwareFactory.CreateHardwareComponentComponent(inputLine);

            this.systemRepository.AddToRepository(newPowerComponent);
        }
        public async Task <IActionResult> Edit(int id, [Bind("ID,Name,Description,DateAdded,DateModified")] HardwareComponent hardwareComponent)
        {
            if (id != hardwareComponent.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hardwareComponent);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HardwareComponentExists(hardwareComponent.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(hardwareComponent));
        }
Пример #4
0
        /// <summary>
        /// This method adds a hardware component to the database
        /// </summary>
        /// <param name="component">The component to be added</param>
        /// <returns></returns>
        public async Task AddComponent(HardwareComponent component)
        {
            var command = dbConnection.CreateCommand();

            command.CommandText =
                $@"INSERT INTO components(
                ComponentAmount,
                ComponentDrawer,
                ComponentName,
                ComponentNotes,
                ComponentOrderWarningMinimum,
                ComponentRack,
                ComponentUID
            )
            VALUES(
                {component.componentAmount},
                {component.componentDrawer},
                '{component.componentName}',
                '{component.componentNotes}',
                {component.componentOrderWarning},
                {component.componentRack},
                '{component.componentUid}'
            )";

            await command.ExecuteNonQueryAsync();
        }
Пример #5
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);
     }
 }
Пример #6
0
        public void AddToRepository(HardwareComponent component)
        {
            if (component == null)
            {
                return;
            }

            this.hardwareComponents.Add(component);
        }
Пример #7
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);
     }
 }
        public async Task StandardSqliteStorageModel_UpdateComponent_UpdatesCorrectComponent()
        {
            HardwareComponent component = new HardwareComponent("#2", 10, 50, 6, "dudeldu", "super cool", 42);

            await model.UpdateHardwareComponent(component);

            var getResultComponent = await model.GetHardwareComponent("#2");

            Assert.AreEqual(component.componentName, getResultComponent.componentName);
        }
        public async Task InMemoryDataBase_Update_UpdatesCorrectComponent()
        {
            InMemoryDatabaseSubstitute substitute = CreateSubstitute();
            HardwareComponent          component  = new HardwareComponent("#2", 50, 10, 200, "Core i9-9900K", "An overpriced processor", 1);

            await substitute.UpdateHardwareComponent(component);

            var getResultComponent = await substitute.GetHardwareComponent("#2");

            Assert.AreEqual(component.componentName, getResultComponent.componentName);
        }
        private void Dump(string[] inputArgs)
        {
            HardwareComponent componentToDump = this.SystemRepository.RemoveFromRepository(inputArgs[1]);

            if (componentToDump == null)
            {
                return;
            }

            this.dumpRepository.AddToRepository(componentToDump);
        }
        public async Task <IActionResult> Create([Bind("ID,Name,Description,DateAdded,DateModified")] HardwareComponent hardwareComponent)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hardwareComponent);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(hardwareComponent));
        }
Пример #12
0
        public HardwareComponent RemoveFromRepository(string componentName)
        {
            HardwareComponent component = this.hardwareComponents.FirstOrDefault(x => x.Name == componentName);

            if (component == null)
            {
                return(null);
            }

            this.hardwareComponents.Remove(component);
            return(component);
        }
Пример #13
0
        public void AttachSoftwareToHardware(SoftwareComponent softwareComponent)
        {
            HardwareComponent componentToAttachTo =
                this.HardwareComponents.FirstOrDefault(x => x.Name == softwareComponent.HardwareName);

            if (componentToAttachTo == null)
            {
                return;
            }

            componentToAttachTo.AddComponent(softwareComponent);
        }
Пример #14
0
    private static void DumpHardware(List <HardwareComponent> hardware, List <HardwareComponent> dumpedHardware, List <string> input)
    {
        string hardwareToRemoveName = input[1];

        if (hardware.Any(h => h.Name == hardwareToRemoveName))
        {
            HardwareComponent hardwareToRemove = hardware.First(h => h.Name == hardwareToRemoveName);

            hardware.Remove(hardware.First(h => h.Name == hardwareToRemoveName));

            dumpedHardware.Add(hardwareToRemove);
        }
    }
Пример #15
0
    private static void ReleaseSoftwareFromHardware(string[] commands, List <HardwareComponent> hardwareComponents, List <SoftwareComponent> softwareComponents)
    {
        string            desiredHardwareName  = commands[1];
        string            softwareToRemoveName = commands[2];
        HardwareComponent desiredComponent     = hardwareComponents.FirstOrDefault(x => x.Name == desiredHardwareName);
        SoftwareComponent unwantedSoftware     = softwareComponents.FirstOrDefault(x => x.Name == softwareToRemoveName);

        if (desiredComponent.Softwares.Any(x => x.Name == softwareToRemoveName))
        {
            desiredComponent.Softwares.Remove(unwantedSoftware);
        }
        desiredComponent.ReleaseSoftware(unwantedSoftware);
    }
Пример #16
0
        public void AddSoftwareToHardware(string hardwareName, SoftwareComponent software)
        {
            HardwareComponent hardware = null;

            if (this.hardwareByName.TryGetValue(hardwareName, out hardware))
            {
                if (hardware.AddSoftware(software))
                {
                    this.CapacityInUse += software.CapacityConsumation;
                    this.MemoryInUse   += software.MemoryConsumation;

                    this.AddedSoftware++;
                }
            }
        }
Пример #17
0
        /// <summary>
        /// This method returns only the requested hardware component.
        /// It fetches the components based on its uid.
        /// </summary>
        /// <param name="uid">The uid of the component</param>
        /// <returns>The requested HardwareComponent</returns>
        public async Task <HardwareComponent> GetHardwareComponent(string uid)
        {
            var command = dbConnection.CreateCommand();

            command.CommandText =
                $@"SELECT * FROM components WHERE ComponentUID='{uid}'";

            var reader = await command.ExecuteReaderAsync();

            await reader.ReadAsync();

            var component = new HardwareComponent(reader.GetString(6), reader.GetInt32(3), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(0), reader.GetString(4), reader.GetInt32(5));

            return(component);
        }
        public async Task <Dictionary <string, HardwareComponent> > GetHardwareComponents()
        {
            var command = inMemDataBase.CreateCommand();

            command.CommandText = @"SELECT * FROM components";
            var reader = command.ExecuteReader();

            Dictionary <string, HardwareComponent> queryResult = new Dictionary <string, HardwareComponent>();

            while (reader.Read())
            {
                HardwareComponent component = new HardwareComponent(reader.GetString(6), reader.GetInt32(3), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(0), reader.GetString(4), reader.GetInt32(5));
                queryResult.Add(component.componentUid, component);
            }

            return(queryResult);
        }
Пример #19
0
        /// <summary>
        /// This method updates a specified component
        /// </summary>
        /// <param name="component">The new component information</param>
        /// <returns></returns>
        public async Task UpdateHardwareComponent(HardwareComponent component)
        {
            var command = dbConnection.CreateCommand();

            command.CommandText =
                $@"UPDATE components
               SET ComponentName = '{component.componentName}',
                   ComponentRack = {component.componentRack},
                   ComponentDrawer = {component.componentDrawer},
                   ComponentAmount = {component.componentAmount},
                   ComponentNotes = '{component.componentNotes}',
                   ComponentOrderWarningMinimum = {component.componentOrderWarning}
               WHERE ComponentUID = '{component.componentUid}';
            ";

            await command.ExecuteNonQueryAsync();
        }
Пример #20
0
        public void RemoveSoftwareFromHardware(string hardwareName, string softwareName)
        {
            HardwareComponent hardware = null;

            if (this.hardwareByName.TryGetValue(hardwareName, out hardware))
            {
                int capacityBeforeRemoving = hardware.CurrentCapacity;
                int memoryBeforeRemoving   = hardware.CurrentMemory;

                if (hardware.RemoveSoftware(softwareName))
                {
                    this.CapacityInUse -= (capacityBeforeRemoving - hardware.CurrentCapacity);
                    this.MemoryInUse   -= (memoryBeforeRemoving - hardware.CurrentMemory);

                    this.AddedSoftware--;
                }
            }
        }
Пример #21
0
        public void Dump(string hardwareComponentName)
        {
            HardwareComponent hardware = null;

            if (this.hardwareByName.TryGetValue(hardwareComponentName, out hardware))
            {
                this.hardwareByName.Remove(hardwareComponentName);
                this.dumpedHardwareByName.Add(hardware.Name, hardware);

                this.MaxCapacity -= hardware.MaxCapacity;
                this.MaxMemory   -= hardware.MaxMemory;

                this.MemoryInUse   -= hardware.CurrentMemory;
                this.CapacityInUse -= hardware.CurrentCapacity;

                this.AddedSoftware -= hardware.GetSoftwareCount;
            }
        }
Пример #22
0
        public void ReleaseSoftwareComponent(string hardwareComponentName, string softwareComponentName)
        {
            HardwareComponent hardwareComponent =
                this.HardwareComponents.FirstOrDefault(x => x.Name == hardwareComponentName);

            if (hardwareComponent == null)
            {
                return;
            }

            SoftwareComponent softwareComponent = hardwareComponent.GetSoftwareComponent(softwareComponentName);

            if (softwareComponent == null)
            {
                return;
            }

            hardwareComponent.RemoveComponent(softwareComponent);
        }
Пример #23
0
        public virtual HardwareComponent CreateHardwareComponentComponent(string[] inputArgs)
        {
            HardwareComponent newComponent = null;

            string[] componentData = inputArgs[1].Split(new[] { ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);

            switch (inputArgs[0])
            {
            case "RegisterPowerHardware":
                newComponent = this.CreatePowerHardware(componentData);
                break;

            case "RegisterHeavyHardware":
                newComponent = this.CreateHeavyHardware(componentData);
                break;
            }

            return(newComponent);
        }
Пример #24
0
        /// <summary>
        /// This method returns a dictionary of type string, HardwareComponent.
        /// It reads all available components and returns them.
        /// </summary>
        /// <returns>Dictionary<string, HardwareComponent></returns>
        public async Task <Dictionary <string, HardwareComponent> > GetHardwareComponents()
        {
            var command = dbConnection.CreateCommand();

            command.CommandText =
                $@"SELECT * FROM components";

            var reader = await command.ExecuteReaderAsync();

            Dictionary <string, HardwareComponent> components = new Dictionary <string, HardwareComponent>();

            while (await reader.ReadAsync())
            {
                HardwareComponent component = new HardwareComponent(reader.GetString(6), reader.GetInt32(3), reader.GetInt32(1), reader.GetInt32(2), reader.GetString(0), reader.GetString(4), reader.GetInt32(5));
                components.Add(component.componentUid, component);
            }

            return(components);
        }
Пример #25
0
        public void HardwareComponent_ConstructorArgumentsPassedIn_SavedCorrectly()
        {
            string name = "LM324";
            string uid  = "#001";
            int    orderWarningLimit = 10;
            int    quantity          = 3;
            int    rack   = 50;
            int    drawer = 2;
            string notes  = "Great component! 10/10";

            HardwareComponent component = new HardwareComponent(componentName: name, componentNotes: notes, componentAmount: quantity, componentDrawer: drawer, componentOrderWarning: orderWarningLimit, componentRack: rack, componentUid: uid);

            Assert.AreEqual(component.componentUid, uid);
            Assert.AreEqual(component.componentRack, rack);
            Assert.AreEqual(component.componentOrderWarning, orderWarningLimit);
            Assert.AreEqual(component.componentNotes, notes);
            Assert.AreEqual(component.componentName, name);
            Assert.AreEqual(component.componentDrawer, drawer);
            Assert.AreEqual(component.componentAmount, quantity);
        }
Пример #26
0
 public bool AddComponent(HardwareComponent component)
 {
     try
     {
         if (String.IsNullOrEmpty(component.RoomUID))
         {
             var room = Company.Buildings[0]?.Rooms[0];
             if (room != null)
             {
                 component.RoomUID = room.UID;
                 room.Components.Add(component);
             }
         }
         return(true);
     }
     catch (Exception e)
     {
         Console.WriteLine(e.ToString());
         return(false);
     }
 }
Пример #27
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;
            }
        }
    }
Пример #28
0
        public string DumpAnalyze()
        {
            int countPowerComponents = 0;
            int countHeavyComponents = 0;
            int countExpressSoftware = 0;
            int countLightSoftware   = 0;
            int dumpMemory           = 0;
            int dumpCapacity         = 0;

            foreach (string hardwareName in this.dumpedHardwareByName.Keys)
            {
                HardwareComponent component = this.dumpedHardwareByName[hardwareName];

                if (component.Type == "Power")
                {
                    countPowerComponents++;
                }
                else
                {
                    countHeavyComponents++;
                }

                countExpressSoftware += component.ExpressSoftwareCount;
                countLightSoftware   += component.LightSoftwareCount;
                dumpMemory           += component.CurrentMemory;
                dumpCapacity         += component.CurrentCapacity;
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("Dump Analysis");
            builder.AppendLine($"Power Hardware Components: {countPowerComponents}");
            builder.AppendLine($"Heavy Hardware Components: {countHeavyComponents}");
            builder.AppendLine($"Express Software Components: {countExpressSoftware}");
            builder.AppendLine($"Light Software Components: {countLightSoftware}");
            builder.AppendLine($"Total Dumped Memory: {dumpMemory}");
            builder.Append($"Total Dumped Capacity: {dumpCapacity}");

            return(builder.ToString());
        }
Пример #29
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;
            }
        }
    }
Пример #30
0
        public static HardwareComponent CreateComponentFromTypeString(string typeString)
        {
            HardwareComponent component = null;

            switch (typeString)
            {
            case "Router":
                component = new Router();
                break;

            case "Switch":
                component = new Switch();
                break;

            case "AccessPoint":
                component = new AccessPoint();
                break;

            case "DesktopPc":
                component = new DesktopPc();
                break;

            case "Notebook":
                component = new Notebook();
                break;

            case "Server":
                component = new Server();
                break;

            case "Drucker":
                component = new Drucker();
                break;
            }

            return(component);
        }