mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Add comparison for SCSI INQUIRY responses.
This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using DiscImageChef.CommonTypes.Metadata;
|
||||
using DiscImageChef.Decoders.ATA;
|
||||
using DiscImageChef.Decoders.SCSI;
|
||||
using DiscImageChef.Server.Models;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -150,5 +153,133 @@ namespace DiscImageChef.Server.Areas.Admin.Controllers
|
||||
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
public IActionResult Compare(int id, int rightId)
|
||||
{
|
||||
var model = new CompareModel
|
||||
{
|
||||
LeftId = id, RightId = rightId
|
||||
};
|
||||
|
||||
CommonTypes.Metadata.Scsi left = _context.Scsi.FirstOrDefault(l => l.Id == id);
|
||||
CommonTypes.Metadata.Scsi right = _context.Scsi.FirstOrDefault(r => r.Id == rightId);
|
||||
|
||||
if(left is null)
|
||||
{
|
||||
model.ErrorMessage = $"SCSI with id {id} has not been found";
|
||||
model.HasError = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(right is null)
|
||||
{
|
||||
model.ErrorMessage = $"SCSI with id {rightId} has not been found";
|
||||
model.HasError = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
Inquiry.SCSIInquiry? leftNullable = left.Inquiry;
|
||||
Inquiry.SCSIInquiry? rightNullable = right.Inquiry;
|
||||
model.ValueNames = new List<string>();
|
||||
model.LeftValues = new List<string>();
|
||||
model.RightValues = new List<string>();
|
||||
|
||||
if(!leftNullable.HasValue &&
|
||||
!rightNullable.HasValue)
|
||||
{
|
||||
model.AreEqual = true;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(leftNullable.HasValue &&
|
||||
!rightNullable.HasValue)
|
||||
{
|
||||
model.ValueNames.Add("Decoded");
|
||||
model.LeftValues.Add("decoded");
|
||||
model.RightValues.Add("null");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
if(!leftNullable.HasValue)
|
||||
{
|
||||
model.ValueNames.Add("Decoded");
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add("decoded");
|
||||
|
||||
return View(model);
|
||||
}
|
||||
|
||||
var leftValue = left.Inquiry.Value;
|
||||
var rightValue = right.Inquiry.Value;
|
||||
|
||||
foreach(FieldInfo fieldInfo in leftValue.GetType().GetFields())
|
||||
{
|
||||
object lv = fieldInfo.GetValue(leftValue);
|
||||
object rv = fieldInfo.GetValue(rightValue);
|
||||
|
||||
if(fieldInfo.FieldType.IsArray)
|
||||
{
|
||||
object[] la = lv as object[];
|
||||
object[] ra = rv as object[];
|
||||
|
||||
switch(la)
|
||||
{
|
||||
case null when ra is null: continue;
|
||||
case null:
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add("[]");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(ra is null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("[]");
|
||||
model.RightValues.Add("null");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(la.SequenceEqual(ra))
|
||||
continue;
|
||||
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("[]");
|
||||
model.RightValues.Add("[]");
|
||||
}
|
||||
else if(lv == null &&
|
||||
rv == null) { }
|
||||
else if(lv != null &&
|
||||
rv == null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add($"{lv}");
|
||||
model.RightValues.Add("null");
|
||||
}
|
||||
else if(lv == null)
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add("null");
|
||||
model.RightValues.Add($"{rv}");
|
||||
}
|
||||
else if(!lv.Equals(rv))
|
||||
|
||||
{
|
||||
model.ValueNames.Add(fieldInfo.Name);
|
||||
model.LeftValues.Add($"{lv}");
|
||||
model.RightValues.Add($"{rv}");
|
||||
}
|
||||
}
|
||||
|
||||
model.AreEqual = model.LeftValues.Count == 0 && model.RightValues.Count == 0;
|
||||
|
||||
return View(model);
|
||||
}
|
||||
}
|
||||
}
|
||||
84
DiscImageChef.Server/Areas/Admin/Views/Scsis/Compare.cshtml
Normal file
84
DiscImageChef.Server/Areas/Admin/Views/Scsis/Compare.cshtml
Normal file
@@ -0,0 +1,84 @@
|
||||
@model CompareModel
|
||||
|
||||
@{
|
||||
Layout = "~/Areas/Admin/Views/Shared/_Layout.cshtml";
|
||||
ViewBag.Title = "DiscImageChef";
|
||||
}
|
||||
@{
|
||||
// /***************************************************************************
|
||||
// The Disc Image Chef
|
||||
// ----------------------------------------------------------------------------
|
||||
//
|
||||
// Filename : Details.cshtml
|
||||
// Author(s) : Natalia Portillo <claunia@claunia.com>
|
||||
//
|
||||
// Component : DiscImageChef Server.
|
||||
//
|
||||
// --[ License ] --------------------------------------------------------------
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Lesser General Public License as
|
||||
// published by the Free Software Foundation; either version 2.1 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This library 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
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, see <http://www.gnu.org/licenses/>.
|
||||
//
|
||||
// ----------------------------------------------------------------------------
|
||||
// Copyright © 2011-2019 Natalia Portillo
|
||||
// ****************************************************************************/
|
||||
}
|
||||
<h2>Comparing SCSI INQUIRY ID @Model.LeftId with ID @Model.RightId</h2>
|
||||
@if (Model.AreEqual)
|
||||
{
|
||||
<p>No differences found.</p>
|
||||
return;
|
||||
}
|
||||
|
||||
@if (Model.HasError)
|
||||
{
|
||||
<p class="alert-info">@Model.ErrorMessage</p>
|
||||
return;
|
||||
}
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
Value name
|
||||
</th>
|
||||
<th>
|
||||
ID: @Model.LeftId
|
||||
</th>
|
||||
<th>
|
||||
ID: @Model.RightId
|
||||
</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@for (var i = 0; i < Model.ValueNames.Count; i++)
|
||||
{
|
||||
<tr>
|
||||
<td>
|
||||
@Model.ValueNames[i]
|
||||
</td>
|
||||
<td>
|
||||
@Model.LeftValues[i]
|
||||
</td>
|
||||
<td>
|
||||
@Model.RightValues[i]
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
</tbody>
|
||||
</table>
|
||||
<a asp-action="Index" class="btn btn-primary">Back to List</a>
|
||||
<a asp-action="Delete" asp-route-id="@Model.LeftId" class="btn btn-danger">Delete ID @Model.LeftId</a>
|
||||
<a asp-action="Delete" asp-route-id="@Model.RightId" class="btn btn-danger">Delete ID @Model.RightId</a>
|
||||
<a asp-action="ConsolidateWithIds" asp-route-masterId="@Model.LeftId" asp-route-slaveId="@Model.RightId" class="btn btn-secondary">Replace all dependencies from ID @Model.RightId with ID @Model.LeftId</a>
|
||||
<a asp-action="ConsolidateWithIds" asp-route-masterId="@Model.RightId" asp-route-slaveId="@Model.LeftId" class="btn btn-secondary">Replace all dependencies from ID @Model.LeftId with ID @Model.RightId</a>
|
||||
Reference in New Issue
Block a user