Agregado de NombreCategoria a los osSimulables

This commit is contained in:
Miguel 2025-09-04 12:26:24 +02:00
parent 6e48539d2e
commit 091170b70d
36 changed files with 308 additions and 12 deletions

View File

@ -13,6 +13,7 @@ using System.Windows;
using CtrEditor.Simulacion; using CtrEditor.Simulacion;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using System.Linq;
using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.ComponentModel;
using Xceed.Wpf.Toolkit.PropertyGrid; using Xceed.Wpf.Toolkit.PropertyGrid;
using CtrEditor.ObjetosSim.Extraccion_Datos; using CtrEditor.ObjetosSim.Extraccion_Datos;
@ -87,6 +88,9 @@ namespace CtrEditor
[ObservableProperty] [ObservableProperty]
public ObservableCollection<TipoSimulable> listaOsBase; public ObservableCollection<TipoSimulable> listaOsBase;
[ObservableProperty]
public ObservableCollection<CategoriaNode> categoriasOsBase;
// Diccionario para almacenar datos expandidos de imágenes // Diccionario para almacenar datos expandidos de imágenes
public Dictionary<string, Models.ImageData> _imageDataDictionary = new Dictionary<string, Models.ImageData>(); public Dictionary<string, Models.ImageData> _imageDataDictionary = new Dictionary<string, Models.ImageData>();
@ -371,6 +375,7 @@ namespace CtrEditor
ObjetosSimulables = new ObservableCollection<osBase>(); ObjetosSimulables = new ObservableCollection<osBase>();
ListaOsBase = new ObservableCollection<TipoSimulable>(); ListaOsBase = new ObservableCollection<TipoSimulable>();
CategoriasOsBase = new ObservableCollection<CategoriaNode>();
// Inicializa el PLCViewModel // Inicializa el PLCViewModel
PLCViewModel = new PLCViewModel(); PLCViewModel = new PLCViewModel();
@ -1029,12 +1034,41 @@ namespace CtrEditor
.SelectMany(assembly => assembly.GetTypes()) .SelectMany(assembly => assembly.GetTypes())
.Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract && typeof(IosBase).IsAssignableFrom(type)); .Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract && typeof(IosBase).IsAssignableFrom(type));
var categorias = new Dictionary<string, CategoriaNode>();
foreach (var type in types) foreach (var type in types)
{ {
var methodInfo = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy); var methodInfoNombre = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
string nombre = methodInfo != null ? methodInfo.Invoke(null, null)?.ToString() : "Nombre no encontrado"; var methodInfoCategoria = type.GetMethod("NombreCategoria", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
ListaOsBase.Add(new TipoSimulable { Nombre = nombre, Tipo = type }); string nombre = methodInfoNombre != null ? methodInfoNombre.Invoke(null, null)?.ToString() : "Nombre no encontrado";
string categoria = methodInfoCategoria != null ? methodInfoCategoria.Invoke(null, null)?.ToString() : "Sin categoría";
var tipoSimulable = new TipoSimulable { Nombre = nombre, Tipo = type, Categoria = categoria };
ListaOsBase.Add(tipoSimulable);
// Crear o obtener el nodo de categoría
if (!categorias.ContainsKey(categoria))
{
categorias[categoria] = new CategoriaNode(categoria);
}
// Agregar el tipo simulable a la categoría correspondiente
categorias[categoria].Elementos.Add(tipoSimulable);
}
// Ordenar categorías y sus elementos
foreach (var categoria in categorias.Values.OrderBy(c => c.Nombre))
{
// Ordenar elementos dentro de cada categoría por nombre
var elementosOrdenados = categoria.Elementos.OrderBy(e => e.Nombre).ToList();
categoria.Elementos.Clear();
foreach (var elemento in elementosOrdenados)
{
categoria.Elementos.Add(elemento);
}
CategoriasOsBase.Add(categoria);
} }
} }
@ -1531,6 +1565,25 @@ namespace CtrEditor
{ {
public string? Nombre { get; set; } public string? Nombre { get; set; }
public Type? Tipo { get; set; } public Type? Tipo { get; set; }
public string? Categoria { get; set; }
}
public partial class CategoriaNode : ObservableObject
{
[ObservableProperty]
private string nombre;
[ObservableProperty]
private ObservableCollection<TipoSimulable> elementos;
[ObservableProperty]
private bool isExpanded = true;
public CategoriaNode(string nombre)
{
this.nombre = nombre;
elementos = new ObservableCollection<TipoSimulable>();
}
} }
public class TickSimulacionEventArgs : EventArgs public class TickSimulacionEventArgs : EventArgs

View File

