Take a contact from another station without reopening the contest
AppSession.TakeFromNetwork wrote the contact to the store and then called OpenContest to see it, which built a new ContestSession, read the whole log back and built new entry positions. Anything the operator was typing at either radio went with them, and the entry boxes were rebuilt under the other operator's hands. It also ran on the socket thread, so it was changing the log while the windows were reading it. ContestSession now applies the three messages itself: AddFromNetwork, ReplaceFromNetwork and DeleteFromNetwork write the store, change the log in place and raise Changed. None of them raises Logged, Edited or Deleted, so nothing goes back out to the other stations. Points and multipliers are still worked out here from the rules rather than trusted. A contact that arrives goes in where its timestamp says it belongs, through the new ContestLog.Insert, and the log is scored again: of two stations that worked the same multiplier, the one that worked it first keeps it, however late the message turns up. Add would have appended it at the end and given the multiplier to the wrong contact. The socket thread now hands the update to the thread the windows run on, which is where every other change to the log is made. The matching rule moved with the code, so ContestSession answers what a message from N1MM refers to: the contact id, then the call and time it had before the edit. Still not tested against a second station. Two of these cannot run on one host to try it, because they share one UDP port. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RoGtneMQaz4M9w7Kk49AVD
This commit is contained in:
@@ -107,6 +107,64 @@ public sealed class ContestSession
|
||||
|
||||
public void NotifyChanged() => Changed?.Invoke(this, EventArgs.Empty);
|
||||
|
||||
/// A contact worked by another station of a multi-operator entry. It is
|
||||
/// scored here from the rules rather than trusting what the sender worked
|
||||
/// out, and it raises no `Logged`, so it does not go back out to the other
|
||||
/// stations. False when we already hold it.
|
||||
public bool AddFromNetwork(Qso qso)
|
||||
{
|
||||
if (Log.Qsos.Any(q => q.Id == qso.Id))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Log.Insert(store.Add(FromNetwork(qso)));
|
||||
SentNumber = NextSentNumber();
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// An edit made at another station. False when we do not hold the contact
|
||||
/// it changes.
|
||||
public bool ReplaceFromNetwork(Qso qso, string oldCall, DateTime oldTimestampUtc)
|
||||
{
|
||||
if (Find(qso.Id, oldCall, oldTimestampUtc) is not { } old)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
Qso replacement = FromNetwork(qso) with { Id = old.Id };
|
||||
store.Update(replacement);
|
||||
Log.Replace(replacement);
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// A contact deleted at another station. False when we do not hold it.
|
||||
public bool DeleteFromNetwork(string id, string call, DateTime timestampUtc)
|
||||
{
|
||||
if (Find(id, call, timestampUtc) is not { } gone)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
store.Delete(gone.Id);
|
||||
Log.Remove(gone.Id);
|
||||
Changed?.Invoke(this, EventArgs.Empty);
|
||||
return true;
|
||||
}
|
||||
|
||||
private Qso FromNetwork(Qso qso) => qso with
|
||||
{
|
||||
ContestNumber = Instance.ContestNumber,
|
||||
IsOriginal = false,
|
||||
};
|
||||
|
||||
/// N1MM keys a contact on its call and time, so a message from N1MM carries
|
||||
/// no id we would recognise. Fall back to that pair when the id misses.
|
||||
private Qso? Find(string id, string call, DateTime timestampUtc) =>
|
||||
Log.Qsos.FirstOrDefault(q => id.Length > 0 && q.Id == id)
|
||||
?? Log.Qsos.FirstOrDefault(q =>
|
||||
string.Equals(q.Call.Text, call, StringComparison.OrdinalIgnoreCase)
|
||||
&& q.TimestampUtc == timestampUtc);
|
||||
|
||||
private QsoEdit EditWith(string id, Func<Qso, QsoEdit> change)
|
||||
{
|
||||
Qso before = Log.Qsos.FirstOrDefault(q => q.Id == id)
|
||||
|
||||
Reference in New Issue
Block a user