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