Move all database logic in machine view out of the view into the controller.

This commit is contained in:
2020-05-22 04:43:44 +01:00
parent 113b9fbad8
commit b3414bde1d
9 changed files with 359 additions and 152 deletions

View File

@@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web"> <Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup> <PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework> <TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.0.99.969</Version> <Version>3.0.99.971</Version>
<Company>Canary Islands Computer Museum</Company> <Company>Canary Islands Computer Museum</Company>
<Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright> <Copyright>Copyright © 2003-2020 Natalia Portillo</Copyright>
<Product>Canary Islands Computer Museum Website</Product> <Product>Canary Islands Computer Museum Website</Product>

View File

@@ -3,12 +3,12 @@
// MARECHAI: Master repository of computing history artifacts information // MARECHAI: Master repository of computing history artifacts information
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// //
// Filename : Index.cshtml // Filename : View.razor
// Author(s) : Natalia Portillo <claunia@claunia.com> // Author(s) : Natalia Portillo <claunia@claunia.com>
// //
// --[ Description ] ---------------------------------------------------------- // --[ Description ] ----------------------------------------------------------
// //
// Index page (and news) // Shows a machine information
// //
// --[ License ] -------------------------------------------------------------- // --[ License ] --------------------------------------------------------------
// //
@@ -32,9 +32,8 @@
} }
@page "/machine/{Id:int}" @page "/machine/{Id:int}"
@using Marechai.Database.Models
@using Marechai.Database
@using Marechai.Database
@inherits OwningComponentBase<MachinesService> @inherits OwningComponentBase<MachinesService>
@inject IStringLocalizer<MachinesService> L @inject IStringLocalizer<MachinesService> L
@inject IWebHostEnvironment Host @inject IWebHostEnvironment Host
@@ -54,17 +53,17 @@
} }
<p align="center"> <p align="center">
@if (_machine.Company.LastLogo != null && @if (_machine.CompanyLogo != null &&
File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.Company.LastLogo.Guid + ".svg"))) File.Exists(Path.Combine(Host.WebRootPath, "assets/logos", _machine.CompanyLogo + ".svg")))
{ {
<picture> <picture>
<source type="image/svg+xml" srcset="/assets/logos/@(_machine.Company.LastLogo.Guid).svg"> <source type="image/svg+xml" srcset="/assets/logos/@(_machine.CompanyLogo).svg">
<source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.Company.LastLogo.Guid).webp, <source type="image/webp" srcset="/assets/logos/webp/1x/@(_machine.CompanyLogo).webp,
/assets/logos/webp/2x/@(_machine.Company.LastLogo.Guid).webp 2x, /assets/logos/webp/2x/@(_machine.CompanyLogo).webp 2x,
/assets/logos/webp/3x/@(_machine.Company.LastLogo.Guid).webp 3x"> /assets/logos/webp/3x/@(_machine.CompanyLogo).webp 3x">
<img srcset="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png, <img srcset="/assets/logos/png/1x/@(_machine.CompanyLogo).png,
/assets/logos/png/2x/@(_machine.Company.LastLogo.Guid).png 2x, /assets/logos/png/2x/@(_machine.CompanyLogo).png 2x,
/assets/logos/png/3x/@(_machine.Company.LastLogo.Guid).png 3x" src="/assets/logos/png/1x/@(_machine.Company.LastLogo.Guid).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" /> /assets/logos/png/3x/@(_machine.CompanyLogo).png 3x" src="/assets/logos/png/1x/@(_machine.CompanyLogo).png" alt="" height="auto" width="auto" style="max-height: 256px; max-width: 256px" />
</picture> </picture>
} }
</p> </p>
@@ -78,8 +77,8 @@
</b> </b>
} }
<b> <b>
<a asp-controller="Company" asp-action="View" asp-route-id="@_machine.Company.Id"> <a href="/company/@_machine.CompanyId">
@_machine.Company.Name</a> @_machine.Name</b> @_machine.CompanyName</a> @_machine.Name</b>
<table width="100%"> <table width="100%">
@if (_machine.Introduced.HasValue && @if (_machine.Introduced.HasValue &&
@@ -97,7 +96,7 @@
</td> </td>
</tr> </tr>
} }
@if (_machine.Family != null) @if (_machine.FamilyId != null)
{ {
<tr> <tr>
<th scope=row width="37%"> <th scope=row width="37%">
@@ -106,8 +105,8 @@
</div> </div>
</th> </th>
<td width="63%"> <td width="63%">
<a asp-controller="Computer" asp-action="ByFamily" asp-route-id="@_machine.Family.Id"> <a href="/machines/family/@_machine.FamilyId">
@_machine.Family.Name</a> @_machine.FamilyName</a>
</td> </td>
</tr> </tr>
} }
@@ -135,17 +134,17 @@
<td> <td>
<table> <table>
@{ counter = 0; } @{ counter = 0; }
@foreach (var processorByMachine in _machine.Processors) @foreach (var processor in _machine.Processors)
{ {
<tr> <tr>
<td> <td>
@if (processorByMachine.Speed > 0) @if (processor.Speed > 0)
{ {
@(processorByMachine.Processor.GprSize > 0 ? $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz ({processorByMachine.Processor.GprSize} bits)" : $"{processorByMachine.Processor.Name} @ {processorByMachine.Speed}Mhz") @(processor.GprSize > 0 ? $"{processor.Name} @ {processor.Speed}Mhz ({processor.GprSize} bits)" : $"{processor.Name} @ {processor.Speed}Mhz")
} }
else else
{ {
@($"{processorByMachine.Processor.Name}") @($"{processor.Name}")
} }
<a aria-controls="@($"cpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#cpuInfo{counter}")"> <a aria-controls="@($"cpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#cpuInfo{counter}")">
+info +info
@@ -153,87 +152,87 @@
<div class="collapse" id="@($"cpuInfo{counter}")"> <div class="collapse" id="@($"cpuInfo{counter}")">
<div class="card card-body"> <div class="card card-body">
<table> <table>
@if (processorByMachine.Processor.ModelCode != null && @if (processor.ModelCode != null &&
processorByMachine.Processor.ModelCode != processorByMachine.Processor.Name) processor.ModelCode != processor.Name)
{ {
<tr> <tr>
<td>Model</td> <td>Model</td>
<td>@processorByMachine.Processor.ModelCode</td> <td>@processor.ModelCode</td>
</tr> </tr>
} }
<tr> <tr>
<td>Manufacturer</td> <td>Manufacturer</td>
<td> <td>
<a asp-controller=Company asp-action=View asp-route-id=@processorByMachine.Processor.Company.Id> <a href="/processors/company/@processor.CompanyId">
@processorByMachine.Processor.Company.Name</a> @processor.CompanyName</a>
</td> </td>
</tr> </tr>
@if (processorByMachine.Processor.Introduced != DateTime.MinValue) @if (processor.Introduced != null)
{ {
<tr> <tr>
<td>Introduction date</td> <td>Introduction date</td>
<td>@($"{processorByMachine.Processor.Introduced:yyyy}")</td> <td>@($"{processor.Introduced:yyyy}")</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.InstructionSet != null) @if (processor.InstructionSet != null)
{ {
<tr> <tr>
<td>Instruction set</td> <td>Instruction set</td>
<td>@processorByMachine.Processor.InstructionSet.Name</td> <td>@processor.InstructionSet</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Speed > 0) @if (processor.Speed > 0)
{ {
<tr> <tr>
<td>Nominal speed</td> <td>Nominal speed</td>
<td>@processorByMachine.Processor.Speed MHz</td> <td>@processor.Speed MHz</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Gprs > 0 || @if (processor.Gprs > 0 ||
processorByMachine.Processor.Fprs > 0 || processor.Fprs > 0 ||
processorByMachine.Processor.SimdRegisters > 0) processor.SimdRegisters > 0)
{ {
<tr> <tr>
<td>Registers</td> <td>Registers</td>
<td> <td>
<table> <table>
@if (processorByMachine.Processor.Gprs > 0) @if (processor.Gprs > 0)
{ {
<tr> <tr>
<td> <td>
@processorByMachine.Processor.Gprs general purpose registers of @processorByMachine.Processor.GprSize bits @processor.Gprs general purpose registers of @processor.GprSize bits
@if (processorByMachine.Processor.FprSize > 0 && @if (processor.FprSize > 0 &&
processorByMachine.Processor.Fprs == 0) processor.Fprs == 0)
{ {
@($", that can be used as floating point registers of {processorByMachine.Processor.FprSize}") @($", that can be used as floating point registers of {processor.FprSize}")
} }
@if (processorByMachine.Processor.SimdSize > 0 && @if (processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0) processor.SimdRegisters == 0)
{ {
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}") @($", that can be used as SIMD registers of {processor.FprSize}")
} }
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Fprs > 0) @if (processor.Fprs > 0)
{ {
<tr> <tr>
<td> <td>
@processorByMachine.Processor.Fprs floating-point registers of @processorByMachine.Processor.FprSize bits @processor.Fprs floating-point registers of @processor.FprSize bits
@if (processorByMachine.Processor.SimdSize > 0 && @if (processor.SimdSize > 0 &&
processorByMachine.Processor.SimdRegisters == 0) processor.SimdRegisters == 0)
{ {
@($", that can be used as SIMD registers of {processorByMachine.Processor.FprSize}") @($", that can be used as SIMD registers of {processor.FprSize}")
} }
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.SimdRegisters > 0) @if (processor.SimdRegisters > 0)
{ {
<tr> <tr>
<td> <td>
@processorByMachine.Processor.SimdRegisters @processor.SimdRegisters
<abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processorByMachine.Processor.SimdSize bits <abbr title="Single instruction, multiple data">SIMD</abbr>registers of @processor.SimdSize bits
</td> </td>
</tr> </tr>
} }
@@ -241,48 +240,48 @@
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Cores > 1) @if (processor.Cores > 1)
{ {
<tr> <tr>
<td>Multi-core</td> <td>Multi-core</td>
<td>@processorByMachine.Processor.Cores cores</td> <td>@processor.Cores cores</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Cores > 1) @if (processor.ThreadsPerCore > 1)
{ {
<tr> <tr>
<td> <td>
<abbr title="Simultaneous multithreading">SMT</abbr> <abbr title="Simultaneous multithreading">SMT</abbr>
</td> </td>
<td> <td>
@processorByMachine.Processor.ThreadsPerCore threads @processor.ThreadsPerCore threads
@if (processorByMachine.Processor.Cores > 1) @if (processor.Cores > 1)
{ {
@(" per core") @(" per core")
} }
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.DataBus > 0 || @if (processor.DataBus > 0 ||
processorByMachine.Processor.AddrBus > 0) processor.AddrBus > 0)
{ {
<tr> <tr>
<td>Bus</td> <td>Bus</td>
<td> <td>
<table> <table>
@if (processorByMachine.Processor.DataBus > 0) @if (processor.DataBus > 0)
{ {
<tr> <tr>
<td> <td>
@processorByMachine.Processor.DataBus-bit data @processor.DataBus-bit data
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.AddrBus > 0) @if (processor.AddrBus > 0)
{ {
<tr> <tr>
<td> <td>
@processorByMachine.Processor.AddrBus-bit address @processor.AddrBus-bit address
</td> </td>
</tr> </tr>
} }
@@ -291,44 +290,44 @@
</tr> </tr>
} }
@if (processorByMachine.Processor.L1Instruction > 0 || @if (processor.L1Instruction > 0 ||
processorByMachine.Processor.L1Data > 0 || processor.L1Data > 0 ||
processorByMachine.Processor.L2 > 0 || processor.L2 > 0 ||
processorByMachine.Processor.L2 > 0) processor.L2 > 0)
{ {
<tr> <tr>
<td>Cache</td> <td>Cache</td>
<td> <td>
<table> <table>
@if (processorByMachine.Processor.L1Instruction > 0) @if (processor.L1Instruction > 0)
{ {
<tr> <tr>
<td> <td>
@(processorByMachine.Processor.L1Data < 0 ? $"{processorByMachine.Processor.L1Instruction}KiB combined instruction-data L1" : $"{processorByMachine.Processor.L1Instruction}KiB instruction L1") @(processor.L1Data < 0 ? $"{processor.L1Instruction}KiB combined instruction-data L1" : $"{processor.L1Instruction}KiB instruction L1")
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.L1Data > 0) @if (processor.L1Data > 0)
{ {
<tr> <tr>
<td> <td>
@($"{processorByMachine.Processor.L1Data}KiB data L1") @($"{processor.L1Data}KiB data L1")
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.L2 > 0) @if (processor.L2 > 0)
{ {
<tr> <tr>
<td> <td>
@($"{processorByMachine.Processor.L2}KiB L2") @($"{processor.L2}KiB L2")
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.L3 > 0) @if (processor.L3 > 0)
{ {
<tr> <tr>
<td> <td>
@($"{processorByMachine.Processor.L3}KiB L3") @($"{processor.L3}KiB L3")
</td> </td>
</tr> </tr>
} }
@@ -336,49 +335,49 @@
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Package != null) @if (processor.Package != null)
{ {
<tr> <tr>
<td>Package</td> <td>Package</td>
<td>@processorByMachine.Processor.Package</td> <td>@processor.Package</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Process != null || @if (processor.Process != null ||
processorByMachine.Processor.ProcessNm > 0) processor.ProcessNm > 0)
{ {
<tr> <tr>
<td>Manufacturing process</td> <td>Manufacturing process</td>
<td> <td>
@if (processorByMachine.Processor.Process != null && @if (processor.Process != null &&
processorByMachine.Processor.ProcessNm > 0) processor.ProcessNm > 0)
{ {
@processorByMachine.Processor.Process @processor.Process
@("@") @("@")
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm") @(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
} }
else if (processorByMachine.Processor.ProcessNm > 0) else if (processor.ProcessNm > 0)
{ {
@(processorByMachine.Processor.ProcessNm > 100 ? $"{processorByMachine.Processor.ProcessNm / 100}µm" : $"{processorByMachine.Processor.ProcessNm}nm") @(processor.ProcessNm > 100 ? $"{processor.ProcessNm / 100}µm" : $"{processor.ProcessNm}nm")
} }
else else
{ {
@processorByMachine.Processor.Process @processor.Process
} }
</td> </td>
</tr> </tr>
} }
@if (processorByMachine.Processor.DieSize > 0) @if (processor.DieSize > 0)
{ {
<tr> <tr>
<td>Die size</td> <td>Die size</td>
<td>@processorByMachine.Processor.DieSize mm&sup2;</td> <td>@processor.DieSize mm&sup2;</td>
</tr> </tr>
} }
@if (processorByMachine.Processor.Transistors > 0) @if (processor.Transistors > 0)
{ {
<tr> <tr>
<td>Transistors</td> <td>Transistors</td>
<td>@processorByMachine.Processor.Transistors</td> <td>@processor.Transistors</td>
</tr> </tr>
} }
</table> </table>
@@ -469,9 +468,9 @@
<td> <td>
<table> <table>
@{ counter = 0; } @{ counter = 0; }
@foreach (var gpuByMachine in _machine.Gpus) @foreach (var gpu in _machine.Gpus)
{ {
if (gpuByMachine.Gpu.Id == -2) if (gpu.Id == -2)
{ {
<td> <td>
Framebuffer Framebuffer
@@ -489,78 +488,78 @@
else else
{ {
<td> <td>
@($"{gpuByMachine.Gpu.Name}") @($"{gpu.Name}")
<a aria-controls="@($"gpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#gpuInfo{counter}")"> <a aria-controls="@($"gpuInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#gpuInfo{counter}")">
+info +info
</a> </a>
<div class="collapse" id="@($"gpuInfo{counter}")"> <div class="collapse" id="@($"gpuInfo{counter}")">
<div class="card card-body"> <div class="card card-body">
<table> <table>
@if (gpuByMachine.Gpu.ModelCode != null && @if (gpu.ModelCode != null &&
gpuByMachine.Gpu.ModelCode != gpuByMachine.Gpu.Name) gpu.ModelCode != gpu.Name)
{ {
<tr> <tr>
<td>Model</td> <td>Model</td>
<td>@gpuByMachine.Gpu.ModelCode</td> <td>@gpu.ModelCode</td>
</tr> </tr>
} }
<tr> <tr>
<td>Manufacturer</td> <td>Manufacturer</td>
<td> <td>
<a asp-controller=Company asp-action=View asp-route-id=@gpuByMachine.Gpu.Company.Id> <a href="/gpus/company/@gpu.CompanyId">
@gpuByMachine.Gpu.Company.Name</a> @gpu.Company</a>
</td> </td>
</tr> </tr>
@if (gpuByMachine.Gpu.Introduced != DateTime.MinValue) @if (gpu.Introduced != null)
{ {
<tr> <tr>
<td>Introduction date</td> <td>Introduction date</td>
<td>@($"{gpuByMachine.Gpu.Introduced:yyyy}")</td> <td>@($"{gpu.Introduced:yyyy}")</td>
</tr> </tr>
} }
@if (gpuByMachine.Gpu.Package != null) @if (gpu.Package != null)
{ {
<tr> <tr>
<td>Package</td> <td>Package</td>
<td>@gpuByMachine.Gpu.Package</td> <td>@gpu.Package</td>
</tr> </tr>
} }
@if (gpuByMachine.Gpu.Process != null || @if (gpu.Process != null ||
gpuByMachine.Gpu.ProcessNm > 0) gpu.ProcessNm > 0)
{ {
<tr> <tr>
<td>Manufacturing process</td> <td>Manufacturing process</td>
<td> <td>
@if (gpuByMachine.Gpu.Process != null && @if (gpu.Process != null &&
gpuByMachine.Gpu.ProcessNm > 0) gpu.ProcessNm > 0)
{ {
@gpuByMachine.Gpu.Process @gpu.Process
@("@") @("@")
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm") @(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
} }
else if (gpuByMachine.Gpu.ProcessNm > 0) else if (gpu.ProcessNm > 0)
{ {
@(gpuByMachine.Gpu.ProcessNm > 100 ? $"{gpuByMachine.Gpu.ProcessNm / 100}µm" : $"{gpuByMachine.Gpu.ProcessNm}nm") @(gpu.ProcessNm > 100 ? $"{gpu.ProcessNm / 100}µm" : $"{gpu.ProcessNm}nm")
} }
else else
{ {
@gpuByMachine.Gpu.Process @gpu.Process
} }
</td> </td>
</tr> </tr>
} }
@if (gpuByMachine.Gpu.DieSize > 0) @if (gpu.DieSize > 0)
{ {
<tr> <tr>
<td>Die size</td> <td>Die size</td>
<td>@gpuByMachine.Gpu.DieSize mm&sup2;</td> <td>@gpu.DieSize mm&sup2;</td>
</tr> </tr>
} }
@if (gpuByMachine.Gpu.Transistors > 0) @if (gpu.Transistors > 0)
{ {
<tr> <tr>
<td>Transistors</td> <td>Transistors</td>
<td>@gpuByMachine.Gpu.Transistors</td> <td>@gpu.Transistors</td>
</tr> </tr>
} }
</table> </table>
@@ -574,7 +573,7 @@
</td> </td>
</tr> </tr>
} }
@if (_machine.Sound.Count > 0) @if (_machine.SoundSynthetizers.Count > 0)
{ {
<tr> <tr>
<th scope=row> <th scope=row>
@@ -585,10 +584,10 @@
<td> <td>
<table> <table>
@{ counter = 0; } @{ counter = 0; }
@foreach (var soundByMachine in _machine.Sound) @foreach (var sound in _machine.SoundSynthetizers)
{ {
<tr> <tr>
@if (soundByMachine.SoundSynth.Id == -2) @if (sound.Id == -2)
{ {
<td> <td>
Software Software
@@ -606,104 +605,104 @@
else else
{ {
<td> <td>
@($"{soundByMachine.SoundSynth.Name}") @($"{sound.Name}")
<a aria-controls="@($"synthInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#synthInfo{counter}")"> <a aria-controls="@($"synthInfo{counter}")" aria-expanded="false" class="btn btn-link" data-toggle="collapse" href="@($"#synthInfo{counter}")">
+info +info
</a> </a>
<div class="collapse" id="@($"synthInfo{counter}")"> <div class="collapse" id="@($"synthInfo{counter}")">
<div class="card card-body"> <div class="card card-body">
<table> <table>
@if (soundByMachine.SoundSynth.ModelCode != null && @if (sound.ModelCode != null &&
soundByMachine.SoundSynth.ModelCode != soundByMachine.SoundSynth.Name) sound.ModelCode != sound.Name)
{ {
<tr> <tr>
<td>Model</td> <td>Model</td>
<td>@soundByMachine.SoundSynth.ModelCode</td> <td>@sound.ModelCode</td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.Company != null) @if (sound.CompanyId != null)
{ {
<tr> <tr>
<td>Manufacturer</td> <td>Manufacturer</td>
<td> <td>
<a asp-controller=Company asp-action=View asp-route-id=@soundByMachine.SoundSynth.Company.Id> <a href="/soundsynths/company/@sound.CompanyId">
@soundByMachine.SoundSynth.Company.Name</a> @sound.CompanyName</a>
</td> </td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.Introduced != DateTime.MinValue) @if (sound.Introduced != null)
{ {
<tr> <tr>
<td>Introduction date</td> <td>Introduction date</td>
<td>@($"{soundByMachine.SoundSynth.Introduced:yyyy}")</td> <td>@($"{sound.Introduced:yyyy}")</td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.Voices != 0 || @if (sound.Voices != 0 ||
soundByMachine.SoundSynth.SquareWave != 0 || sound.SquareWave != 0 ||
soundByMachine.SoundSynth.WhiteNoise != 0) sound.WhiteNoise != 0)
{ {
<tr> <tr>
<td>Generators</td> <td>Generators</td>
<td> <td>
<table> <table>
@if (soundByMachine.SoundSynth.Voices != 0) @if (sound.Voices != 0)
{ {
<tr> <tr>
<td>@soundByMachine.SoundSynth.Voices voices</td> <td>@sound.Voices voices</td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.SquareWave != 0) @if (sound.SquareWave != 0)
{ {
<tr> <tr>
<td>@soundByMachine.SoundSynth.SquareWave square wave</td> <td>@sound.SquareWave square wave</td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.WhiteNoise != 0) @if (sound.WhiteNoise != 0)
{ {
<tr> <tr>
<td>@soundByMachine.SoundSynth.WhiteNoise white noise</td> <td>@sound.WhiteNoise white noise</td>
</tr> </tr>
} }
</table> </table>
</td> </td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.Depth != 0 || @if (sound.Depth != 0 ||
soundByMachine.SoundSynth.Frequency > 0) sound.Frequency > 0)
{ {
<tr> <tr>
<td>Sample rate</td> <td>Sample rate</td>
<td> <td>
<table> <table>
@if (soundByMachine.SoundSynth.Depth != 0 && @if (sound.Depth != 0 &&
soundByMachine.SoundSynth.Frequency > 0) sound.Frequency > 0)
{ {
<tr> <tr>
<td>@soundByMachine.SoundSynth.Depth bits at @(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td> <td>@sound.Depth bits at @(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr> </tr>
} }
else if (soundByMachine.SoundSynth.Depth != 0) else if (sound.Depth != 0)
{ {
<tr> <tr>
<td>@soundByMachine.SoundSynth.Depth bits</td> <td>@sound.Depth bits</td>
</tr> </tr>
} }
else else
{ {
<tr> <tr>
<td>@(soundByMachine.SoundSynth.Frequency > 1000 ? $"{soundByMachine.SoundSynth.Frequency / 1000}KHz" : $"{soundByMachine.SoundSynth.Frequency}Hz")</td> <td>@(sound.Frequency > 1000 ? $"{sound.Frequency / 1000}KHz" : $"{sound.Frequency}Hz")</td>
</tr> </tr>
} }
</table> </table>
</td> </td>
</tr> </tr>
} }
@if (soundByMachine.SoundSynth.Type != 0) @if (sound.Type != 0)
{ {
<tr> <tr>
<td>Synthetizer type</td> <td>Synthetizer type</td>
<td> <td>
@soundByMachine.SoundSynth.Type @sound.Type
</td> </td>
</tr> </tr>
} }
@@ -811,7 +810,7 @@
[Parameter] [Parameter]
public int Id { get; set; } public int Id { get; set; }
Machine _machine; MachineViewModel _machine;
bool _loaded; bool _loaded;
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()

View File

@@ -1,5 +1,8 @@
using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Marechai.Database.Models; using Marechai.Database.Models;
using Marechai.ViewModels;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Localization; using Microsoft.Extensions.Localization;
namespace Marechai.Services namespace Marechai.Services
@@ -15,6 +18,99 @@ namespace Marechai.Services
_l = localizer; _l = localizer;
} }
public async Task<Machine> GetMachine(int id) => await _context.Machines.FindAsync(id); public async Task<MachineViewModel> GetMachine(int id)
{
Machine machine = await _context.Machines.FindAsync(id);
if(machine is null)
return null;
var model = new MachineViewModel
{
Introduced = machine.Introduced, Name = machine.Name, CompanyId = machine.CompanyId,
Model = machine.Model
};
Company company = await _context.Companies.FindAsync(model.CompanyId);
if(company != null)
{
model.CompanyName = company.Name;
IQueryable<CompanyLogo> logos = _context.CompanyLogos.Where(l => l.CompanyId == company.Id);
if(model.Introduced.HasValue)
model.CompanyLogo = (await logos.FirstOrDefaultAsync(l => l.Year >= model.Introduced.Value.Year))?.
Guid;
if(model.CompanyLogo is null &&
logos.Any())
model.CompanyLogo = (await logos.FirstAsync())?.Guid;
}
MachineFamily family = await _context.MachineFamilies.FindAsync(machine.FamilyId);
if(family != null)
{
model.FamilyName = family.Name;
model.FamilyId = family.Id;
}
model.Gpus = await _context.GpusByMachine.Where(g => g.MachineId == machine.Id).Select(g => g.Gpu).
Select(g => new GpuViewModel
{
Id = g.Id, Name = g.Name, Company = g.Company.Name,
CompanyId = g.Company.Id, ModelCode = g.ModelCode,
Introduced = g.Introduced, Package = g.Package, Process = g.Process,
ProcessNm = g.ProcessNm, DieSize = g.DieSize, Transistors = g.Transistors
}).ToListAsync();
model.Memory = await _context.MemoryByMachine.Where(m => m.MachineId == machine.Id).
Select(m => new MemoryViewModel
{
Type = m.Type, Usage = m.Usage, Size = m.Size, Speed = m.Speed
}).ToListAsync();
model.Processors = await _context.ProcessorsByMachine.Where(p => p.MachineId == machine.Id).
Select(p => new ProcessorViewModel
{
Name = p.Processor.Name, CompanyName = p.Processor.Company.Name,
CompanyId = p.Processor.Company.Id, ModelCode = p.Processor.ModelCode,
Introduced = p.Processor.Introduced, Speed = p.Speed,
Package = p.Processor.Package, Gprs = p.Processor.Gprs,
GprSize = p.Processor.GprSize, Fprs = p.Processor.Fprs,
FprSize = p.Processor.FprSize, Cores = p.Processor.Cores,
ThreadsPerCore = p.Processor.ThreadsPerCore,
Process = p.Processor.Process, ProcessNm = p.Processor.ProcessNm,
DieSize = p.Processor.DieSize, Transistors = p.Processor.Transistors,
DataBus = p.Processor.DataBus, AddrBus = p.Processor.AddrBus,
SimdRegisters = p.Processor.SimdRegisters,
SimdSize = p.Processor.SimdSize,
L1Instruction = p.Processor.L1Instruction,
L1Data = p.Processor.L1Data, L2 = p.Processor.L2, L3 = p.Processor.L3,
InstructionSet = p.Processor.InstructionSet.Name,
InstructionSetExtensions =
p.Processor.InstructionSetExtensions.
Select(e => e.Extension.Extension).ToList()
}).ToListAsync();
model.SoundSynthetizers =
await _context.SoundByMachine.Where(s => s.MachineId == machine.Id).Select(s => s.SoundSynth).
Select(s => new SoundSynthViewModel
{
Id = s.Id, Name = s.Name, CompanyId = s.Company.Id, CompanyName = s.Company.Name,
ModelCode = s.ModelCode, Introduced = s.Introduced, Voices = s.Voices,
Frequency = s.Frequency, Depth = s.Depth, SquareWave = s.SquareWave,
WhiteNoise = s.WhiteNoise, Type = s.Type
}).ToListAsync();
model.Storage = await _context.StorageByMachine.Where(s => s.MachineId == machine.Id).
Select(s => new StorageViewModel
{
Type = s.Type, Interface = s.Interface, Capacity = s.Capacity
}).ToListAsync();
return model;
}
} }
} }

View File

@@ -0,0 +1,19 @@
using System;
namespace Marechai.ViewModels
{
public class GpuViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public int? CompanyId { get; set; }
public string Company { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public string Package { get; set; }
public string Process { get; set; }
public float? ProcessNm { get; set; }
public float? DieSize { get; set; }
public long? Transistors { get; set; }
}
}

View File

@@ -1,9 +1,23 @@
using System;
using System.Collections.Generic;
namespace Marechai.ViewModels namespace Marechai.ViewModels
{ {
public class MachineViewModel public class MachineViewModel
{ {
public int Id { get; set; } public int Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string Model { get; set; }
public string CompanyName { get; set; } public string CompanyName { get; set; }
public int CompanyId { get; set; }
public Guid? CompanyLogo { get; set; }
public DateTime? Introduced { get; set; }
public int? FamilyId { get; set; }
public string FamilyName { get; set; }
public List<GpuViewModel> Gpus { get; set; }
public List<MemoryViewModel> Memory { get; set; }
public List<ProcessorViewModel> Processors { get; set; }
public List<SoundSynthViewModel> SoundSynthetizers { get; set; }
public List<StorageViewModel> Storage { get; set; }
} }
} }

View File

@@ -0,0 +1,12 @@
using Marechai.Database;
namespace Marechai.ViewModels
{
public class MemoryViewModel
{
public MemoryType Type { get; set; }
public MemoryUsage Usage { get; set; }
public long? Size { get; set; }
public double? Speed { get; set; }
}
}

View File

@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
namespace Marechai.ViewModels
{
public class ProcessorViewModel
{
public string Name { get; set; }
public string CompanyName { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public double? Speed { get; set; }
public string Package { get; set; }
public int? Gprs { get; set; }
public int? GprSize { get; set; }
public int? Fprs { get; set; }
public int? FprSize { get; set; }
public int? Cores { get; set; }
public int? ThreadsPerCore { get; set; }
public string Process { get; set; }
public float? ProcessNm { get; set; }
public float? DieSize { get; set; }
public long? Transistors { get; set; }
public int? DataBus { get; set; }
public int? AddrBus { get; set; }
public int? SimdRegisters { get; set; }
public int? SimdSize { get; set; }
public float? L1Instruction { get; set; }
public float? L1Data { get; set; }
public float? L2 { get; set; }
public float? L3 { get; set; }
public string InstructionSet { get; set; }
public List<string> InstructionSetExtensions { get; set; }
public int? CompanyId { get; set; }
}
}

View File

@@ -0,0 +1,20 @@
using System;
namespace Marechai.ViewModels
{
public class SoundSynthViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public string CompanyName { get; set; }
public int? CompanyId { get; set; }
public string ModelCode { get; set; }
public DateTime? Introduced { get; set; }
public int? Voices { get; set; }
public double? Frequency { get; set; }
public int? Depth { get; set; }
public int? SquareWave { get; set; }
public int? WhiteNoise { get; set; }
public int? Type { get; set; }
}
}

View File

@@ -0,0 +1,11 @@
using Marechai.Database;
namespace Marechai.ViewModels
{
public class StorageViewModel
{
public StorageType Type { get; set; }
public StorageInterface Interface { get; set; }
public long? Capacity { get; set; }
}
}