Restructure Form1 into a sequential wizard (database -> import -> raw -> recursive component resolution -> completeness/STEP report), fix case-sensitivity bugs in codice/tipo_file lookups and a word-boundary gap in the assembly scanner that missed _D100-style sub-assembly references, and treat the distinta's general assembly as an ordinary CSV row (derived from the DBP_<codice>_<timestamp> filename) instead of special-casing it throughout. Also adds CadSearchGui.Tests (xUnit) covering the scanner, filename parsing, and the case-insensitive DB lookup behavior. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
36 lines
1.6 KiB
C#
36 lines
1.6 KiB
C#
using System.Text;
|
|
using System.Text.RegularExpressions;
|
|
|
|
namespace CadSearchGui;
|
|
|
|
/// <summary>
|
|
/// Estrae i codici componente referenziati dentro un file .asm Pro-E/Creo.
|
|
/// Il formato è per lo più binario, ma i codici dei sotto-componenti compaiono
|
|
/// come stringhe ASCII leggibili al suo interno: si scansiona il file come testo
|
|
/// cercando pattern che assomigliano a un codice (stesso stile usato nei nomi file,
|
|
/// vedi Indexer.FilenameRegex) e si lascia poi al chiamante il compito di verificarli
|
|
/// contro l'indice DB, che scarta automaticamente i falsi positivi (numeri che non
|
|
/// corrispondono a nessun codice reale).
|
|
///
|
|
/// Verificato su un caso reale confrontando con un report BOM generato da Creo: i
|
|
/// riferimenti veri compaiono più volte nel file (una volta per feature/placement),
|
|
/// mentre il rumore binario casuale che assomiglia a un codice compare quasi sempre
|
|
/// una sola volta. Si scartano quindi i candidati con una sola occorrenza.
|
|
/// </summary>
|
|
static class AssemblyComponentScanner
|
|
{
|
|
private static readonly Regex CodiceRegex = new(@"\b\d{8,12}(?:_[A-Za-z]\d{2,4}|[A-Za-z]{0,2})\b", RegexOptions.Compiled);
|
|
private const int OccorrenzeMinime = 2;
|
|
|
|
public static HashSet<string> EstraiCodiciReferenziati(string percorsoAsm)
|
|
{
|
|
var testo = Encoding.Latin1.GetString(File.ReadAllBytes(percorsoAsm));
|
|
var occorrenze = new Dictionary<string, int>();
|
|
foreach (Match m in CodiceRegex.Matches(testo))
|
|
{
|
|
occorrenze[m.Value] = occorrenze.GetValueOrDefault(m.Value) + 1;
|
|
}
|
|
return occorrenze.Where(kv => kv.Value >= OccorrenzeMinime).Select(kv => kv.Key).ToHashSet();
|
|
}
|
|
}
|