feat: Geutebruck GeViScope/GeViSoft Action Mapping System - MVP

This MVP release provides a complete full-stack solution for managing action mappings
in Geutebruck's GeViScope and GeViSoft video surveillance systems.

## Features

### Flutter Web Application (Port 8081)
- Modern, responsive UI for managing action mappings
- Action picker dialog with full parameter configuration
- Support for both GSC (GeViScope) and G-Core server actions
- Consistent UI for input and output actions with edit/delete capabilities
- Real-time action mapping creation, editing, and deletion
- Server categorization (GSC: prefix for GeViScope, G-Core: prefix for G-Core servers)

### FastAPI REST Backend (Port 8000)
- RESTful API for action mapping CRUD operations
- Action template service with comprehensive action catalog (247 actions)
- Server management (G-Core and GeViScope servers)
- Configuration tree reading and writing
- JWT authentication with role-based access control
- PostgreSQL database integration

### C# SDK Bridge (gRPC, Port 50051)
- Native integration with GeViSoft SDK (GeViProcAPINET_4_0.dll)
- Action mapping creation with correct binary format
- Support for GSC and G-Core action types
- Proper Camera parameter inclusion in action strings (fixes CrossSwitch bug)
- Action ID lookup table with server-specific action IDs
- Configuration reading/writing via SetupClient

## Bug Fixes
- **CrossSwitch Bug**: GSC and G-Core actions now correctly display camera/PTZ head parameters in GeViSet
- Action strings now include Camera parameter: `@ PanLeft (Comment: "", Camera: 101028)`
- Proper filter flags and VideoInput=0 for action mappings
- Correct action ID assignment (4198 for GSC, 9294 for G-Core PanLeft)

## Technical Stack
- **Frontend**: Flutter Web, Dart, Dio HTTP client
- **Backend**: Python FastAPI, PostgreSQL, Redis
- **SDK Bridge**: C# .NET 8.0, gRPC, GeViSoft SDK
- **Authentication**: JWT tokens
- **Configuration**: GeViSoft .set files (binary format)

## Credentials
- GeViSoft/GeViScope: username=sysadmin, password=masterkey
- Default admin: username=admin, password=admin123

## Deployment
All services run on localhost:
- Flutter Web: http://localhost:8081
- FastAPI: http://localhost:8000
- SDK Bridge gRPC: localhost:50051
- GeViServer: localhost (default port)

