nc_program_manager/.paul/STATE.md
dtrentin bd17ea46e5 feat(11-refactor): extract ArgParser, fix error handling, remove dead code
Phase 11 complete:
- ArgParser.cs: CLI parsing extracted from Program.cs (pure static method)
- Program.cs: no static state; Scarica/Invia take explicit InputArgs param
- Program.cs: try/finally with connected flag — fixes connection leak on exception
- Program.cs: PrintErrors helper surfaces CncResult.Errors on every failure
- AesCrypt.cs: deleted (dead code, zero references)
- NcProgramManager.csproj: AesCrypt.cs → ArgParser.cs

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-18 00:01:32 +02:00

6.6 KiB

Project State

Project Reference

See: .paul/PROJECT.md (updated 2026-05-17)

Core value: Machinists transfer CNC programs to/from any controller without manual steps or internet Current focus: All phases complete — project fully documented

Current Position

Milestone: v0.3 Code Quality Phase: 12 of 2 (docs-cli) — Not started Plan: Not started Status: Ready to plan Phase 12 Last activity: 2026-05-18 — Phase 11 (refactor) complete, transitioned to Phase 12

Progress:

  • Milestone v0.1: [██████████] 100% (complete)
  • Milestone v0.2: [██████████] 100% (complete)
  • Milestone v0.3: [█████░░░░░] 50%
  • Phase 11 (refactor): [██████████] 100% (complete)
  • Phase 12 (docs-cli): [░░░░░░░░░░] 0%

Loop Position

PLAN ──▶ APPLY ──▶ UNIFY
  ✓        ✓        ✓     [Phase 11 complete — ready to plan Phase 12]

What Was Built (v0.3 Code Quality — in progress)

Phase 11 — Refactor

  • ArgParser.cs — static class, Parse(string[]) → InputArgs; all CLI regex parsing extracted from Program.cs
  • Program.cs — no static state; Scarica/Invia take explicit InputArgs; VediErrore takes bool debugMode
  • Program.cs — try/finally with connected flag in Scarica and Invia; connection leak fixed
  • Program.csPrintErrors(IReadOnlyList<CncError>) helper; CncResult.Errors printed on every failure
  • AesCrypt.cs — deleted (dead code, no references)

What Was Built (v0.1 Multi-CN Release)

Phase 1 — CNC Abstraction

  • Namespace: Fanuc_integration.Cnc.*FanucProgramManager.Cnc.* (29 files)
  • IFocasDialect extended: UploadStart/DownloadStart accept short fileType
  • IFanucMachine created: extends ICncMachine with tool offset + work zero R/W
  • CncManufacturer enum: Fanuc, Heidenhain, Siemens, Mitsubishi
  • All 29 Cnc/**/*.cs files added to csproj

Phase 2 — Heidenhain LSV2

  • HeidenhainConnectionConfig — IP, port 19000, credentials, timeout
  • Lsv2Client — TCP framing, CRC-16/CCITT, login (SELECT+LOG_IN), ReceiveFile/SendFile
  • HeidenhainMachine : ICncMachine — RunGuardedAsync pattern, state machine

Phase 3 — Siemens + Mitsubishi FTP

  • SiemensConnectionConfig / SiemensFtpClient / SiemensMachine : ICncMachine
  • MitsubishiConnectionConfig / MitsubishiFtpClient / MitsubishiMachine : ICncMachine

Phase 4 — Wiring

  • CncMachineFactory — creates right ICncMachine from InputArgs
  • InputArgs — added manufacturer, username, password fields
  • Program.cs — full rewrite using ICncMachine; Fanuc 3-file via IFanucMachine cast

Phase 5 — NC Validator

  • ValidationSeverity / ValidationError / ValidationResult model types
  • INcProgramValidator + NcProgramValidator (5 universal + per-manufacturer rules)
  • Validator injected into all 4 machine classes; upload blocked on Error severity
  • NcProgramValidatorTests — 30+ NUnit tests

