mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 11:14:27 +00:00
Refactor MediaInformation to use a sorted set for preventing crashes on duplicate media types.
This commit is contained in:
@@ -684,16 +684,16 @@
|
||||
</h3>
|
||||
|
||||
<Accordion>
|
||||
@foreach(KeyValuePair<string, (Dictionary<string, string> Table, List<string> List)> mediaInfo in MediaInformation)
|
||||
@foreach((string Header, Dictionary<string, string> Table, List<string> List) mediaInfo in MediaInformation)
|
||||
{
|
||||
<AccordionItem>
|
||||
<TitleTemplate>
|
||||
@mediaInfo.Key
|
||||
@mediaInfo.Header
|
||||
</TitleTemplate>
|
||||
<Content>
|
||||
<table class="table table-dark table-borderless w-100">
|
||||
<tbody>
|
||||
@foreach(KeyValuePair<string, string> kvp in mediaInfo.Value.Table)
|
||||
@foreach(KeyValuePair<string, string> kvp in mediaInfo.Table)
|
||||
{
|
||||
<tr>
|
||||
<th>@kvp.Key</th>
|
||||
@@ -703,7 +703,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
<ul class="list-group">
|
||||
@foreach(string cap in mediaInfo.Value.List)
|
||||
@foreach(string cap in mediaInfo.List)
|
||||
{
|
||||
<li class="list-group-item">@cap</li>
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ using Aaru.CommonTypes.Structs.Devices.SCSI;
|
||||
using Aaru.Decoders.PCMCIA;
|
||||
using Aaru.Decoders.SCSI;
|
||||
using Aaru.Helpers;
|
||||
using Aaru.Server.Database.Models;
|
||||
using Aaru.Server.Core;
|
||||
using Aaru.Server.Database.Models;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Ata = Aaru.CommonTypes.Metadata.Ata;
|
||||
@@ -69,7 +69,11 @@ public partial class View
|
||||
public List<string>? MmcModeList { get; set; }
|
||||
public Dictionary<string, List<string>>? EvpdPages { get; set; }
|
||||
|
||||
public Dictionary<string, (Dictionary<string, string> Table, List<string> List)>? MediaInformation { get; set; }
|
||||
public SortedSet<(string Header, Dictionary<string, string> Table, List<string> List)>? MediaInformation
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override async Task OnInitializedAsync()
|
||||
@@ -280,10 +284,10 @@ public partial class View
|
||||
}
|
||||
}
|
||||
|
||||
var removable = true;
|
||||
bool removable = true;
|
||||
List<TestedMedia>? testedMedia = null;
|
||||
var atapi = false;
|
||||
var sscMedia = false;
|
||||
bool atapi = false;
|
||||
bool sscMedia = false;
|
||||
|
||||
if(report.ATA != null || report.ATAPI != null)
|
||||
{
|
||||
@@ -396,7 +400,7 @@ public partial class View
|
||||
|
||||
if(report.SCSI != null)
|
||||
{
|
||||
var vendorId = "";
|
||||
string? vendorId = "";
|
||||
|
||||
if(report.SCSI.Inquiry != null)
|
||||
{
|
||||
@@ -406,7 +410,8 @@ public partial class View
|
||||
DeviceInquiry = new Dictionary<string, string>
|
||||
{
|
||||
{
|
||||
"Vendor:", VendorString.Prettify(vendorId) != vendorId
|
||||
"Vendor:",
|
||||
VendorString.Prettify(vendorId) != vendorId
|
||||
? $"{vendorId} ({VendorString.Prettify(vendorId)})"
|
||||
: vendorId
|
||||
},
|
||||
@@ -511,8 +516,8 @@ public partial class View
|
||||
sscMedia = true;
|
||||
|
||||
SscTestedMedia.Report(report.SCSI.SequentialDevice.TestedMedia,
|
||||
out Dictionary<string, (Dictionary<string, string> Table, List<string> List)>
|
||||
mediaInformation);
|
||||
out SortedSet<(string Header, Dictionary<string, string> Table, List<string>
|
||||
List)> mediaInformation);
|
||||
|
||||
if(mediaInformation.Count > 0) MediaInformation = mediaInformation;
|
||||
}
|
||||
@@ -605,7 +610,7 @@ public partial class View
|
||||
if(removable && !sscMedia && testedMedia != null)
|
||||
{
|
||||
Core.TestedMedia.Report(testedMedia,
|
||||
out Dictionary<string, (Dictionary<string, string> Table, List<string> List)>
|
||||
out SortedSet<(string Header, Dictionary<string, string> Table, List<string> List)>
|
||||
mediaInformation);
|
||||
|
||||
if(mediaInformation.Count > 0) MediaInformation = mediaInformation;
|
||||
|
||||
@@ -36,14 +36,15 @@ namespace Aaru.Server.Core;
|
||||
|
||||
public static class SscTestedMedia
|
||||
{
|
||||
/// <summary>Takes the tested media from SCSI Streaming devices of a device report and prints it as a list of values</summary>
|
||||
/// <param name="mediaOneValue">List to put values on</param>
|
||||
/// <summary>Takes the tested media from SCSI Streaming devices of a device report and prints it as a sorted set of values</summary>
|
||||
/// <param name="testedMedia">List of tested media</param>
|
||||
public static void Report(IEnumerable<TestedSequentialMedia> testedMedia,
|
||||
out Dictionary<string, (Dictionary<string, string> Table, List<string> List)>
|
||||
out SortedSet<(string Header, Dictionary<string, string> Table, List<string> List)>
|
||||
mediaInformation)
|
||||
{
|
||||
mediaInformation = [];
|
||||
mediaInformation =
|
||||
new SortedSet<(string Header, Dictionary<string, string> Table, List<string> List
|
||||
)>(new MediaInfoComparer());
|
||||
|
||||
foreach(TestedSequentialMedia media in testedMedia)
|
||||
{
|
||||
@@ -54,7 +55,6 @@ public static class SscTestedMedia
|
||||
if(!string.IsNullOrWhiteSpace(media.MediumTypeName))
|
||||
{
|
||||
header = $"Information for medium named \"{media.MediumTypeName}\"";
|
||||
|
||||
if(media.MediumType.HasValue) table.Add("Medium type code", $"{media.MediumType:X2}h");
|
||||
}
|
||||
else if(media.MediumType.HasValue)
|
||||
@@ -62,8 +62,7 @@ public static class SscTestedMedia
|
||||
else
|
||||
header = "Information for unknown medium type";
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(media.Manufacturer))
|
||||
table.Add("Medium manufacturer", media.Manufacturer);
|
||||
if(!string.IsNullOrWhiteSpace(media.Manufacturer)) table.Add("Medium manufacturer", media.Manufacturer);
|
||||
|
||||
if(!string.IsNullOrWhiteSpace(media.Model)) table.Add("Medium model", media.Model);
|
||||
|
||||
@@ -73,7 +72,15 @@ public static class SscTestedMedia
|
||||
|
||||
if(media.MediaIsRecognized) list.Add("Drive recognizes this medium.");
|
||||
|
||||
mediaInformation.Add(header, (table, list));
|
||||
mediaInformation.Add((header, table, list));
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class
|
||||
MediaInfoComparer : IComparer<(string Header, Dictionary<string, string> Table, List<string> List)>
|
||||
{
|
||||
public int Compare((string Header, Dictionary<string, string> Table, List<string> List) x,
|
||||
(string Header, Dictionary<string, string> Table, List<string> List) y) =>
|
||||
string.Compare(x.Header, y.Header, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
@@ -38,9 +38,12 @@ public static class TestedMedia
|
||||
/// <param name="mediaInformation">List to put values on</param>
|
||||
/// <param name="testedMedias">List of tested media</param>
|
||||
public static void Report(List<CommonTypes.Metadata.TestedMedia> testedMedias,
|
||||
out Dictionary<string, (Dictionary<string, string> Table, List<string> List)> mediaInformation)
|
||||
out SortedSet<(string Header, Dictionary<string, string> Table, List<string> List)>
|
||||
mediaInformation)
|
||||
{
|
||||
mediaInformation = [];
|
||||
mediaInformation =
|
||||
new SortedSet<(string Header, Dictionary<string, string> Table, List<string> List
|
||||
)>(new MediaInfoComparer());
|
||||
|
||||
foreach(CommonTypes.Metadata.TestedMedia testedMedia in testedMedias)
|
||||
{
|
||||
@@ -395,7 +398,15 @@ public static class TestedMedia
|
||||
if(testedMedia.CanReadF1_06LeadOut == true)
|
||||
list.Add("Device can read Lead-Out from cache using F1h command with subcommand 06h");
|
||||
|
||||
mediaInformation.Add(header, (table, list));
|
||||
mediaInformation.Add((header, table, list));
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class
|
||||
MediaInfoComparer : IComparer<(string Header, Dictionary<string, string> Table, List<string> List)>
|
||||
{
|
||||
public int Compare((string Header, Dictionary<string, string> Table, List<string> List) x,
|
||||
(string Header, Dictionary<string, string> Table, List<string> List) y) =>
|
||||
string.Compare(x.Header, y.Header, StringComparison.Ordinal);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user