Sessione salvata: copia alla chiusura della finestra e alla fine della guida, «Serve «Ho finito»», scelta per la copia incompleta e stato in Collegamento (#36, S4b)
Risposte 1, 5, 6, 9 e 10 di Alberto a S4. I valori __spin_r, __spin_b e __spin_t si copiano dalla pagina come gli altri (su Instagram da SiteData, ipotesi H23, operazioni ancora non configurate; nel sito di prova dal modulo GiroProva). La sessione si copia anche quando si chiude la finestra del browser su Windows e quando il permesso di guida finisce, sempre prima che la pagina torni al motore e con le garanzie di «Ho finito». Con «richieste» «Collegato» vuole una sessione salvata leggibile, altrimenti lo stato è «Serve «Ho finito»» e il motore aspetta. Nuova impostazione sessione.copia-incompleta (sostituisci, predefinita, o tieni-completa) e riquadro della sessione salvata nella pagina Collegamento, con soli conteggi e nomi. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9958745e53
commit
883ea4683c
41 files changed
+1349
-101
No files matched your search
@@ -19,6 +19,12 @@ public enum SessionCopyStatus
|
||||
|
||||
/// <summary>Copied, then thrown away: meanwhile the page was no longer Alberto's (rule 7).</summary>
|
||||
Discarded,
|
||||
|
||||
/// <summary>
|
||||
/// Copied but not saved: a value the requests need was missing, the saved copy has them all, and Alberto chose
|
||||
/// «Tieni la copia completa» (<see cref="IncompleteCopyChoice.KeepComplete"/>). The saved session stays as it was.
|
||||
/// </summary>
|
||||
KeptComplete,
|
||||
}
|
||||
|
||||
/// <summary>What a copy did, for the message of «Ho finito» and the tests. Never a value.</summary>
|
||||
@@ -34,11 +40,42 @@ public sealed record SessionCopyOutcome(SessionCopyStatus Status, CaptureRefusal
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the session of Febe's browser into the saved session (issue #36, S4, spec §6.0): at «Ho finito», and after the
|
||||
/// automatic login of the test site. A new copy replaces the saved one (§6.0 «un nuovo accesso ricopia tutto e
|
||||
/// sostituisce»), also when some value of the page is missing: the requests that send it then do not leave and stop
|
||||
/// the engine as a disconnection until a new copy has it (never a way back to the pages). A refused copy leaves the
|
||||
/// saved session as it is.
|
||||
/// The saved session as the Collegamento page shows it (issue #36, S4b, answer 10): its state, when it was copied, how
|
||||
/// many values of the page and doc_id it holds and the names of those it lacks. Counts and names only, never a value.
|
||||
/// </summary>
|
||||
/// <param name="State">Whether a saved session is there and can be read.</param>
|
||||
/// <param name="CopiedAt">When the browser's session was copied; null without a session or when not known.</param>
|
||||
/// <param name="Cookies">How many cookies it holds.</param>
|
||||
/// <param name="ValuesPresent">Values of the page it holds, of <paramref name="ValuesExpected"/>.</param>
|
||||
/// <param name="ValuesExpected">Values of the page the copy reads.</param>
|
||||
/// <param name="MissingValues">Names of the values of the page it lacks.</param>
|
||||
/// <param name="DocIdsPresent">doc_id it holds, of <paramref name="DocIdsExpected"/>.</param>
|
||||
/// <param name="DocIdsExpected">doc_id the copy reads.</param>
|
||||
/// <param name="MissingDocIds">Operations whose doc_id it lacks.</param>
|
||||
/// <param name="NeededMissing">How many of the missing values and doc_id a configured operation sends.</param>
|
||||
public sealed record SavedSessionReport(
|
||||
SavedSessionState State,
|
||||
DateTimeOffset? CopiedAt,
|
||||
int Cookies,
|
||||
int ValuesPresent,
|
||||
int ValuesExpected,
|
||||
IReadOnlyList<string> MissingValues,
|
||||
int DocIdsPresent,
|
||||
int DocIdsExpected,
|
||||
IReadOnlyList<string> MissingDocIds,
|
||||
int NeededMissing)
|
||||
{
|
||||
/// <summary>True when a readable session is there and nothing a configured operation sends is missing.</summary>
|
||||
public bool Complete => State == SavedSessionState.Present && NeededMissing == 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies the session of Febe's browser into the saved session (issue #36, S4, spec §6.0): at «Ho finito», after the
|
||||
/// automatic login of the test site, and (S4b) when Alberto closes the browser window on Windows or his driving lease
|
||||
/// ends by itself. A new copy replaces the saved one (§6.0 «un nuovo accesso ricopia tutto e sostituisce»), also when
|
||||
/// some value of the page is missing — unless Alberto chose «Tieni la copia completa» and the saved one is complete.
|
||||
/// The requests that send a missing value do not leave and stop the engine as a disconnection until a new copy has it
|
||||
/// (never a way back to the pages). A refused copy leaves the saved session as it is.
|
||||
/// </summary>
|
||||
public interface ISessionCopier
|
||||
{
|
||||
@@ -48,6 +85,12 @@ public interface ISessionCopier
|
||||
/// <param name="mayKeep">Asked after reading, before saving: false throws the copy away (the page stopped being Alberto's).</param>
|
||||
/// <param name="ct">Cancels the copy; nothing is saved then.</param>
|
||||
Task<SessionCopyOutcome> CopyAsync(Func<bool> mayKeep, CancellationToken ct);
|
||||
|
||||
/// <summary>Whether a saved session is there and can be read (cheap: «Collegato» and the engine ask it often).</summary>
|
||||
SavedSessionState SavedState { get; }
|
||||
|
||||
/// <summary>The saved session now, in counts and names (the Collegamento page, «Collegato»).</summary>
|
||||
SavedSessionReport Report();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,6 +119,12 @@ public sealed class BrowserSessionCopier : ISessionCopier
|
||||
_log = log ?? throw new ArgumentNullException(nameof(log));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What an incomplete copy does, asked at every copy (the setting of the Collegamento page,
|
||||
/// <see cref="SessionCopySettings"/>); by default it replaces the saved session, as before.
|
||||
/// </summary>
|
||||
public Func<CancellationToken, Task<IncompleteCopyChoice>> IncompleteCopy { get; init; } = _ => Task.FromResult(IncompleteCopyChoice.Replace);
|
||||
|
||||
/// <summary>
|
||||
/// How long the reading may last before it counts as a browser error: «Ho finito» holds the commands of the
|
||||
/// connection meanwhile, so a browser that hangs must not hold them for ever (real time).
|
||||
@@ -116,15 +165,24 @@ public sealed class BrowserSessionCopier : ISessionCopier
|
||||
return new SessionCopyOutcome(SessionCopyStatus.Discarded, null, result.Cookies, result.MissingValues.Count, result.MissingDocIds.Count);
|
||||
}
|
||||
|
||||
// Not cancelled from here: the copy was made, and a half-written replacement is never left. It replaces the
|
||||
// saved session also when a value is missing (§6.0): keeping an older copy could keep another login's cookies.
|
||||
var onDisk = await _store.ReplaceAsync(values, CancellationToken.None).ConfigureAwait(false);
|
||||
|
||||
// Missing counts only what a configured operation sends: that request will not leave (a disconnection, §6.0).
|
||||
var neededValues = result.MissingValues.Where(_plan.NeededValues.Contains).ToList();
|
||||
var neededDocIds = result.MissingDocIds.Where(_plan.NeededDocIds.Contains).ToList();
|
||||
var needed = neededValues.Concat(neededDocIds).ToList();
|
||||
var unused = result.MissingValues.Concat(result.MissingDocIds).Except(needed, StringComparer.Ordinal).ToList();
|
||||
|
||||
// An incomplete copy replaces the saved one (§6.0: an older copy could keep another login's cookies), unless
|
||||
// Alberto chose to keep a complete one (answer 9 of 18 November 2026) and the saved one is complete.
|
||||
if (needed.Count > 0
|
||||
&& IsComplete(_store.Read())
|
||||
&& await IncompleteCopy(CancellationToken.None).ConfigureAwait(false) == IncompleteCopyChoice.KeepComplete)
|
||||
{
|
||||
_log($"Sessione letta ma non salvata: mancano {string.Join(", ", needed)}, che servono alle operazioni configurate; come scelto, resta la copia completa salvata prima ({counts}).");
|
||||
return new SessionCopyOutcome(SessionCopyStatus.KeptComplete, null, result.Cookies, neededValues.Count, neededDocIds.Count);
|
||||
}
|
||||
|
||||
// Not cancelled from here: the copy was made, and a half-written replacement is never left.
|
||||
var onDisk = await _store.ReplaceAsync(values, CancellationToken.None).ConfigureAwait(false);
|
||||
_log($"Sessione copiata: {counts}"
|
||||
+ (needed.Count == 0 ? string.Empty : "; mancano " + string.Join(", ", needed) + ", che servono alle operazioni configurate")
|
||||
+ (unused.Count == 0 ? string.Empty : "; mancano anche " + string.Join(", ", unused) + ", che nessuna operazione configurata usa")
|
||||
@@ -138,6 +196,52 @@ public sealed class BrowserSessionCopier : ISessionCopier
|
||||
neededDocIds.Count);
|
||||
}
|
||||
|
||||
public SavedSessionState SavedState => _store.State;
|
||||
|
||||
public SavedSessionReport Report()
|
||||
{
|
||||
var state = _store.State;
|
||||
var values = state == SavedSessionState.Present ? _store.Read() : null;
|
||||
if (values is null)
|
||||
{
|
||||
var none = state == SavedSessionState.Present ? SavedSessionState.None : state;
|
||||
return new SavedSessionReport(none, null, 0, 0, _plan.Values.Count, [], 0, _plan.DocIds.Count, [], 0);
|
||||
}
|
||||
|
||||
var missingValues = new List<string>();
|
||||
var needed = 0;
|
||||
foreach (var read in _plan.Values)
|
||||
{
|
||||
if (!values.Fields.ContainsKey(read.Field))
|
||||
{
|
||||
missingValues.Add(read.Field);
|
||||
needed += _plan.NeededValues.Contains(read.Field) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
var missingDocIds = new List<string>();
|
||||
foreach (var read in _plan.DocIds)
|
||||
{
|
||||
if (!values.DocIds.ContainsKey(read.Field))
|
||||
{
|
||||
missingDocIds.Add(read.Field);
|
||||
needed += _plan.NeededDocIds.Contains(read.Field) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
|
||||
return new SavedSessionReport(
|
||||
SavedSessionState.Present,
|
||||
values.CopiedAt,
|
||||
values.Cookies.Count,
|
||||
_plan.Values.Count - missingValues.Count,
|
||||
_plan.Values.Count,
|
||||
missingValues,
|
||||
_plan.DocIds.Count - missingDocIds.Count,
|
||||
_plan.DocIds.Count,
|
||||
missingDocIds,
|
||||
needed);
|
||||
}
|
||||
|
||||
/// <summary>Why a copy was refused, in Italian.</summary>
|
||||
public static string Reason(CaptureRefusal refusal) => refusal switch
|
||||
{
|
||||
@@ -146,4 +250,31 @@ public sealed class BrowserSessionCopier : ISessionCopier
|
||||
CaptureRefusal.NoUserAgent => "il browser non ha dato il suo user agent",
|
||||
_ => "il browser non ha risposto",
|
||||
};
|
||||
|
||||
/// <summary>True when <paramref name="saved"/> holds every value and doc_id a configured operation sends.</summary>
|
||||
private bool IsComplete(SiteSessionValues? saved)
|
||||
{
|
||||
if (saved is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach (var field in _plan.NeededValues)
|
||||
{
|
||||
if (!saved.Fields.ContainsKey(field))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var operation in _plan.NeededDocIds)
|
||||
{
|
||||
if (!saved.DocIds.ContainsKey(operation))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user