Generated with Claude Code (https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Administrator
2025-12-31 18:10:54 +01:00
commit 14893e62a5
4189 changed files with 1395076 additions and 0 deletions

View File

@@ -0,0 +1,74 @@
using System;
using System.IO;
using System.Text.Json;
using GeViSetEditor.Core.Parsers;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Analyze binary structure to understand configuration format
/// </summary>
public static class AnalyzeStructureCommand
{
public static void Execute(string inputPath, string? outputReportPath = null)
{
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
// Read file
byte[] data = File.ReadAllBytes(inputPath);
Console.WriteLine($"Analyzing: {inputPath}");
Console.WriteLine($"File size: {data.Length:N0} bytes");
// Run analysis
var analyzer = new AdvancedBinaryAnalyzer();
var report = analyzer.Analyze(data);
// Show summary
Console.WriteLine("\n=== Analysis Summary ===");
Console.WriteLine($"Header: '{report.Header}'");
Console.WriteLine($"Header ends at: {report.HeaderEndOffset} (0x{report.HeaderEndOffset:X})");
Console.WriteLine($"Sections identified: {report.Sections.Count}");
Console.WriteLine("\n=== Markers Found ===");
foreach (var marker in report.Markers)
{
Console.WriteLine($"{marker.Key}: {marker.Value.Count} occurrences");
}
Console.WriteLine("\n=== Data Type Counts ===");
foreach (var type in report.DataTypeCounts)
{
Console.WriteLine($"{type.Key}: {type.Value}");
}
// Export detailed report if requested
if (!string.IsNullOrEmpty(outputReportPath))
{
var options = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
string json = JsonSerializer.Serialize(report, options);
File.WriteAllText(outputReportPath, json);
Console.WriteLine($"\nDetailed report saved to: {outputReportPath}");
}
Console.WriteLine("\n✓ Analysis complete!");
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,92 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using GeViSetEditor.Core.Parsers;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Parse ALL configuration data comprehensively
/// </summary>
public static class ComprehensiveParseCommand
{
public static void Execute(string inputPath, string? outputJsonPath = null)
{
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
// Read file
byte[] data = File.ReadAllBytes(inputPath);
Console.WriteLine($"Input: {inputPath}");
Console.WriteLine($"Size: {data.Length:N0} bytes");
// Parse with comprehensive parser
var parser = new ComprehensiveConfigParser();
var config = parser.Parse(data);
// Show sample properties
Console.WriteLine($"\n=== Sample Properties (first 20) ===");
foreach (var prop in config.Properties.Take(20))
{
string valueStr = prop.Value?.ToString() ?? "null";
if (valueStr.Length > 50)
valueStr = valueStr.Substring(0, 47) + "...";
Console.WriteLine($" {prop.Name} = {valueStr} ({prop.ValueType})");
}
if (config.Properties.Count() > 20)
Console.WriteLine($" ... and {config.Properties.Count() - 20} more properties");
// Show Rules sections
Console.WriteLine($"\n=== Rules Sections (first 5) ===");
foreach (var rules in config.RulesSections.Take(5))
{
if (rules.Value is List<string> actions)
{
Console.WriteLine($"\nRules at offset {rules.StartOffset}:");
Console.WriteLine($" Actions: {actions.Count}");
foreach (var action in actions.Take(3))
{
Console.WriteLine($" - {action}");
}
if (actions.Count > 3)
Console.WriteLine($" ... and {actions.Count - 3} more actions");
}
}
// Export to JSON if requested
if (!string.IsNullOrEmpty(outputJsonPath))
{
Console.WriteLine($"\n=== Exporting to JSON ===");
var options = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
string json = JsonSerializer.Serialize(config, options);
File.WriteAllText(outputJsonPath, json);
Console.WriteLine($"JSON written to: {outputJsonPath}");
Console.WriteLine($"JSON size: {json.Length:N0} characters ({json.Length / 1024:N0} KB)");
}
Console.WriteLine("\n✓ Comprehensive parsing complete!");
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,142 @@
using System;
using System.IO;
using System.Linq;
using System.Text.Json;
using System.Text.Json.Serialization;
using GeViSetEditor.Core.Models;
using GeViSetEditor.Core.Parsers;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Parse full configuration structure and export to JSON
/// </summary>
public static class EnhancedParseCommand
{
public static void Execute(string inputPath, string? outputJsonPath = null)
{
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
// Read file
byte[] data = File.ReadAllBytes(inputPath);
// Parse with enhanced parser
var parser = new EnhancedSetFileParser();
var setFile = parser.Parse(data);
// Display results
Console.WriteLine("\n=== Full Configuration Structure ===");
Console.WriteLine($"File: {Path.GetFileName(inputPath)}");
Console.WriteLine($"Size: {setFile.FileSize:N0} bytes");
Console.WriteLine($"Header: '{setFile.Header}'\n");
// Show statistics
var stats = setFile.Statistics;
Console.WriteLine("=== Statistics ===");
Console.WriteLine($"Configuration Items: {stats.TotalConfigItems}");
Console.WriteLine($"Action Mappings: {stats.TotalActionMappings}");
Console.WriteLine($"Section Names: {stats.TotalSectionNames}");
Console.WriteLine($"Total Actions: {stats.TotalActions}");
if (stats.ConfigItemsByType.Count > 0)
{
Console.WriteLine("\nConfig Items by Type:");
foreach (var type in stats.ConfigItemsByType.OrderByDescending(kv => kv.Value))
{
Console.WriteLine($" {type.Key}: {type.Value}");
}
}
if (stats.ActionsPerMapping.Count > 0)
{
Console.WriteLine("\nActions per Mapping:");
foreach (var group in stats.ActionsPerMapping.OrderBy(kv => kv.Key))
{
Console.WriteLine($" {group.Key} actions: {group.Value} mappings");
}
}
// Show sample config items
if (setFile.ConfigItems.Count > 0)
{
Console.WriteLine("\n=== Sample Config Items (first 10) ===");
foreach (var item in setFile.ConfigItems.Take(10))
{
string valueStr = item.Value?.ToString() ?? "null";
if (valueStr.Length > 50)
valueStr = valueStr.Substring(0, 47) + "...";
Console.WriteLine($" {item.Key} = {valueStr} ({item.ValueType})");
}
if (setFile.ConfigItems.Count > 10)
Console.WriteLine($" ... and {setFile.ConfigItems.Count - 10} more");
}
// Show sample section names
if (setFile.SectionNames.Count > 0)
{
Console.WriteLine("\n=== Section Names (top 20) ===");
var topSections = setFile.SectionNames
.GroupBy(s => s.Name)
.OrderByDescending(g => g.Count())
.Take(20);
foreach (var group in topSections)
{
Console.WriteLine($" {group.Key} ({group.Count()} occurrences)");
}
}
// Show sample action mappings
if (setFile.ActionMappings.Count > 0)
{
Console.WriteLine("\n=== Sample Action Mappings (first 5) ===");
foreach (var mapping in setFile.ActionMappings.Take(5))
{
Console.WriteLine($"\nMapping at offset {mapping.FileOffset}:");
Console.WriteLine($" Actions ({mapping.Actions.Count}):");
foreach (var action in mapping.Actions)
{
Console.WriteLine($" - {action}");
}
}
if (setFile.ActionMappings.Count > 5)
Console.WriteLine($"\n ... and {setFile.ActionMappings.Count - 5} more mappings");
}
// Export to JSON if requested
if (!string.IsNullOrEmpty(outputJsonPath))
{
Console.WriteLine($"\n=== Exporting to JSON ===");
var options = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
string json = JsonSerializer.Serialize(setFile, options);
File.WriteAllText(outputJsonPath, json);
Console.WriteLine($"JSON written to: {outputJsonPath}");
Console.WriteLine($"JSON size: {json.Length:N0} characters ({json.Length / 1024:N0} KB)");
}
Console.WriteLine("\n✓ Parsing complete!");
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,136 @@
using System;
using System.IO;
using System.Text.Json;
using System.Text.Json.Serialization;
using GeViSetEditor.Core.Models;
using GeViSetEditor.Core.Parsers;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Export .set file to JSON format (action mappings + metadata)
/// Binary data is preserved for round-trip conversion
/// </summary>
public static class ExportJsonCommand
{
public static void Execute(string inputPath, string outputJsonPath)
{
Console.WriteLine("=== Export to JSON ===\n");
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
// Parse with safe parser
byte[] data = File.ReadAllBytes(inputPath);
var parser = new SafeSetFileParser();
var setFile = parser.Parse(data);
Console.WriteLine($"\nFile: {inputPath}");
Console.WriteLine($"Size: {setFile.FileSize:N0} bytes");
Console.WriteLine($"Header: '{setFile.Header}'");
Console.WriteLine($"Action Mappings: {setFile.ActionMappings.Count}");
// Create JSON-friendly export model
var exportModel = new SetFileJsonExport
{
Version = "1.0",
SourceFile = Path.GetFileName(inputPath),
FileSize = setFile.FileSize,
Header = setFile.Header,
ExportDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
ActionMappings = setFile.ActionMappings.Select((m, index) => new ActionMappingJson
{
Id = index + 1,
FileOffset = m.FileOffset,
RulesMarkerOffset = m.RulesMarkerOffset,
Actions = m.Actions.ToList(),
TriggerConditions = m.TriggerConditions.ToDictionary(kv => kv.Key, kv => kv.Value)
}).ToList()
};
// Serialize to JSON
var options = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull,
Encoder = System.Text.Encodings.Web.JavaScriptEncoder.UnsafeRelaxedJsonEscaping
};
string json = JsonSerializer.Serialize(exportModel, options);
// Write to file
File.WriteAllText(outputJsonPath, json);
Console.WriteLine($"\n✓ JSON exported successfully!");
Console.WriteLine($"Output: {outputJsonPath}");
Console.WriteLine($"JSON size: {json.Length:N0} characters ({json.Length / 1024:N0} KB)");
// Show statistics
Console.WriteLine($"\n=== Statistics ===");
Console.WriteLine($"Total mappings: {exportModel.ActionMappings.Count}");
Console.WriteLine($"Total actions: {exportModel.ActionMappings.Sum(m => m.Actions.Count)}");
var actionsPerMapping = exportModel.ActionMappings.GroupBy(m => m.Actions.Count);
Console.WriteLine($"\nActions per mapping:");
foreach (var group in actionsPerMapping.OrderBy(g => g.Key))
{
Console.WriteLine($" {group.Key} actions: {group.Count()} mappings");
}
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
}
/// <summary>
/// JSON export model (without binary data)
/// </summary>
public class SetFileJsonExport
{
[JsonPropertyName("version")]
public string Version { get; set; }
[JsonPropertyName("sourceFile")]
public string SourceFile { get; set; }
[JsonPropertyName("exportDate")]
public string ExportDate { get; set; }
[JsonPropertyName("fileSize")]
public int FileSize { get; set; }
[JsonPropertyName("header")]
public string Header { get; set; }
[JsonPropertyName("actionMappings")]
public List<ActionMappingJson> ActionMappings { get; set; } = new();
}
public class ActionMappingJson
{
[JsonPropertyName("id")]
public int Id { get; set; }
[JsonPropertyName("fileOffset")]
public int FileOffset { get; set; }
[JsonPropertyName("rulesMarkerOffset")]
public int RulesMarkerOffset { get; set; }
[JsonPropertyName("actions")]
public List<string> Actions { get; set; } = new();
[JsonPropertyName("triggerConditions")]
public Dictionary<string, object> TriggerConditions { get; set; } = new();
}
}

View File

@@ -0,0 +1,249 @@
using System;
using System.IO;
using System.Linq;
using GeViSetEditor.Core.Parsers;
using GeViSetEditor.Core.Models;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Test modification capabilities: edit/add/delete configuration nodes
/// </summary>
public static class ModifyConfigCommand
{
public static void Execute(string inputPath, string outputPath = null)
{
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
Console.WriteLine("=== Configuration Modification Test ===\n");
// Read and parse original file
byte[] originalData = File.ReadAllBytes(inputPath);
Console.WriteLine($"Input: {inputPath}");
Console.WriteLine($"Original size: {originalData.Length:N0} bytes\n");
var parser = new ComprehensiveConfigParser();
var config = parser.Parse(originalData);
Console.WriteLine($"Parsed {config.Statistics.TotalNodes:N0} nodes\n");
// Show original state
Console.WriteLine("=== Original Configuration (sample) ===");
ShowSampleNodes(config);
// Perform modifications
Console.WriteLine("\n=== Applying Modifications ===");
int modificationsCount = 0;
// 1. Modify some booleans
var booleans = config.RootNodes.Where(n => n.NodeType == "boolean").Take(3).ToList();
foreach (var node in booleans)
{
bool oldValue = (bool)node.Value;
node.Value = !oldValue;
Console.WriteLine($"Modified boolean at offset {node.StartOffset}: {oldValue} → {node.Value}");
modificationsCount++;
}
// 2. Modify some integers
var integers = config.RootNodes.Where(n => n.NodeType == "integer").Take(3).ToList();
foreach (var node in integers)
{
int oldValue = (int)node.Value;
node.Value = oldValue + 1000;
Console.WriteLine($"Modified integer at offset {node.StartOffset}: {oldValue} → {node.Value}");
modificationsCount++;
}
// 3. Modify some strings
var strings = config.RootNodes.Where(n => n.NodeType == "string" && !string.IsNullOrEmpty(n.Value?.ToString())).Take(2).ToList();
foreach (var node in strings)
{
string oldValue = node.Value?.ToString() ?? "";
node.Value = oldValue + "_MODIFIED";
Console.WriteLine($"Modified string at offset {node.StartOffset}: '{oldValue}' → '{node.Value}'");
modificationsCount++;
}
// 4. Add a new property
var newProperty = new ConfigNode
{
NodeType = "property",
Name = "TestProperty",
Value = 12345,
ValueType = "integer"
};
config.RootNodes.Add(newProperty);
Console.WriteLine($"Added new property: {newProperty.Name} = {newProperty.Value}");
modificationsCount++;
Console.WriteLine($"\nTotal modifications: {modificationsCount}");
// Apply modifications in-place (preserves binary structure)
Console.WriteLine("\n=== Applying In-Place Modifications ===");
byte[] modifiedData = config.GetDataForWriting(); // Get copy of original data
var inPlaceModifier = new InPlaceConfigModifier();
int appliedCount = 0;
// Apply boolean modifications
foreach (var node in booleans)
{
if (inPlaceModifier.ModifyNode(modifiedData, node, node.Value))
{
Console.WriteLine($"✓ Applied boolean modification at offset {node.StartOffset}");
appliedCount++;
}
}
// Apply integer modifications
foreach (var node in integers)
{
if (inPlaceModifier.ModifyNode(modifiedData, node, node.Value))
{
Console.WriteLine($"✓ Applied integer modification at offset {node.StartOffset}");
appliedCount++;
}
}
// Apply string modifications
foreach (var node in strings)
{
if (inPlaceModifier.ModifyNode(modifiedData, node, node.Value))
{
Console.WriteLine($"✓ Applied string modification at offset {node.StartOffset}");
appliedCount++;
}
}
Console.WriteLine($"\n{appliedCount} out of {modificationsCount - 1} in-place modifications applied");
Console.WriteLine($"(Note: New property addition not supported in in-place mode)");
Console.WriteLine($"\nModified size: {modifiedData.Length:N0} bytes");
Console.WriteLine($"Size difference: {modifiedData.Length - originalData.Length:+#;-#;0} bytes (should be 0 for in-place)");
// Save to output file
string outputFilePath = outputPath ?? Path.Combine(
Path.GetDirectoryName(inputPath),
Path.GetFileNameWithoutExtension(inputPath) + "_modified" + Path.GetExtension(inputPath)
);
File.WriteAllBytes(outputFilePath, modifiedData);
Console.WriteLine($"Saved to: {outputFilePath}");
// Verify by parsing the modified file
Console.WriteLine("\n=== Verifying Modified File ===");
var verifyConfig = parser.Parse(modifiedData);
Console.WriteLine($"Parsed {verifyConfig.Statistics.TotalNodes:N0} nodes from modified file");
// Check if modifications persisted
Console.WriteLine("\n=== Verification Results ===");
int verifiedChanges = 0;
int expectedChanges = appliedCount; // Only verify what was actually applied
// Check modified booleans
foreach (var originalNode in booleans)
{
var modifiedNode = verifyConfig.RootNodes.FirstOrDefault(n =>
n.NodeType == "boolean" && n.StartOffset == originalNode.StartOffset);
if (modifiedNode != null && modifiedNode.Value.Equals(originalNode.Value))
{
Console.WriteLine($"✓ Boolean at {originalNode.StartOffset}: expected={originalNode.Value}, actual={modifiedNode.Value}");
verifiedChanges++;
}
else
{
Console.WriteLine($"✗ Boolean at {originalNode.StartOffset}: expected={originalNode.Value}, actual={modifiedNode?.Value?.ToString() ?? "NOT FOUND"}");
}
}
// Check modified integers
foreach (var originalNode in integers)
{
var modifiedNode = verifyConfig.RootNodes.FirstOrDefault(n =>
n.NodeType == "integer" && n.StartOffset == originalNode.StartOffset);
if (modifiedNode != null && modifiedNode.Value.Equals(originalNode.Value))
{
Console.WriteLine($"✓ Integer at {originalNode.StartOffset}: expected={originalNode.Value}, actual={modifiedNode.Value}");
verifiedChanges++;
}
else
{
Console.WriteLine($"✗ Integer at {originalNode.StartOffset}: expected={originalNode.Value}, actual={modifiedNode?.Value?.ToString() ?? "NOT FOUND"}");
}
}
// Check modified strings
foreach (var originalNode in strings)
{
var modifiedNode = verifyConfig.RootNodes.FirstOrDefault(n =>
n.NodeType == "string" && n.StartOffset == originalNode.StartOffset);
if (modifiedNode != null && modifiedNode.Value?.ToString() == originalNode.Value?.ToString())
{
string displayValue = originalNode.Value?.ToString() ?? "";
if (displayValue.Length > 30)
displayValue = displayValue.Substring(0, 27) + "...";
Console.WriteLine($"✓ String at {originalNode.StartOffset}: '{displayValue}'");
verifiedChanges++;
}
else
{
Console.WriteLine($"✗ String at {originalNode.StartOffset}: VERIFICATION FAILED");
}
}
Console.WriteLine($"\n{verifiedChanges}/{expectedChanges} modifications verified successfully!");
if (verifiedChanges == expectedChanges)
{
Console.WriteLine("\n✓ All in-place modifications applied and verified successfully!");
Console.WriteLine($"Modified file saved to: {outputFilePath}");
Console.WriteLine($"\nFile size preserved: {modifiedData.Length:N0} bytes (in-place modification)");
}
else
{
Console.WriteLine($"\n⚠ Some modifications could not be verified! ({verifiedChanges}/{expectedChanges})");
}
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
private static void ShowSampleNodes(ComprehensiveConfigFile config)
{
Console.WriteLine("First 5 booleans:");
foreach (var node in config.RootNodes.Where(n => n.NodeType == "boolean").Take(5))
{
Console.WriteLine($" Offset {node.StartOffset}: {node.Value}");
}
Console.WriteLine("\nFirst 5 integers:");
foreach (var node in config.RootNodes.Where(n => n.NodeType == "integer").Take(5))
{
Console.WriteLine($" Offset {node.StartOffset}: {node.Value}");
}
Console.WriteLine("\nFirst 5 strings:");
foreach (var node in config.RootNodes.Where(n => n.NodeType == "string").Take(5))
{
string value = node.Value?.ToString() ?? "null";
if (value.Length > 40)
value = value.Substring(0, 37) + "...";
Console.WriteLine($" Offset {node.StartOffset}: '{value}'");
}
}
}
}

View File

@@ -0,0 +1,112 @@
using System;
using System.IO;
using System.Text.Json;
using GeViSetEditor.Core.Models;
using GeViSetEditor.Core.Parsers;
namespace GeViSetEditor.CLI.Commands
{
/// <summary>
/// Test complete binary parser - parses ENTIRE structure
/// </summary>
public static class ParseCompleteCommand
{
public static void Execute(string inputPath, string? outputJsonPath = null)
{
Console.WriteLine("=== Complete Binary Parser Test ===\n");
if (!File.Exists(inputPath))
{
Console.WriteLine($"ERROR: File not found: {inputPath}");
return;
}
try
{
// Read file
byte[] data = File.ReadAllBytes(inputPath);
Console.WriteLine($"Read file: {inputPath}");
Console.WriteLine($"File size: {data.Length:N0} bytes\n");
// Parse with complete parser
var parser = new CompleteBinaryParser();
var setFile = parser.Parse(data);
// Display results
Console.WriteLine("\n=== Parse Results ===");
Console.WriteLine($"Header: '{setFile.Header}'");
Console.WriteLine($"Sections: {setFile.Sections.Count}");
Console.WriteLine($"Total Items: {setFile.Statistics.TotalItems}");
Console.WriteLine($"Total Rules: {setFile.Statistics.TotalRules}");
Console.WriteLine($"Total Actions: {setFile.Statistics.TotalActions}");
Console.WriteLine("\n=== Section Breakdown ===");
foreach (var sectionType in setFile.Statistics.SectionTypes.OrderByDescending(x => x.Value))
{
Console.WriteLine($" {sectionType.Key}: {sectionType.Value} occurrences");
}
// Show first few sections in detail
Console.WriteLine("\n=== First 10 Sections (Detail) ===");
foreach (var section in setFile.Sections.Take(10))
{
Console.WriteLine($"\nSection: '{section.Name}'");
Console.WriteLine($" Offset: {section.FileOffset} - {section.FileEndOffset} ({section.ByteSize} bytes)");
Console.WriteLine($" Items: {section.Items.Count}, Rules: {section.Rules.Count}");
if (section.Items.Count > 0)
{
Console.WriteLine(" Sample items:");
foreach (var item in section.Items.Take(3))
{
Console.WriteLine($" {item.Key} = {item.Value} ({item.ValueType})");
}
if (section.Items.Count > 3)
{
Console.WriteLine($" ... and {section.Items.Count - 3} more");
}
}
if (section.Rules.Count > 0)
{
Console.WriteLine(" Sample rules:");
foreach (var rule in section.Rules.Take(2))
{
Console.WriteLine($" Rule #{rule.RuleId}: {rule.Actions.Count} actions");
foreach (var action in rule.Actions.Take(2))
{
Console.WriteLine($" - {action}");
}
}
}
}
// Export to JSON if requested
if (!string.IsNullOrEmpty(outputJsonPath))
{
Console.WriteLine($"\n=== Exporting to JSON ===");
var options = new JsonSerializerOptions
{
WriteIndented = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
string json = JsonSerializer.Serialize(setFile, options);
File.WriteAllText(outputJsonPath, json);
Console.WriteLine($"JSON written to: {outputJsonPath}");
Console.WriteLine($"JSON size: {json.Length:N0} characters");
}
Console.WriteLine("\n✓ Parsing complete!");
}
catch (Exception ex)
{
Console.WriteLine($"\n✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace:\n{ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,97 @@
using System;
using System.IO;
using GeViSetEditor.Core.Parsers;
using GeViSetEditor.Core.Writers;
namespace GeViSetEditor.CLI.Commands
{
public static class TestRoundTripCommand
{
public static void Execute(string inputPath)
{
Console.WriteLine("=== Round-Trip Conversion Test ===\n");
if (!File.Exists(inputPath))
{
Console.WriteLine($"Error: File not found: {inputPath}");
return;
}
try
{
// Step 1: Read original file
Console.WriteLine($"Step 1: Reading original file...");
byte[] originalData = File.ReadAllBytes(inputPath);
Console.WriteLine($" Read {originalData.Length} bytes\n");
// Step 2: Parse with safe parser
Console.WriteLine($"Step 2: Parsing file...");
var parser = new SafeSetFileParser();
var setFile = parser.Parse(originalData);
Console.WriteLine($" Parsed successfully");
Console.WriteLine($" Found {setFile.ActionMappings.Count} action mappings\n");
// Step 3: Write back
Console.WriteLine($"Step 3: Writing file back...");
var writer = new SafeSetFileWriter();
byte[] outputData = writer.Write(setFile);
Console.WriteLine($" Written {outputData.Length} bytes\n");
// Step 4: Compare
Console.WriteLine($"Step 4: Comparing original vs output...");
var comparison = writer.Compare(originalData, outputData);
if (comparison.IsIdentical)
{
Console.WriteLine("\n✓✓✓ SUCCESS! Round-trip conversion is PERFECT!");
Console.WriteLine(" Original and output files are byte-for-byte identical.");
Console.WriteLine(" Safe to write back to GeViServer!");
}
else
{
Console.WriteLine($"\n✗✗✗ WARNING! Files differ in {comparison.DifferentBytes} bytes");
Console.WriteLine("\nFirst differences:");
foreach (var diff in comparison.Differences)
{
Console.WriteLine($" {diff}");
}
Console.WriteLine("\n!!! DO NOT write to server until this is fixed !!!");
}
// Step 5: Show extracted action mappings
Console.WriteLine($"\n" + new string('=', 70));
Console.WriteLine("EXTRACTED ACTION MAPPINGS");
Console.WriteLine(new string('=', 70));
int count = 0;
foreach (var mapping in setFile.ActionMappings)
{
count++;
Console.WriteLine($"\nMapping #{count} at offset {mapping.FileOffset}:");
Console.WriteLine($" Actions ({mapping.Actions.Count}):");
int actionNum = 0;
foreach (var action in mapping.Actions)
{
actionNum++;
Console.WriteLine($" {actionNum}. {action}");
if (actionNum >= 5 && mapping.Actions.Count > 5)
{
Console.WriteLine($" ... and {mapping.Actions.Count - 5} more");
break;
}
}
}
Console.WriteLine($"\n" + new string('=', 70));
Console.WriteLine($"Total: {setFile.ActionMappings.Count} mappings");
Console.WriteLine(new string('=', 70));
}
catch (Exception ex)
{
Console.WriteLine($"\n✗✗✗ ERROR: {ex.Message}");
Console.WriteLine($"Stack trace: {ex.StackTrace}");
}
}
}
}

View File

@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<ItemGroup>
<ProjectReference Include="..\GeViSetEditor.Core\GeViSetEditor.Core.csproj" />
</ItemGroup>
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@@ -0,0 +1,244 @@
using System;
using System.Linq;
using GeViSetEditor.Core.Parsers;
using GeViSetEditor.Core.Models;
using GeViSetEditor.CLI.Commands;
namespace GeViSetEditor.CLI
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("=== GeViSet Configuration Editor ===\n");
if (args.Length == 0)
{
ShowHelp();
return;
}
string command = args[0].ToLower();
try
{
switch (command)
{
case "view":
case "parse":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor view <input.set>");
return;
}
ViewSetFile(args[1]);
break;
case "export":
if (args.Length < 3)
{
Console.WriteLine("Usage: GeViSetEditor export <input.set> <output.xlsx>");
return;
}
ExportToExcel(args[1], args[2]);
break;
case "import":
if (args.Length < 3)
{
Console.WriteLine("Usage: GeViSetEditor import <input.xlsx> <output.set>");
return;
}
ImportFromExcel(args[1], args[2]);
break;
case "test-roundtrip":
case "test":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor test-roundtrip <input.set>");
return;
}
TestRoundTripCommand.Execute(args[1]);
break;
case "parse-complete":
case "full":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor parse-complete <input.set> [output.json]");
return;
}
string jsonOutput = args.Length >= 3 ? args[2] : null;
ParseCompleteCommand.Execute(args[1], jsonOutput);
break;
case "to-json":
case "json":
if (args.Length < 3)
{
Console.WriteLine("Usage: GeViSetEditor to-json <input.set> <output.json>");
return;
}
ExportJsonCommand.Execute(args[1], args[2]);
break;
case "enhanced":
case "full-parse":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor enhanced <input.set> [output.json]");
return;
}
string enhancedOutput = args.Length >= 3 ? args[2] : null;
EnhancedParseCommand.Execute(args[1], enhancedOutput);
break;
case "analyze":
case "inspect":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor analyze <input.set> [report.json]");
return;
}
string reportOutput = args.Length >= 3 ? args[2] : null;
AnalyzeStructureCommand.Execute(args[1], reportOutput);
break;
case "comprehensive":
case "all":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor comprehensive <input.set> [output.json]");
return;
}
string comprehensiveOutput = args.Length >= 3 ? args[2] : null;
ComprehensiveParseCommand.Execute(args[1], comprehensiveOutput);
break;
case "modify":
case "edit":
if (args.Length < 2)
{
Console.WriteLine("Usage: GeViSetEditor modify <input.set> [output.set]");
return;
}
string modifyOutput = args.Length >= 3 ? args[2] : null;
ModifyConfigCommand.Execute(args[1], modifyOutput);
break;
default:
Console.WriteLine($"Unknown command: {command}");
ShowHelp();
break;
}
}
catch (Exception ex)
{
Console.WriteLine($"\n❌ Error: {ex.Message}");
Console.WriteLine($"\nStack trace:\n{ex.StackTrace}");
}
}
static void ShowHelp()
{
Console.WriteLine("Commands:");
Console.WriteLine(" view <input.set> - View configuration and action mappings");
Console.WriteLine(" test-roundtrip <input.set> - Test read/write safety (IMPORTANT!)");
Console.WriteLine(" comprehensive <input.set> [out.json] - Parse ALL config data (19K+ nodes)");
Console.WriteLine(" modify <input.set> [output.set] - Test edit/add/delete operations");
Console.WriteLine(" to-json <input.set> <output.json> - Export action mappings to JSON");
Console.WriteLine(" export <input.set> <output.xlsx> - Export to Excel for editing");
Console.WriteLine(" import <input.xlsx> <output.set> - Import from Excel to .set file");
Console.WriteLine("\nExamples:");
Console.WriteLine(" GeViSetEditor test-roundtrip TestMKS.set");
Console.WriteLine(" GeViSetEditor enhanced TestMKS.set full_config.json");
Console.WriteLine(" GeViSetEditor to-json TestMKS.set mappings.json");
Console.WriteLine(" GeViSetEditor view TestMKS.set");
Console.WriteLine(" GeViSetEditor export TestMKS.set mappings.xlsx");
}
static void ViewSetFile(string inputPath)
{
Console.WriteLine($"Parsing: {inputPath}\n");
var parser = new SetFileParser();
var config = parser.Parse(inputPath);
Console.WriteLine("\n" + new string('=', 70));
Console.WriteLine("CONFIGURATION SUMMARY");
Console.WriteLine(new string('=', 70) + "\n");
int totalRules = 0;
int totalVariations = 0;
foreach (var section in config.Sections)
{
if (section.Rules.Count > 0)
{
Console.WriteLine($"\n{section.Name}:");
Console.WriteLine(new string('-', 50));
foreach (var rule in section.Rules)
{
totalRules++;
totalVariations += rule.ActionVariations.Count;
Console.WriteLine($"\n Rule #{rule.RuleId}:");
// Show triggers
var activeTriggers = rule.TriggerProperties.Where(kv => kv.Value).ToList();
if (activeTriggers.Any())
{
Console.WriteLine($" Triggers: {string.Join(", ", activeTriggers.Select(t => t.Key))}");
}
// Show main action
if (!string.IsNullOrEmpty(rule.MainAction))
{
Console.WriteLine($" Action: {rule.MainAction}");
}
// Show variations
if (rule.ActionVariations.Count > 0)
{
Console.WriteLine($" Variations ({rule.ActionVariations.Count}):");
foreach (var variation in rule.ActionVariations)
{
Console.WriteLine($" [{variation.VariationId}] {variation.ActionString}");
if (!string.IsNullOrEmpty(variation.ActionType))
{
Console.WriteLine($" Type: {variation.ActionType}");
}
if (!string.IsNullOrEmpty(variation.FullCommand))
{
Console.WriteLine($" Command: {variation.FullCommand}");
}
if (!string.IsNullOrEmpty(variation.ServerName))
{
Console.WriteLine($" Server: {variation.ServerName}");
}
}
}
}
}
}
Console.WriteLine("\n" + new string('=', 70));
Console.WriteLine($"Total: {totalRules} rules, {totalVariations} variations");
Console.WriteLine(new string('=', 70));
}
static void ExportToExcel(string inputPath, string outputPath)
{
Console.WriteLine("Excel export not yet implemented.");
Console.WriteLine("Will be added in next step with EPPlus library.");
}
static void ImportFromExcel(string inputPath, string outputPath)
{
Console.WriteLine("Excel import not yet implemented.");
Console.WriteLine("Will be added after export functionality.");
}
}
}