From 95de473054c700712bdc6c311582d311c0d91ab4 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 28 Apr 2018 17:27:35 +0100 Subject: [PATCH] Update DB to version 18: Machines can have an arbitrary number of memories, so use an interconnection table, `memory_by_machine`. --- Cicm.Database/Operations/Init.cs | 58 +++---- Cicm.Database/Operations/Machine.cs | 90 +++++------ Cicm.Database/Operations/MemoryByMachine.cs | 168 ++++++++++++++++++++ Cicm.Database/Operations/Operations.cs | 2 +- Cicm.Database/Operations/Update.cs | 124 +++++++++++++++ Cicm.Database/Schemas/Enums.cs | 107 +++++++++++++ Cicm.Database/Schemas/Machine.cs | 6 - Cicm.Database/Schemas/MemoryByMachine.cs | 47 ++++++ Cicm.Database/Schemas/Sql/V18.cs | 135 ++++++++++++++++ cicm_web/Models/Machine.cs | 10 +- cicm_web/Models/MemoryByMachine.cs | 64 ++++++++ cicm_web/Views/Machine/View.cshtml | 123 +++++--------- cicm_web/cicm_web.csproj | 2 +- 13 files changed, 753 insertions(+), 183 deletions(-) create mode 100644 Cicm.Database/Operations/MemoryByMachine.cs create mode 100644 Cicm.Database/Schemas/MemoryByMachine.cs create mode 100644 Cicm.Database/Schemas/Sql/V18.cs create mode 100644 cicm_web/Models/MemoryByMachine.cs diff --git a/Cicm.Database/Operations/Init.cs b/Cicm.Database/Operations/Init.cs index d3d73552..3cdb91d8 100644 --- a/Cicm.Database/Operations/Init.cs +++ b/Cicm.Database/Operations/Init.cs @@ -49,111 +49,115 @@ namespace Cicm.Database IDbCommand dbCmd = dbCon.CreateCommand(); Console.WriteLine("Creating table `admins`"); - dbCmd.CommandText = V17.Admins; + dbCmd.CommandText = V18.Admins; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `browser_tests`"); - dbCmd.CommandText = V17.BrowserTests; + dbCmd.CommandText = V18.BrowserTests; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `cicm_db`"); - dbCmd.CommandText = V17.CicmDb; + dbCmd.CommandText = V18.CicmDb; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `companies`"); - dbCmd.CommandText = V17.Companies; + dbCmd.CommandText = V18.Companies; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `machines`"); - dbCmd.CommandText = V17.Machines; + dbCmd.CommandText = V18.Machines; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `disk_formats`"); - dbCmd.CommandText = V17.DiskFormats; + dbCmd.CommandText = V18.DiskFormats; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `forbidden`"); - dbCmd.CommandText = V17.Forbidden; + dbCmd.CommandText = V18.Forbidden; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus`"); - dbCmd.CommandText = V17.Gpus; + dbCmd.CommandText = V18.Gpus; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `log`"); - dbCmd.CommandText = V17.Logs; + dbCmd.CommandText = V18.Logs; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `money_donations`"); - dbCmd.CommandText = V17.MoneyDonations; + dbCmd.CommandText = V18.MoneyDonations; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `news`"); - dbCmd.CommandText = V17.News; + dbCmd.CommandText = V18.News; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_computers`"); - dbCmd.CommandText = V17.OwnedComputers; + dbCmd.CommandText = V18.OwnedComputers; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `owned_consoles`"); - dbCmd.CommandText = V17.OwnedConsoles; + dbCmd.CommandText = V18.OwnedConsoles; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_sets`"); - dbCmd.CommandText = V17.InstructionSets; + dbCmd.CommandText = V18.InstructionSets; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions`"); - dbCmd.CommandText = V17.InstructionSetExtensions; + dbCmd.CommandText = V18.InstructionSetExtensions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors`"); - dbCmd.CommandText = V17.Processors; + dbCmd.CommandText = V18.Processors; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `instruction_set_extensions_by_processor`"); - dbCmd.CommandText = V17.InstructionSetExtensionsByProcessor; + dbCmd.CommandText = V18.InstructionSetExtensionsByProcessor; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_synths`"); - dbCmd.CommandText = V17.SoundSynths; + dbCmd.CommandText = V18.SoundSynths; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `iso3166_1_numeric`"); - dbCmd.CommandText = V17.Iso3166Numeric; + dbCmd.CommandText = V18.Iso3166Numeric; dbCmd.ExecuteNonQuery(); Console.WriteLine("Filling table `iso3166_1_numeric`"); - dbCmd.CommandText = V17.Iso3166NumericValues; + dbCmd.CommandText = V18.Iso3166NumericValues; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `companies`"); - dbCmd.CommandText = V17.CompaniesForeignKeys; + dbCmd.CommandText = V18.CompaniesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating foreign keys for table `machines`"); - dbCmd.CommandText = V17.MachinesForeignKeys; + dbCmd.CommandText = V18.MachinesForeignKeys; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_logos`"); - dbCmd.CommandText = V17.CompanyLogos; + dbCmd.CommandText = V18.CompanyLogos; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `company_descriptions`"); - dbCmd.CommandText = V17.CompanyDescriptions; + dbCmd.CommandText = V18.CompanyDescriptions; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `processors_by_machine`"); - dbCmd.CommandText = V17.ProcessorsByMachine; + dbCmd.CommandText = V18.ProcessorsByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `gpus_by_machine`"); - dbCmd.CommandText = V17.GpusByMachine; + dbCmd.CommandText = V18.GpusByMachine; dbCmd.ExecuteNonQuery(); Console.WriteLine("Creating table `sound_by_machine`"); - dbCmd.CommandText = V17.SoundByMachine; + dbCmd.CommandText = V18.SoundByMachine; + dbCmd.ExecuteNonQuery(); + + Console.WriteLine("Creating table `memory_by_machine`"); + dbCmd.CommandText = V18.MemoryByMachine; dbCmd.ExecuteNonQuery(); return true; diff --git a/Cicm.Database/Operations/Machine.cs b/Cicm.Database/Operations/Machine.cs index fce34edd..e1b75a68 100644 --- a/Cicm.Database/Operations/Machine.cs +++ b/Cicm.Database/Operations/Machine.cs @@ -214,9 +214,9 @@ namespace Cicm.Database dbcmd.Transaction = trans; const string SQL = - "INSERT INTO machines (company, year, model, ram, rom, vram, colors, res, hdd1, hdd2, hdd3, disk1, " + - "cap1, disk2, cap2, type) VALUES (@company, @year, @model, @ram, @rom, @vram, @colors, @res, @hdd1, " + - "@hdd2, @hdd3, @disk1, @cap1, @disk2, @cap2, @type)"; + "INSERT INTO machines (company, year, model, colors, res, hdd1, hdd2, hdd3, disk1, cap1, disk2, cap2, " + + "type) VALUES (@company, @year, @model, @colors, @res, @hdd1, @hdd2, @hdd3, @disk1, @cap1, @disk2, " + + "@cap2, @type)"; dbcmd.CommandText = SQL; @@ -249,9 +249,9 @@ namespace Cicm.Database dbcmd.Transaction = trans; string sql = - "UPDATE machines SET company = @company, year = @year, model = @model, ram = @ram, rom = @rom, " + - "vram = @vram, colors = @colors, res = @res, hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, " + - "cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, type = @type " + + "UPDATE machines SET company = @company, year = @year, model = @model, colors = @colors, res = @res, " + + "hdd1 = @hdd1, hdd2 = @hdd2, hdd3 = @hdd3, disk1 = @disk1, cap1 = @cap1, disk2 = @disk2, cap2 = @cap2, " + + "type = @type " + $"WHERE id = {entry.Id}"; dbcmd.CommandText = sql; @@ -299,67 +299,55 @@ namespace Cicm.Database IDbDataParameter param4 = dbcmd.CreateParameter(); IDbDataParameter param5 = dbcmd.CreateParameter(); IDbDataParameter param6 = dbcmd.CreateParameter(); - IDbDataParameter param7 = dbcmd.CreateParameter(); - IDbDataParameter param8 = dbcmd.CreateParameter(); - IDbDataParameter param9 = dbcmd.CreateParameter(); + IDbDataParameter param7 = dbcmd.CreateParameter(); + IDbDataParameter param8 = dbcmd.CreateParameter(); + IDbDataParameter param9 = dbcmd.CreateParameter(); IDbDataParameter param10 = dbcmd.CreateParameter(); IDbDataParameter param11 = dbcmd.CreateParameter(); IDbDataParameter param12 = dbcmd.CreateParameter(); IDbDataParameter param13 = dbcmd.CreateParameter(); - IDbDataParameter param14 = dbcmd.CreateParameter(); - IDbDataParameter param15 = dbcmd.CreateParameter(); - IDbDataParameter param16 = dbcmd.CreateParameter(); param1.ParameterName = "@company"; param2.ParameterName = "@year"; param3.ParameterName = "@model"; - param4.ParameterName = "@ram"; - param5.ParameterName = "@rom"; - param6.ParameterName = "@vram"; - param7.ParameterName = "@colors"; - param8.ParameterName = "@res"; - param9.ParameterName = "@hdd1"; - param10.ParameterName = "@hdd2"; - param11.ParameterName = "@hdd3"; - param12.ParameterName = "@disk1"; - param13.ParameterName = "@cap1"; - param14.ParameterName = "@disk2"; - param15.ParameterName = "@cap2"; - param16.ParameterName = "@type"; + param4.ParameterName = "@colors"; + param5.ParameterName = "@res"; + param6.ParameterName = "@hdd1"; + param7.ParameterName = "@hdd2"; + param8.ParameterName = "@hdd3"; + param9.ParameterName = "@disk1"; + param10.ParameterName = "@cap1"; + param11.ParameterName = "@disk2"; + param12.ParameterName = "@cap2"; + param13.ParameterName = "@type"; param1.DbType = DbType.Int32; param2.DbType = DbType.Int32; param3.DbType = DbType.String; param4.DbType = DbType.Int32; - param5.DbType = DbType.Int32; + param5.DbType = DbType.String; param6.DbType = DbType.Int32; - param7.DbType = DbType.Int32; - param8.DbType = DbType.String; - param9.DbType = DbType.Int32; - param10.DbType = DbType.Int32; + param7.DbType = DbType.Int32; + param8.DbType = DbType.Int32; + param9.DbType = DbType.Int32; + param10.DbType = DbType.String; param11.DbType = DbType.Int32; - param12.DbType = DbType.Int32; - param13.DbType = DbType.String; - param14.DbType = DbType.Int32; - param15.DbType = DbType.String; - param16.DbType = DbType.Int32; + param12.DbType = DbType.String; + param13.DbType = DbType.Int32; param1.Value = entry.Company; param2.Value = entry.Year; param3.Value = entry.Model; - param4.Value = entry.Ram; - param5.Value = entry.Rom; - param6.Value = entry.Vram; - param7.Value = entry.Colors; - param8.Value = entry.Resolution; - param9.Value = entry.Hdd1; - param10.Value = entry.Hdd2; - param11.Value = entry.Hdd3; - param12.Value = entry.Disk1; - param13.Value = entry.Cap1; - param14.Value = entry.Disk2; - param15.Value = entry.Cap2; - param16.Value = entry.Type; + param4.Value = entry.Colors; + param5.Value = entry.Resolution; + param6.Value = entry.Hdd1; + param7.Value = entry.Hdd2; + param8.Value = entry.Hdd3; + param9.Value = entry.Disk1; + param10.Value = entry.Cap1; + param11.Value = entry.Disk2; + param12.Value = entry.Cap2; + param13.Value = entry.Type; dbcmd.Parameters.Add(param1); dbcmd.Parameters.Add(param2); @@ -374,9 +362,6 @@ namespace Cicm.Database dbcmd.Parameters.Add(param11); dbcmd.Parameters.Add(param12); dbcmd.Parameters.Add(param13); - dbcmd.Parameters.Add(param14); - dbcmd.Parameters.Add(param15); - dbcmd.Parameters.Add(param16); return dbcmd; } @@ -393,9 +378,6 @@ namespace Cicm.Database Company = (int)dataRow["company"], Year = (int)dataRow["year"], Model = (string)dataRow["model"], - Ram = (int)dataRow["ram"], - Rom = (int)dataRow["rom"], - Vram = (int)dataRow["vram"], Colors = (int)dataRow["colors"], Resolution = (string)dataRow["res"], Hdd1 = (int)dataRow["hdd1"], diff --git a/Cicm.Database/Operations/MemoryByMachine.cs b/Cicm.Database/Operations/MemoryByMachine.cs new file mode 100644 index 00000000..6a4db0d2 --- /dev/null +++ b/Cicm.Database/Operations/MemoryByMachine.cs @@ -0,0 +1,168 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : MemoryByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains operations to manage memory. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System; +using System.Collections.Generic; +using System.Data; +using Cicm.Database.Schemas; + +namespace Cicm.Database +{ + public partial class Operations + { + /// + /// Gets all memory in machine + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetMemoryByMachine(out List entries, int machineId) + { + #if DEBUG + Console.WriteLine("Getting all memory synths for machine {0}...", machineId); + #endif + + try + { + string sql = $"SELECT * FROM memory_by_machine WHERE machine = {machineId}"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = MemoryByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting memory by machine."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + /// + /// Gets all machines with specified gpu + /// + /// All CPUs + /// true if is correct, false otherwise + public bool GetMachinesByMemory(out List entries, int gpuId) + { + #if DEBUG + Console.WriteLine("Getting all machines with memory synth {0}...", gpuId); + #endif + + try + { + string sql = $"SELECT * FROM memory_by_machine WHERE gpu = {gpuId}"; + + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = sql; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + entries = MemoryByMachinesFromDataTable(dataSet.Tables[0]); + + return true; + } + catch(Exception ex) + { + Console.WriteLine("Error getting machines by memory synth."); + Console.WriteLine(ex); + entries = null; + return false; + } + } + + IDbCommand GetCommandMemoryByMachine(MemoryByMachine entry) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + IDbDataParameter param4 = dbcmd.CreateParameter(); + IDbDataParameter param5 = dbcmd.CreateParameter(); + + param1.ParameterName = "@machine"; + param2.ParameterName = "@type"; + param3.ParameterName = "@usage"; + param4.ParameterName = "@size"; + param5.ParameterName = "@speed"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + param3.DbType = DbType.Int32; + param4.DbType = DbType.Int64; + param5.DbType = DbType.Double; + + param1.Value = entry.Machine; + param2.Value = entry.Type; + param3.Value = entry.Usage; + param4.Value = entry.Size == 0 ? (object)null : entry.Size; + param5.Value = entry.Speed <= 0 ? (object)null : entry.Speed; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + dbcmd.Parameters.Add(param4); + dbcmd.Parameters.Add(param5); + + return dbcmd; + } + + static List MemoryByMachinesFromDataTable(DataTable dataTable) + { + List entries = new List(); + + foreach(DataRow dataRow in dataTable.Rows) + { + MemoryByMachine entry = new MemoryByMachine + { + Machine = (int)dataRow["machine"], + Type = (MemoryType)dataRow["type"], + Usage = (MemoryUsage)dataRow["usage"], + Size = dataRow["size"] == DBNull.Value ? 0 : (long)dataRow["size"], + Speed = dataRow["speed"] == DBNull.Value ? 0 : (double)dataRow["speed"], + }; + + entries.Add(entry); + } + + return entries; + } + } +} \ No newline at end of file diff --git a/Cicm.Database/Operations/Operations.cs b/Cicm.Database/Operations/Operations.cs index 48535df7..cc2fc374 100644 --- a/Cicm.Database/Operations/Operations.cs +++ b/Cicm.Database/Operations/Operations.cs @@ -35,7 +35,7 @@ namespace Cicm.Database public partial class Operations { /// Last known database version - const int DB_VERSION = 17; + const int DB_VERSION = 18; /// The column with this value indicates there is no item of this type. public const int DB_NONE = -1; /// diff --git a/Cicm.Database/Operations/Update.cs b/Cicm.Database/Operations/Update.cs index a672665f..f672ae6d 100644 --- a/Cicm.Database/Operations/Update.cs +++ b/Cicm.Database/Operations/Update.cs @@ -154,6 +154,11 @@ namespace Cicm.Database UpdateDatabaseToV17(); break; } + case 17: + { + UpdateDatabaseToV18(); + break; + } } OptimizeDatabase(); @@ -1902,6 +1907,125 @@ namespace Cicm.Database dbCmd.Dispose(); } + void UpdateDatabaseToV18() + { + Console.WriteLine("Updating database to version 18"); + + Console.WriteLine("Creating table `memory_by_machine`"); + IDbCommand dbCmd = dbCon.CreateCommand(); + IDbTransaction trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = V18.MemoryByMachine; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Getting all items from `machines`"); + + dbCmd = dbCon.CreateCommand(); + IDbDataAdapter dataAdapter = dbCore.GetNewDataAdapter(); + dbCmd.CommandText = "SELECT * from machines"; + DataSet dataSet = new DataSet(); + dataAdapter.SelectCommand = dbCmd; + dataAdapter.Fill(dataSet); + + foreach(DataRow dataRow in dataSet.Tables[0].Rows) + { + IDbCommand dbcmd = dbCon.CreateCommand(); + + IDbDataParameter param1 = dbcmd.CreateParameter(); + IDbDataParameter param2 = dbcmd.CreateParameter(); + IDbDataParameter param3 = dbcmd.CreateParameter(); + + param1.ParameterName = "@machine"; + param2.ParameterName = "@usage"; + param3.ParameterName = "@size"; + + param1.DbType = DbType.Int32; + param2.DbType = DbType.Int32; + param3.DbType = DbType.Int64; + + param1.Value = (int)dataRow["id"]; + + const string SQL = + "INSERT INTO `memory_by_machine` (`machine`, `usage`, `size`) VALUES (@machine, @usage, @size)"; + + dbcmd.Parameters.Add(param1); + dbcmd.Parameters.Add(param2); + dbcmd.Parameters.Add(param3); + + if(dataRow["ram"] != DBNull.Value && (int)dataRow["ram"] > 0) + { + param2.Value = MemoryUsage.Work; + param3.Value = (int)dataRow["ram"] * 1024; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding {0} bytes of {1} memory to machine {2}", (int)param3.Value, + MemoryUsage.Work, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + if(dataRow["rom"] != DBNull.Value && (int)dataRow["rom"] > 0) + { + param2.Value = MemoryUsage.Firmware; + param3.Value = (int)dataRow["rom"] * 1024; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding {0} bytes of {1} memory to machine {2}", (int)param3.Value, + MemoryUsage.Firmware, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + if(dataRow["vram"] != DBNull.Value && (int)dataRow["vram"] > 0) + { + param2.Value = MemoryUsage.Video; + param3.Value = (int)dataRow["vram"] * 1024; + + trans = dbCon.BeginTransaction(); + dbcmd.Transaction = trans; + + Console.WriteLine("Adding {0} bytes of {1} memory to machine {2}", (int)param3.Value, + MemoryUsage.Video, (int)param1.Value); + + dbcmd.CommandText = SQL; + + dbcmd.ExecuteNonQuery(); + trans.Commit(); + } + + dbcmd.Dispose(); + } + + Console.WriteLine("Removing memory columns from table `machines`"); + dbCmd = dbCon.CreateCommand(); + trans = dbCon.BeginTransaction(); + dbCmd.Transaction = trans; + dbCmd.CommandText = "ALTER TABLE `machines` DROP COLUMN `ram`;\n" + + "ALTER TABLE `machines` DROP COLUMN `rom`;\n" + + "ALTER TABLE `machines` DROP COLUMN `vram`;"; + dbCmd.ExecuteNonQuery(); + trans.Commit(); + dbCmd.Dispose(); + + Console.WriteLine("Setting new database version to 18..."); + dbCmd = dbCon.CreateCommand(); + dbCmd.CommandText = "INSERT INTO cicm_db (version) VALUES ('18')"; + dbCmd.ExecuteNonQuery(); + dbCmd.Dispose(); + } + void OptimizeDatabase() { IDbCommand dbCmd = dbCon.CreateCommand(); diff --git a/Cicm.Database/Schemas/Enums.cs b/Cicm.Database/Schemas/Enums.cs index 27271871..64d0e738 100644 --- a/Cicm.Database/Schemas/Enums.cs +++ b/Cicm.Database/Schemas/Enums.cs @@ -77,4 +77,111 @@ namespace Cicm.Database.Schemas /// Videogame console Console = 2 } + + public enum MemoryType + { + /// Unknown memory type + Unknown = 0, + /// Dynamic RAM + DRAM = 1, + /// Fast page mode DRAM + FPM = 2, + /// Extended data out DRAM + EDO = 3, + /// Dual-ported video DRAM + VRAM = 4, + /// Synchronous DRAM + SDRAM = 5, + /// Double data rate SDRAM + DDR = 6, + /// Double data rate SDRAM v2 + DDR2 = 7, + /// Double data rate SDRAM v3 + DDR3 = 8, + /// Double data rate SDRAM v4 + DDR4 = 9, + /// Rambus DRAM + RDRAM = 10, + /// Synchronous graphics RAM + SGRAM = 11, + /// Pseudostatic RAM + PSRAM = 12, + /// Static RAM + SRAM = 13, + /// Read-only memory + ROM = 14, + /// Programmable ROM + PROM = 15, + /// Erasable programmable ROM + EPROM = 16, + /// Electronically-erasable programmable ROM + EEPROM = 17, + /// NAND flash + NAND = 18, + /// NOR flash + NOR = 19, + /// Resistive RAM + ReRAM = 20, + /// Conductive-bridging RAM + CBRAM = 21, + /// Domain-wall memory + DWM = 22, + /// Nano-RAM + NanoRAM = 23, + /// Millipede memory + Millipede = 24, + /// Floating Junction Gate RAM + FJG = 25, + /// Punched paper + PunchedPaper = 26, + /// Drum memory + DrumMemory = 27, + /// Magnetic-core + MagneticCore = 28, + /// Plated wire memory + PlatedWire = 29, + /// Core rope memory + CoreRope = 30, + /// Thin-film memory + ThinFilm = 31, + /// Twistor memory + Twistor = 32, + /// Bubble memory + Bubble = 33 + } + + public enum MemoryUsage + { + /// Unknown usage + Unknown = 0, + /// + /// Contains a boot loader (usually read-only) whose only function is to load the next memory (firmware or + /// cartridge) + /// + Bootloader = 1, + /// + /// Contains hardware initializing, some (or many) low level calls and code to load software from secondary + /// storage + /// + Firmware = 2, + /// Memory used by software running on the machine + Work = 3, + /// Memory used by the graphics processing units + Video = 4, + /// Memory used by the sound synthetizers + Sound = 5, + /// Memory used to store wave tables + Wavetable = 6, + /// Memory used as a buffer from secondary storage + StorageBuffer = 7, + /// Memory used to save arbitrary data and possible also configuration + Save = 8, + /// Memory used to save only configuration + Configuration = 9, + /// + /// Memory accessible directly to any of the processors in the machine, including graphics processors and sound + /// synthetizers + /// + Unified = 10 + } } \ No newline at end of file diff --git a/Cicm.Database/Schemas/Machine.cs b/Cicm.Database/Schemas/Machine.cs index 6f468f01..81d6ce3c 100644 --- a/Cicm.Database/Schemas/Machine.cs +++ b/Cicm.Database/Schemas/Machine.cs @@ -55,16 +55,10 @@ namespace Cicm.Database.Schemas public int Id; /// Model name public string Model; - /// Size in kibibytes of program RAM - public int Ram; /// Resolution in WxH pixels public string Resolution; - /// Size in kibibytes of firmware - public int Rom; /// Machine type public MachineType Type; - /// Size in kibibytes for video RAM - public int Vram; /// Introduction date, 0 if unknown, 1000 if prototype public int Year; } diff --git a/Cicm.Database/Schemas/MemoryByMachine.cs b/Cicm.Database/Schemas/MemoryByMachine.cs new file mode 100644 index 00000000..7c8efcb4 --- /dev/null +++ b/Cicm.Database/Schemas/MemoryByMachine.cs @@ -0,0 +1,47 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : MemoryByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// High level representation of a computer. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas +{ + /// Computer + public class MemoryByMachine + { + /// Machine ID + public int Machine; + /// Memory type + public MemoryType Type; + /// Memory usage + public MemoryUsage Usage; + /// Memory size in bytes + public long Size; + /// Memory speed in Hz + public double Speed; + } +} \ No newline at end of file diff --git a/Cicm.Database/Schemas/Sql/V18.cs b/Cicm.Database/Schemas/Sql/V18.cs new file mode 100644 index 00000000..541d3fa9 --- /dev/null +++ b/Cicm.Database/Schemas/Sql/V18.cs @@ -0,0 +1,135 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : V18.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Contains SQL queries to create the database version 7. +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +namespace Cicm.Database.Schemas.Sql +{ + public static class V18 + { + public static readonly string Admins = V17.Admins; + + public static readonly string BrowserTests = V17.BrowserTests; + + public static readonly string CicmDb = "CREATE TABLE `cicm_db` (\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,\n" + + "`version` int(11) NOT NULL,\n" + + "`updated` datetime DEFAULT CURRENT_TIMESTAMP,\n" + + "PRIMARY KEY (`id`));\n" + + "INSERT INTO cicm_db (version) VALUES ('18');"; + + public static readonly string Companies = V17.Companies; + + public static readonly string Machines = "CREATE TABLE `machines` (;\n" + + "`id` int(11) NOT NULL AUTO_INCREMENT,;\n" + + "`company` int(11) NOT NULL DEFAULT '0',;\n" + + "`year` int(11) NOT NULL DEFAULT '0',;\n" + + "`model` char(50) NOT NULL DEFAULT '',;\n" + + "`colors` int(11) NOT NULL DEFAULT '0',;\n" + + "`res` char(10) NOT NULL DEFAULT '',;\n" + + "`hdd1` int(11) NOT NULL DEFAULT '0',;\n" + + "`hdd2` int(11) DEFAULT NULL,;\n" + + "`hdd3` int(11) DEFAULT NULL,;\n" + + "`disk1` int(11) NOT NULL DEFAULT '0',;\n" + + "`cap1` char(25) NOT NULL DEFAULT '0',;\n" + + "`disk2` int(11) DEFAULT NULL,;\n" + + "`cap2` char(25) DEFAULT NULL,;\n" + + "`type` int(11) NOT NULL DEFAULT '0',;\n" + + "PRIMARY KEY (`id`),;\n" + + "KEY `idx_machines_company` (`company`),;\n" + + "KEY `idx_machines_year` (`year`),;\n" + + "KEY `idx_machines_model` (`model`),;\n" + + "KEY `idx_machines_colors` (`colors`),;\n" + + "KEY `idx_machines_res` (`res`),;\n" + + "KEY `idx_machines_hdd1` (`hdd1`),;\n" + + "KEY `idx_machines_hdd2` (`hdd2`),;\n" + + "KEY `idx_machines_hdd3` (`hdd3`),;\n" + + "KEY `idx_machines_disk1` (`disk1`),;\n" + + "KEY `idx_machines_disk2` (`disk2`),;\n" + + "KEY `idx_machines_cap1` (`cap1`),;\n" + + "KEY `idx_machines_cap2` (`cap2`),;\n" + + "KEY `idx_machines_type` (`type`));"; + + public static readonly string DiskFormats = V17.DiskFormats; + + public static readonly string Forbidden = V17.Forbidden; + + public static readonly string Gpus = V17.Gpus; + + public static readonly string Logs = V17.Logs; + + public static readonly string MoneyDonations = V17.MoneyDonations; + + public static readonly string News = V17.News; + + public static readonly string OwnedComputers = V17.OwnedComputers; + + public static readonly string OwnedConsoles = V17.OwnedConsoles; + + public static readonly string Processors = V17.Processors; + + public static readonly string SoundSynths = V17.SoundSynths; + + public static readonly string MachinesForeignKeys = V17.MachinesForeignKeys; + + public static readonly string Iso3166Numeric = V17.Iso3166Numeric; + + public static readonly string Iso3166NumericValues = V17.Iso3166NumericValues; + + public static readonly string CompaniesForeignKeys = V17.CompaniesForeignKeys; + + public static readonly string CompanyLogos = V17.CompanyLogos; + + public static readonly string CompanyDescriptions = V17.CompanyDescriptions; + + public static readonly string InstructionSets = V17.InstructionSets; + + public static readonly string InstructionSetExtensions = V17.InstructionSetExtensions; + + public static readonly string InstructionSetExtensionsByProcessor = V17.InstructionSetExtensionsByProcessor; + + public static readonly string ProcessorsByMachine = V17.ProcessorsByMachine; + + public static readonly string GpusByMachine = V17.GpusByMachine; + + public static readonly string SoundByMachine = V17.SoundByMachine; + + public static readonly string MemoryByMachine = "CREATE TABLE `memory_by_machine` (\n" + + "`machine` INT NOT NULL,\n" + + "`type` INT NOT NULL DEFAULT 0,\n" + + "`usage` INT NOT NULL DEFAULT 0,\n" + + "`size` BIGINT DEFAULT NULL,\n" + + "`speed` DOUBLE DEFAULT NULL,\n" + + "KEY `idx_memory_by_machine_machine` (`machine`),\n" + + "KEY `idx_memory_by_machine_type` (`type`),\n" + + "KEY `idx_memory_by_machine_usage` (`usage`),\n" + + "KEY `idx_memory_by_machine_size` (`size`),\n" + + "KEY `idx_memory_by_machine_speed` (`speed`),\n" + + "CONSTRAINT `fk_memory_by_machine_machine` FOREIGN KEY (`machine`) REFERENCES `machines` (`id`) ON UPDATE CASCADE ON DELETE CASCADE);"; + } +} \ No newline at end of file diff --git a/cicm_web/Models/Machine.cs b/cicm_web/Models/Machine.cs index 01a1b755..f37e1b1b 100644 --- a/cicm_web/Models/Machine.cs +++ b/cicm_web/Models/Machine.cs @@ -48,14 +48,12 @@ namespace cicm_web.Models public DiskFormat Hdd2; public DiskFormat Hdd3; public int Id; + public MemoryByMachine[] Memories; public string Model; public ProcessorByMachine[] Processors; - public int Ram; public string Resolution; - public int Rom; public SoundByMachine[] SoundSynths; public MachineType Type; - public int Vram; public int Year; public static Machine[] GetAllItems() @@ -97,14 +95,12 @@ namespace cicm_web.Models Hdd3 = DiskFormat.GetItem(dbItem.Hdd3), Id = dbItem.Id, Model = dbItem.Model, - Ram = dbItem.Ram, Resolution = dbItem.Resolution, - Rom = dbItem.Rom, - Vram = dbItem.Vram, Year = dbItem.Year, Type = dbItem.Type, Processors = ProcessorByMachine.GetAllItems(dbItem.Id), - SoundSynths = SoundByMachine.GetAllItems(dbItem.Id) + SoundSynths = SoundByMachine.GetAllItems(dbItem.Id), + Memories = MemoryByMachine.GetAllItems(dbItem.Id) }; if(dbItem.Disk1 > 0) diff --git a/cicm_web/Models/MemoryByMachine.cs b/cicm_web/Models/MemoryByMachine.cs new file mode 100644 index 00000000..de2d87b7 --- /dev/null +++ b/cicm_web/Models/MemoryByMachine.cs @@ -0,0 +1,64 @@ +/****************************************************************************** +// Canary Islands Computer Museum Website +// ---------------------------------------------------------------------------- +// +// Filename : GpuByMachine.cs +// Author(s) : Natalia Portillo +// +// --[ Description ] ---------------------------------------------------------- +// +// Gpu by machine model +// +// --[ License ] -------------------------------------------------------------- +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// +// ---------------------------------------------------------------------------- +// Copyright © 2003-2018 Natalia Portillo +*******************************************************************************/ + +using System.Collections.Generic; +using Cicm.Database.Schemas; + +namespace cicm_web.Models +{ + public class MemoryByMachine + { + public MemoryType Type; + public MemoryUsage Usage; + public long Size; + public double Speed; + + public static MemoryByMachine[] GetAllItems(int machineId) + { + List dbItems = null; + bool? result = + Program.Database?.Operations.GetMemoryByMachine(out dbItems, machineId); + if(result == null || result.Value == false || dbItems == null) return null; + + List items = new List(); + + foreach(Cicm.Database.Schemas.MemoryByMachine dbItem in dbItems) + items.Add(new MemoryByMachine + { + Type =dbItem.Type, + Usage =dbItem.Usage, + Size =dbItem.Size, + Speed =dbItem.Speed + }); + + return items.ToArray(); + } + } +} \ No newline at end of file diff --git a/cicm_web/Views/Machine/View.cshtml b/cicm_web/Views/Machine/View.cshtml index 1d48ae76..01d5960a 100644 --- a/cicm_web/Views/Machine/View.cshtml +++ b/cicm_web/Views/Machine/View.cshtml @@ -329,64 +329,42 @@ } - - -
- Base RAM memory -
- - @if(Model.Ram > 1024) - { - if(Model.Ram > 1048576) - { - @($"{Model.Ram / 1048576}") Gbytes - } - else - { - @($"{Model.Ram / 1024}") Mbytes - } - } - else - { - if(Model.Ram == 0) - { - Unknown data - } - else - { - @Model.Ram Kbytes - } - } - - - -
- ROM -
- - @if(Model.Rom > 1024) - { - if(Model.Rom > 1048576) - { - @($"{Model.Rom / 1048576}") Gbytes - } - else - { - @($"{Model.Rom / 1024}") Mbytes - } - } - else - { - if(Model.Rom == 0) - { - Unknown data - } - else - { - @Model.Rom Kbytes - } - } - +@if(Model.Memories != null && Model.Memories.Length > 0) +{ + + +
+ Memory +
+ + + + @foreach(MemoryByMachine memory in Model.Memories) + { + string memValue; + if(memory.Size > 1073741824) { memValue = $"{memory.Size / 1073741824} GiB"; } + else if(memory.Size > 1048576) { memValue = $"{memory.Size / 1048576} MiB"; } + else if(memory.Size > 1024) { memValue = $"{memory.Size / 1024} KiB"; } + else if(memory.Size > 0) { memValue = $"{memory.Size} bytes"; } + else + { memValue = "Unknown size"; } + + string speedValue; + if(memory.Speed > 1000000000) { speedValue = $"{memory.Speed / 1000000000} GHz"; } + else if(memory.Speed > 1000000) { speedValue = $"{memory.Speed / 1000000} MHz"; } + else if(memory.Speed > 1000) { speedValue = $"{memory.Speed / 1000} KHz"; } + else if(memory.Speed > 0) { speedValue = $"{memory.Speed} Hz"; } + else + { speedValue = "unknown speed"; } + + + + + } +
@memValue of @memory.Usage memory (@memory.Type at @speedValue)
+ + +} @if(Model.Gpus != null && Model.Gpus.Length > 0) { @@ -511,35 +489,6 @@ } - - -
- Video memory -
- - @if(Model.Vram > 1024) - { - if(Model.Vram > 1048576) - { - @($"{Model.Vram / 1048576}") Gbytes - } - else - { - @($"{Model.Vram / 1024}") Mbytes - } - } - else - { - if(Model.Vram == 0) - { - Unknown data - } - else - { - @Model.Vram Kbytes - } - } -
diff --git a/cicm_web/cicm_web.csproj b/cicm_web/cicm_web.csproj index 55cdc653..17a503de 100644 --- a/cicm_web/cicm_web.csproj +++ b/cicm_web/cicm_web.csproj @@ -2,7 +2,7 @@ netcoreapp2.0 - 3.0.99.209 + 3.0.99.215 Canary Islands Computer Museum Copyright © 2003-2018 Natalia Portillo Canary Islands Computer Museum Website