Class SqliteNcResultAmender
- Namespace
- Hi.SqliteUtils
- Assembly
- HiNc.dll
Internal Use Only. The amender of a completed result file (the NC play result recording's
P3), opened by OpenWrite(string): it writes onto steps the file
holds what two commands write onto the steps after a play – the measured time the CSV
one-to-one mapping sets (AmendActualTimes(IEnumerable<NcResultActualTimeAmendment>, CancellationToken)) and the two briefs the step-physics
recompute replaces (AmendStepBriefs(IEnumerable<StepBrief>, CancellationToken): the force brief and the sequential physics state
both, as the recompute rebuilds the sequential chain of every step it passes). A step's record
is taken once by the writer and never added again, so these are the one way a recorded value
changes. An amend rewrites whole chunks: the chunk is decoded, the step's payload replaced, the
chunk laid out and compressed again and its row updated – one transaction a bin (1,024
steps), the file's rollback journal keeping it consistent – so the amendments are handed in by
step index ascending and the cost is a chunk's decode and encode for every bin touched, not for
every step. Each amend that wrote something stamps its time into Meta
(ActualTimesAmendedUtc, BriefsAmendedUtc)
in the transaction of every bin it wrote, so a bin that stands carries the stamp even when a
later bin fails, and a review can tell a file that carries measured times, or recomputed
briefs, from one that holds the play's values alone.
The file stays completed (Finalized 1, rollback-journal mode); a file that was not
completed is refused. The amender wants the file to itself. On Windows a file another
connection holds open -- a review, a listing, another program -- is refused when the amender
opens (a share-mode probe); other systems do not enforce share modes, so there the open
passes, and SQLite's own locks keep each bin's transaction whole: a reader in the middle of a
read makes a bin wait up to two seconds, then fail. Neither keeps a reader's chunk cache
current: a review reads the chunks as they were when its cache took them, so it is reopened,
or its cache dropped, after an amend. Any thread may call the amender, one call at a time.
public sealed class SqliteNcResultAmender : IDisposable
- Inheritance
-
SqliteNcResultAmender
- Implements
- Inherited Members
- Extension Methods
Properties
DatabasePath
The full path of the result file.
public string DatabasePath { get; }
Property Value
Methods
AmendActualTimes(IEnumerable<NcResultActualTimeAmendment>, CancellationToken)
Writes measured times onto steps the file holds: in each step's payload the flags' bit 1 is
set and the 20-byte record (WriteBin(BinaryWriter)) replaces the one there or
is appended, so SqliteNcResultReader.TryGetMachiningStep reads the time back as
ActualTime. The step chunks touched are rewritten, one
transaction a bin; a step without a step payload in the file is skipped. A bin that wrote
something writes the time of this amend into Meta in its own transaction
(ActualTimesAmendedUtc).
public NcResultAmendResult AmendActualTimes(IEnumerable<NcResultActualTimeAmendment> amendments, CancellationToken cancellationToken = default)
Parameters
amendmentsIEnumerable<NcResultActualTimeAmendment>The steps and their times, by step index strictly ascending; read as they come, a bin at a time, so a long sequence may be streamed.
cancellationTokenCancellationTokenChecked before each bin: once cancelled, the bins committed stand and the result says it stopped.
Returns
- NcResultAmendResult
What was written.
Exceptions
- ArgumentNullException
amendmentsor an amendment is null.- ArgumentException
A step index is not above the one before it.
- InvalidDataException
A chunk or a payload of the file is not what this build reads.
- SqliteException
SQLite failed to read or write (a connection that holds the file makes a statement fail after two seconds); the bin in progress is rolled back.
- ObjectDisposedException
The amender was disposed.
AmendStepBriefs(IEnumerable<StepBrief>, CancellationToken)
Writes the two briefs onto steps the file holds, in the three places a step's briefs live:
the Status column of its narrow row (the force brief's tri-state tag), the tag byte of
the removal scalars in its step payload, and its brief payload, rewritten whole as the
force brief's record (WriteBin(BinaryWriter, MillingForceBrief?))
followed by the sequential physics state's (WriteBin(BinaryWriter)) – the
recompute rebuilds the sequential chain of every step it passes, so the pair is replaced as a
pair. The step and brief chunks touched are rewritten, one transaction a bin with the rows.
Each of the three places is written where the file holds it and skipped where it does not
(a step whose record the full queue dropped or the writer refused, its brief taken, has a
brief payload and no narrow row). A bin that wrote something writes the time of this amend
into Meta in its own transaction (BriefsAmendedUtc).
public NcResultAmendResult AmendStepBriefs(IEnumerable<StepBrief> briefs, CancellationToken cancellationToken = default)
Parameters
briefsIEnumerable<StepBrief>The steps' briefs, by step index strictly ascending (the force brief null for the null record, the sequential physics state not null); read as they come, a bin at a time.
cancellationTokenCancellationTokenChecked before each bin: once cancelled, the bins committed stand and the result says it stopped.
Returns
- NcResultAmendResult
What was written.
Exceptions
- ArgumentNullException
briefsor a brief is null.- ArgumentException
A step index is not above the one before it, or a sequential physics state is null.
- InvalidDataException
A chunk or a payload of the file is not what this build reads.
- SqliteException
SQLite failed to read or write (a connection that holds the file makes a statement fail after two seconds); the bin in progress is rolled back.
- ObjectDisposedException
The amender was disposed.
Dispose()
Closes the amender; idempotent. A bin in progress on another thread is finished first.
public void Dispose()