Agregado de NombreCategoria a los osSimulables
This commit is contained in:
parent
6e48539d2e
commit
091170b70d
|
@ -13,6 +13,7 @@ using System.Windows;
|
|||
using CtrEditor.Simulacion;
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using Xceed.Wpf.Toolkit.PropertyGrid;
|
||||
using CtrEditor.ObjetosSim.Extraccion_Datos;
|
||||
|
@ -87,6 +88,9 @@ namespace CtrEditor
|
|||
[ObservableProperty]
|
||||
public ObservableCollection<TipoSimulable> listaOsBase;
|
||||
|
||||
[ObservableProperty]
|
||||
public ObservableCollection<CategoriaNode> categoriasOsBase;
|
||||
|
||||
// Diccionario para almacenar datos expandidos de imágenes
|
||||
public Dictionary<string, Models.ImageData> _imageDataDictionary = new Dictionary<string, Models.ImageData>();
|
||||
|
||||
|
@ -371,6 +375,7 @@ namespace CtrEditor
|
|||
ObjetosSimulables = new ObservableCollection<osBase>();
|
||||
|
||||
ListaOsBase = new ObservableCollection<TipoSimulable>();
|
||||
CategoriasOsBase = new ObservableCollection<CategoriaNode>();
|
||||
|
||||
// Inicializa el PLCViewModel
|
||||
PLCViewModel = new PLCViewModel();
|
||||
|
@ -1029,12 +1034,41 @@ namespace CtrEditor
|
|||
.SelectMany(assembly => assembly.GetTypes())
|
||||
.Where(type => type.IsSubclassOf(baseType) && !type.IsAbstract && typeof(IosBase).IsAssignableFrom(type));
|
||||
|
||||
var categorias = new Dictionary<string, CategoriaNode>();
|
||||
|
||||
foreach (var type in types)
|
||||
{
|
||||
var methodInfo = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
string nombre = methodInfo != null ? methodInfo.Invoke(null, null)?.ToString() : "Nombre no encontrado";
|
||||
var methodInfoNombre = type.GetMethod("NombreClase", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
var methodInfoCategoria = type.GetMethod("NombreCategoria", BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);
|
||||
|
||||
string nombre = methodInfoNombre != null ? methodInfoNombre.Invoke(null, null)?.ToString() : "Nombre no encontrado";
|
||||
string categoria = methodInfoCategoria != null ? methodInfoCategoria.Invoke(null, null)?.ToString() : "Sin categoría";
|
||||
|
||||
ListaOsBase.Add(new TipoSimulable { Nombre = nombre, Tipo = type });
|
||||
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 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
|
||||
|
|
|
@ -104,15 +104,24 @@
|
|||
</ContextMenu>
|
||||
</ListBox.ContextMenu>
|
||||
</ListBox>
|
||||
<ListBox x:Name="ListaFunciones" Grid.Row="1" Margin="5" ItemsSource="{Binding ListaOsBase}"
|
||||
DisplayMemberPath="Nombre" SelectedItem="{Binding SelectedItem}">
|
||||
<i:Interaction.Triggers>
|
||||
<i:EventTrigger EventName="MouseDoubleClick">
|
||||
<i:InvokeCommandAction Command="{Binding ItemDoubleClickCommand}"
|
||||
CommandParameter="{Binding SelectedItem}" />
|
||||
</i:EventTrigger>
|
||||
</i:Interaction.Triggers>
|
||||
</ListBox>
|
||||
<TreeView x:Name="ListaFunciones" Grid.Row="1" Margin="5" ItemsSource="{Binding CategoriasOsBase}">
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate DataType="{x:Type local:CategoriaNode}" ItemsSource="{Binding Elementos}">
|
||||
<TextBlock Text="{Binding Nombre}" FontWeight="Bold" Foreground="DarkBlue"/>
|
||||
<HierarchicalDataTemplate.ItemTemplate>
|
||||
<DataTemplate DataType="{x:Type local:TipoSimulable}">
|
||||
<TextBlock Text="{Binding Nombre}" Margin="10,0,0,0">
|
||||
<TextBlock.InputBindings>
|
||||
<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}" />
|
||||
</Grid>
|
||||
|
|
|
@ -19,6 +19,11 @@ namespace CtrEditor.ObjetosSim
|
|||
return "Imagen Personalizada";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Decorativos";
|
||||
}
|
||||
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -31,6 +31,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Marco de Panel";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Decorativos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Placa de Texto";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Decorativos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Botella";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Dinamicos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -25,6 +25,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Botella con Cuello";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Dinamicos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -21,6 +21,11 @@ namespace CtrEditor.ObjetosSim
|
|||
return "Generador de Botellas";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Emuladores";
|
||||
}
|
||||
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -24,6 +24,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Llenadora";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Emuladores";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -18,6 +18,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Tanque";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Emuladores";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -22,6 +22,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Descarte";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Estaticos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -20,6 +20,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Guía";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Estaticos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -26,6 +26,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Transporte Curva 90°";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Estaticos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osTransporteCurvaGuias : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
private osBase Motor = null;
|
||||
|
||||
private simCurve Simulation_TransporteCurvaGuias;
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osTransporteGuias : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
private osBase Motor = null;
|
||||
|
||||
private simTransporte? SimGeometria;
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osTransporteGuiasUnion : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
private osBase _osMotorA = null;
|
||||
private osBase _osMotorB = null;
|
||||
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
|
|||
|
||||
public partial class osTransporteTTop : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
|
||||
private simTransporte SimGeometria;
|
||||
private osVMmotorSim Motor;
|
||||
|
|
|
@ -19,6 +19,7 @@ namespace CtrEditor.ObjetosSim
|
|||
|
||||
public partial class osTransporteTTopDualInverter : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
|
||||
private simTransporte SimGeometria;
|
||||
private osVMmotorSim MotorA;
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace CtrEditor.ObjetosSim
|
|||
|
||||
public partial class osVMmotorSim : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Estaticos";
|
||||
|
||||
// Otros datos y métodos relevantes para la simulación
|
||||
|
||||
|
|
|
@ -64,6 +64,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
|
||||
public partial class osBuscarCoincidencias : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Extraccion Datos";
|
||||
[JsonIgnore]
|
||||
public float offsetY;
|
||||
[JsonIgnore]
|
||||
|
|
|
@ -15,6 +15,7 @@ namespace CtrEditor.ObjetosSim.Extraccion_Datos
|
|||
|
||||
public partial class osExtraccionTag : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Extraccion Datos";
|
||||
public static string NombreClase()
|
||||
{
|
||||
return "Extractor de Tags";
|
||||
|
|
|
@ -20,6 +20,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Botón";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "SensoresComandos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
public partial class osEncoderMotor : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "SensoresComandos";
|
||||
private osBase Motor = null;
|
||||
|
||||
public static string NombreClase()
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
public partial class osEncoderMotorLineal : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "SensoresComandos";
|
||||
private osBase Motor = null;
|
||||
|
||||
public static string NombreClase()
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osGearEncoder : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "SensoresComandos";
|
||||
private osBase Motor = null;
|
||||
private Stopwatch Stopwatch = new Stopwatch();
|
||||
private double stopwatch_last = 0;
|
||||
|
|
|
@ -27,6 +27,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Fotocélula";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "SensoresComandos";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -13,6 +13,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osSensTemperatura : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "SensoresComandos";
|
||||
// Otros datos y métodos relevantes para la simulación
|
||||
|
||||
public static string NombreClase()
|
||||
|
|
|
@ -23,6 +23,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Tag Analógico";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "TagsSignals";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -24,6 +24,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Tag Digital";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "TagsSignals";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -27,6 +27,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Consenso Genérico";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "TagsSignals";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -16,6 +16,7 @@ namespace CtrEditor.ObjetosSim
|
|||
/// </summary>
|
||||
public partial class osTrace3 : osBase, IosBase
|
||||
{
|
||||
public static string NombreCategoria() => "Traces";
|
||||
private List<float> _series1 = new List<float>();
|
||||
private List<float> _series2 = new List<float>();
|
||||
private List<float> _series3 = new List<float>();
|
||||
|
|
|
@ -31,6 +31,11 @@ namespace CtrEditor.ObjetosSim
|
|||
{
|
||||
return "Trazador Simple";
|
||||
}
|
||||
|
||||
public static string NombreCategoria()
|
||||
{
|
||||
return "Traces";
|
||||
}
|
||||
private string nombre = NombreClase();
|
||||
|
||||
[property: Category("Identificación")]
|
||||
|
|
|
@ -28,6 +28,7 @@ namespace CtrEditor.ObjetosSim
|
|||
public interface IosBase
|
||||
{
|
||||
static abstract string NombreClase();
|
||||
static abstract string NombreCategoria();
|
||||
}
|
||||
|
||||
public interface IDataContainer
|
||||
|
|
|
@ -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 ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
Loading…
Reference in New Issue