@ -104,15 +104,24 @@
</ContextMenu> </ContextMenu>
</ListBox.ContextMenu> </ListBox.ContextMenu>
</ListBox> </ListBox>
<ListBox x:Name="ListaFunciones" Grid.Row="1" Margin="5" ItemsSource="{Binding ListaOsBase}" <TreeView x:Name="ListaFunciones" Grid.Row="1" Margin="5" ItemsSource="{Binding CategoriasOsBase}">
DisplayMemberPath="Nombre" SelectedItem="{Binding SelectedItem}"> <TreeView.ItemTemplate>
<i:Interaction.Triggers> <HierarchicalDataTemplate DataType="{x:Type local:CategoriaNode}" ItemsSource="{Binding Elementos}">
<i:EventTrigger EventName="MouseDoubleClick"> <TextBlock Text="{Binding Nombre}" FontWeight="Bold" Foreground="DarkBlue"/>
<i:InvokeCommandAction Command="{Binding ItemDoubleClickCommand}" <HierarchicalDataTemplate.ItemTemplate>
CommandParameter="{Binding SelectedItem}" /> <DataTemplate DataType="{x:Type local:TipoSimulable}">
</i:EventTrigger> <TextBlock Text="{Binding Nombre}" Margin="10,0,0,0">
</i:Interaction.Triggers> <TextBlock.InputBindings>
</ListBox> <MouseBinding MouseAction="LeftDoubleClick"
Command="{Binding DataContext.ItemDoubleClickCommand, RelativeSource={RelativeSource AncestorType=TreeView}}"
CommandParameter="{Binding}" />
</TextBlock.InputBindings>
</TextBlock>
</DataTemplate>
</HierarchicalDataTemplate.ItemTemplate>
</HierarchicalDataTemplate>
</TreeView.ItemTemplate>
</TreeView>
<Siemens:PLCControl x:Name="PLCSim" Grid.Row="2" Margin="5" DataContext="{Binding PLCViewModel}" /> <Siemens:PLCControl x:Name="PLCSim" Grid.Row="2" Margin="5" DataContext="{Binding PLCViewModel}" />
</Grid> </Grid>

View File