Test Infrastructure

  • NcProgramManager.Tests/ — NUnit 3.13.3 + Moq 4.18.4, .NET 4.7.2
  • FtpServerStub + Lsv2ServerStub — in-process TCP stubs
  • Unit + integration tests; Fanuc FOCAS tests [Ignore]d (Windows-only DLL)

What Was Built (v0.2 NcProgramManager — complete)

Phase 06 — Rename Cleanup

  • Namespace: FanucProgramManager.*NcProgramManager.* (all files)
  • Project renamed, test folder renamed, dead FANUCMachine.cs deleted

Phase 07 — License Core

  • IMachineFingerprint / ILicenseValidator interfaces
  • MachineFingerprint — WMI CPU/BIOS fingerprint
  • LicenseFile.TryRead — reads .lic file, returns base64 signature
  • LicenseValidator.Validate — RSA-SHA256 verify
  • LicenseValidatorTests — 6 unit tests (testable via internal ctor injection)

Phase 08 — License Integration

  • Program.cs — RSA check wired at startup; checkLicense deleted; license.lic next to EXE
  • InputArgs.cs-chiave= field removed

Phase 09 — License Generator

  • LicenseGenerator standalone console tool (separate repo: ssh://git@3nt-git.duckdns.org:222/davide.trentin/license-generator.git)
  • Commands: keygen (RSA 2048-bit pair), fingerprint (WMI, Windows), sign (RSA-SHA256 → .lic)
  • Real public key embedded in Licensing/LicenseValidator.cs (PLACEHOLDER removed)
  • private.key.xml at ~/Documents/mine/c#/LicenseGenerator/ (gitignored — keep secure)

Phase 10 — README Docs

  • README.md in NcProgramManager root — Italian, operator-facing: CLI args, license setup, examples, controllers table
  • README.md in LicenseGenerator repo — Italian, vendor-facing: keygen first-run, 4-step license issuance workflow, commands table, security

CLI Args (current)

  • -manufacturer=fanuc|heidenhain|siemens|mitsubishi (default: fanuc)
  • -azione= — action (Scarica/Invia/etc.)
  • -ip= — CNC IP
  • -porta= — port
  • -username= (Heidenhain/Siemens/Mitsubishi)
  • -password= (Heidenhain/Siemens/Mitsubishi)
  • License: place license.lic next to the EXE (no CLI arg)

Accumulated Context

Decisions

  • .NET 4.7.2 locked — max compatibility
  • RSA asymmetric offline licensing: private key vendor-only, public key embedded in binary
  • license.lic always at AppDomain.CurrentDomain.BaseDirectory — no CLI override
  • RSACryptoServiceProvider + SHA256CryptoServiceProvider (not HashAlgorithmName) — .NET 4.7.2 compat
  • Constructor injection pattern: internal ctor accepts key XML — testable without Windows WMI
  • LicenseGenerator: standalone separate repo — vendor tool, never shipped to customers
  • Heidenhain: LSV2 port 19000, needs real hardware testing
  • Siemens: FTP /_N_MPF_DIR/, needs Sinumerik FTP option enabled on machine
  • # = Warning in Fanuc/Mitsubishi — macro variable indicator

Deferred Issues

  • Heidenhain: ReadActiveProgramAsync / SelectMainProgram not implemented
  • Siemens: same as Heidenhain
  • Build + integration not verifiable on Linux (fwlib32 Windows-only)
  • MachineFingerprint WMI + full license flow — needs real Windows hardware test
  • private.key.xml owned by root — run sudo chown $USER ~/Documents/mine/c#/LicenseGenerator/private.key.xml

Blockers/Concerns

None — project complete.

Git State

Last commit (NcProgramManager): see git log --oneline LicenseGenerator repo: commit 2ef68dd — feat: initial LicenseGenerator Branch: main

Session Continuity

Last session: 2026-05-17 Stopped at: Phase 11 complete, phase 12 ready Next action: /paul:plan for Phase 12 (docs-cli — README complete CLI reference) Resume file: .paul/ROADMAP.md


STATE.md — Updated after every significant action