Files
lmxopcua/src/ZB.MOM.WW.OtOpcUa.Driver.AbCip/Import/IL5kSource.cs
T
Joseph Doherty 86407e6ca2 Auto: abcip-2.1 — L5K parser + ingest
Pure-text parser for Studio 5000 L5K controller exports. Recognises
TAG/END_TAG, DATATYPE/END_DATATYPE, and PROGRAM/END_PROGRAM blocks,
strips (* ... *) comments, and tolerates multi-line entries + unknown
sections (CONFIG, MOTION_GROUP, etc.). Output records — L5kTag,
L5kDataType, L5kMember — feed L5kIngest which converts to
AbCipTagDefinition + AbCipStructureMember. Alias tags and
ExternalAccess=None tags are skipped per Kepware precedent.

AbCipDriverOptions gains an L5kImports collection
(AbCipL5kImportOptions records — file path or inline text + per-import
device + name prefix). InitializeAsync merges the imports into the
declared Tags map, with declared tags winning on Name conflicts so
operators can override import results without editing the L5K source.

Tests cover controller-scope TAG, program-scope TAG, alias-tag flag,
DATATYPE with member array dims, comment stripping, unknown-section
skipping, multi-line entries, and the full ingest path including
ExternalAccess=None / ReadOnly / UDT-typed tag fanout.

Closes #229

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-25 18:01:08 -04:00

30 lines
1.2 KiB
C#

namespace ZB.MOM.WW.OtOpcUa.Driver.AbCip.Import;
/// <summary>
/// Abstraction over an L5K text source so the parser can consume strings, files, or streams
/// without coupling to <see cref="System.IO"/>. Implementations return the full text in a
/// single call — L5K files are typically &lt;10 MB even for large controllers, and the parser
/// needs random access to handle nested DATATYPE/TAG blocks regardless.
/// </summary>
public interface IL5kSource
{
/// <summary>Reads the full L5K body as a string.</summary>
string ReadAll();
}
/// <summary>String-backed source — used by tests + when the L5K body is loaded elsewhere.</summary>
public sealed class StringL5kSource : IL5kSource
{
private readonly string _text;
public StringL5kSource(string text) => _text = text ?? throw new ArgumentNullException(nameof(text));
public string ReadAll() => _text;
}
/// <summary>File-backed source — used by Admin / driver init to load <c>*.L5K</c> exports.</summary>
public sealed class FileL5kSource : IL5kSource
{
private readonly string _path;
public FileL5kSource(string path) => _path = path ?? throw new ArgumentNullException(nameof(path));
public string ReadAll() => System.IO.File.ReadAllText(_path);
}