@ -19,6 +19,11 @@ namespace CtrEditor.ObjetosSim
return "Imagen Personalizada"; return "Imagen Personalizada";
} }
public static string NombreCategoria()
{
return "Decorativos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -31,6 +31,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Marco de Panel"; return "Marco de Panel";
} }
public static string NombreCategoria()
{
return "Decorativos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Placa de Texto"; return "Placa de Texto";
} }
public static string NombreCategoria()
{
return "Decorativos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Botella"; return "Botella";
} }
public static string NombreCategoria()
{
return "Dinamicos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Botella con Cuello"; return "Botella con Cuello";
} }
public static string NombreCategoria()
{
return "Dinamicos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -21,6 +21,11 @@ namespace CtrEditor.ObjetosSim
return "Generador de Botellas"; return "Generador de Botellas";
} }
public static string NombreCategoria()
{
return "Emuladores";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -24,6 +24,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Llenadora"; return "Llenadora";
} }
public static string NombreCategoria()
{
return "Emuladores";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -18,6 +18,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Tanque"; return "Tanque";
} }
public static string NombreCategoria()
{
return "Emuladores";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -22,6 +22,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Descarte"; return "Descarte";
} }
public static string NombreCategoria()
{
return "Estaticos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -20,6 +20,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Guía"; return "Guía";
} }
public static string NombreCategoria()
{
return "Estaticos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -26,6 +26,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Transporte Curva 90°"; return "Transporte Curva 90°";
} }
public static string NombreCategoria()
{
return "Estaticos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -17,6 +17,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTransporteCurvaGuias : osBase, IosBase public partial class osTransporteCurvaGuias : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
private osBase Motor = null; private osBase Motor = null;
private simCurve Simulation_TransporteCurvaGuias; private simCurve Simulation_TransporteCurvaGuias;

View File

@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTransporteGuias : osBase, IosBase public partial class osTransporteGuias : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
private osBase Motor = null; private osBase Motor = null;
private simTransporte? SimGeometria; private simTransporte? SimGeometria;

View File

@ -17,6 +17,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTransporteGuiasUnion : osBase, IosBase public partial class osTransporteGuiasUnion : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
private osBase _osMotorA = null; private osBase _osMotorA = null;
private osBase _osMotorB = null; private osBase _osMotorB = null;

View File

@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
public partial class osTransporteTTop : osBase, IosBase public partial class osTransporteTTop : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
private simTransporte SimGeometria; private simTransporte SimGeometria;
private osVMmotorSim Motor; private osVMmotorSim Motor;

View File

@ -19,6 +19,7 @@ namespace CtrEditor.ObjetosSim
public partial class osTransporteTTopDualInverter : osBase, IosBase public partial class osTransporteTTopDualInverter : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
private simTransporte SimGeometria; private simTransporte SimGeometria;
private osVMmotorSim MotorA; private osVMmotorSim MotorA;

View File

@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
public partial class osVMmotorSim : osBase, IosBase public partial class osVMmotorSim : osBase, IosBase
{ {
public static string NombreCategoria() => "Estaticos";
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación

View File

@ -64,6 +64,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
public partial class osBuscarCoincidencias : osBase, IosBase public partial class osBuscarCoincidencias : osBase, IosBase
{ {
public static string NombreCategoria() => "Extraccion Datos";
[JsonIgnore] [JsonIgnore]
public float offsetY; public float offsetY;
[JsonIgnore] [JsonIgnore]

View File

@ -15,6 +15,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
public partial class osExtraccionTag : osBase, IosBase public partial class osExtraccionTag : osBase, IosBase
{ {
public static string NombreCategoria() => "Extraccion Datos";
public static string NombreClase() public static string NombreClase()
{ {
return "Extractor de Tags"; return "Extractor de Tags";

View File

@ -20,6 +20,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Botón"; return "Botón";
} }
public static string NombreCategoria()
{
return "SensoresComandos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
{ {
public partial class osEncoderMotor : osBase, IosBase public partial class osEncoderMotor : osBase, IosBase
{ {
public static string NombreCategoria() => "SensoresComandos";
private osBase Motor = null; private osBase Motor = null;
public static string NombreClase() public static string NombreClase()

View File

@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
{ {
public partial class osEncoderMotorLineal : osBase, IosBase public partial class osEncoderMotorLineal : osBase, IosBase
{ {
public static string NombreCategoria() => "SensoresComandos";
private osBase Motor = null; private osBase Motor = null;
public static string NombreClase() public static string NombreClase()

View File

@ -16,6 +16,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osGearEncoder : osBase, IosBase public partial class osGearEncoder : osBase, IosBase
{ {
public static string NombreCategoria() => "SensoresComandos";
private osBase Motor = null; private osBase Motor = null;
private Stopwatch Stopwatch = new Stopwatch(); private Stopwatch Stopwatch = new Stopwatch();
private double stopwatch_last = 0; private double stopwatch_last = 0;

View File

@ -27,6 +27,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Fotocélula"; return "Fotocélula";
} }
public static string NombreCategoria()
{
return "SensoresComandos";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osSensTemperatura : osBase, IosBase public partial class osSensTemperatura : osBase, IosBase
{ {
public static string NombreCategoria() => "SensoresComandos";
// Otros datos y métodos relevantes para la simulación // Otros datos y métodos relevantes para la simulación
public static string NombreClase() public static string NombreClase()

View File

@ -23,6 +23,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Tag Analógico"; return "Tag Analógico";
} }
public static string NombreCategoria()
{
return "TagsSignals";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -24,6 +24,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Tag Digital"; return "Tag Digital";
} }
public static string NombreCategoria()
{
return "TagsSignals";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -27,6 +27,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Consenso Genérico"; return "Consenso Genérico";
} }
public static string NombreCategoria()
{
return "TagsSignals";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -16,6 +16,7 @@ namespace CtrEditor.ObjetosSim
/// </summary> /// </summary>
public partial class osTrace3 : osBase, IosBase public partial class osTrace3 : osBase, IosBase
{ {
public static string NombreCategoria() => "Traces";
private List<float> _series1 = new List<float>(); private List<float> _series1 = new List<float>();
private List<float> _series2 = new List<float>(); private List<float> _series2 = new List<float>();
private List<float> _series3 = new List<float>(); private List<float> _series3 = new List<float>();

View File

@ -31,6 +31,11 @@ namespace CtrEditor.ObjetosSim
{ {
return "Trazador Simple"; return "Trazador Simple";
} }
public static string NombreCategoria()
{
return "Traces";
}
private string nombre = NombreClase(); private string nombre = NombreClase();
[property: Category("Identificación")] [property: Category("Identificación")]

View File

@ -28,6 +28,7 @@ namespace CtrEditor.ObjetosSim
public interface IosBase public interface IosBase
{ {
static abstract string NombreClase(); static abstract string NombreClase();
static abstract string NombreCategoria();
} }
public interface IDataContainer public interface IDataContainer

64
add_categoria_method.ps1 Normal file
View File

@ -0,0 +1,64 @@
# Script para agregar método NombreCategoria a archivos de osBase
$files = @(
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Decorativos\ucCustomImage.xaml.cs"; Category="Decorativos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Decorativos\ucFramePlate.xaml.cs"; Category="Decorativos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Decorativos\ucTextPlate.xaml.cs"; Category="Decorativos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucDescarte.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucGuia.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucTransporteCurvaGuias.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucTransporteGuias.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucTransporteGuiasUnion.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucTransporteTTop.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucTransporteTTopDualInverter.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Estaticos\ucVMmotorSim.xaml.cs"; Category="Estaticos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Extraccion Datos\ucBuscarCoincidencias.xaml.cs"; Category="Extraccion Datos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Extraccion Datos\ucExtraccionTag.xaml.cs"; Category="Extraccion Datos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucBoton.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucEncoderMotor.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucEncoderMotorLineal.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucGearEncoder.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucPhotocell.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\SensoresComandos\ucSensTemperatura.xaml.cs"; Category="SensoresComandos"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\TagsSignals\ucAnalogTag.xaml.cs"; Category="TagsSignals"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\TagsSignals\ucBoolTag.xaml.cs"; Category="TagsSignals"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\TagsSignals\ucConsensGeneric.xaml.cs"; Category="TagsSignals"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Traces\ucTrace3.xaml.cs"; Category="Traces"},
@{Path="d:\Proyectos\VisualStudio\CtrEditor\ObjetosSim\Traces\ucTraceSimple.xaml.cs"; Category="Traces"}
)
foreach ($file in $files) {
if (Test-Path $file.Path) {
Write-Host "Processing: $($file.Path)"
Write-Host "Category: $($file.Category)"
# Buscar la línea que contiene "public static string NombreClase()"
$content = Get-Content $file.Path
$lineIndex = -1
for ($i = 0; $i -lt $content.Length; $i++) {
if ($content[$i].Trim() -eq "public static string NombreClase()") {
$lineIndex = $i
break
}
}
if ($lineIndex -ne -1) {
# Encontrar el final del método NombreClase (la línea que contiene "}")
$endIndex = -1
for ($i = $lineIndex + 1; $i -lt $content.Length; $i++) {
if ($content[$i].Trim() -eq "}") {
$endIndex = $i
break
}
}
if ($endIndex -ne -1) {
Write-Host "Found NombreClase method at lines $($lineIndex + 1) to $($endIndex + 1)"
Write-Host "Method body:"
for ($i = $lineIndex; $i -le $endIndex; $i++) {
Write-Host " $($content[$i])"
}
Write-Host ""
}
}
}
}

32
fix_file.ps1 Normal file
View File

@ -0,0 +1,32 @@
param(
[string]$FilePath,
[string]$Category
)
if (-not (Test-Path $FilePath)) {
Write-Error "File not found: $FilePath"
return
}
$content = Get-Content $FilePath -Raw
if ($content -match '(\s+public static string NombreClase\(\)\s+\{\s+return ".*?";\s+\})') {
$nombreclaseMethod = $matches[1]
$newMethod = "$nombreclaseMethod
public static string NombreCategoria()
{
return `"$Category`";
}"
$newContent = $content -replace [regex]::Escape($nombreclaseMethod), $newMethod
if ($content -notmatch 'public static string NombreCategoria\(\)') {
Set-Content $FilePath -Value $newContent -NoNewline
Write-Host "Updated: $FilePath"
} else {
Write-Host "Skipped (already has NombreCategoria): $FilePath"
}
} else {
Write-Warning "Could not find NombreClase method in: $FilePath"
}

39
update_single_file.ps1 Normal file
View File

@ -0,0 +1,39 @@
# Script para agregar automáticamente el método NombreCategoria
param(
[string]$FilePath,
[string]$Category
)
if (-not (Test-Path $FilePath)) {
Write-Error "File not found: $FilePath"
return
}
$content = Get-Content $FilePath -Raw
# Buscar el patrón del método NombreClase
$pattern = '(\s+public static string NombreClase\(\)\s+\{\s+return ".*?";\s+\})'
if ($content -match $pattern) {
$nombreclaseMethod = $matches[1]
$newMethod = @"
$nombreclaseMethod
public static string NombreCategoria()
{
return "$Category";
}
"@
$newContent = $content -replace [regex]::Escape($nombreclaseMethod), $newMethod
# Verificar que no ya existe el método NombreCategoria
if ($content -notmatch 'public static string NombreCategoria\(\)') {
Set-Content $FilePath -Value $newContent -NoNewline
Write-Host "✓ Updated: $FilePath"
} else {
Write-Host "- Skipped (already has NombreCategoria): $FilePath"
}
} else {
Write-Warning "Could not find NombreClase method in: $FilePath"
}