34 lines
1.9 KiB
C#

using PlotDirector.Companion.Protocol;
namespace PlotDirector.Companion.Client;
// Value-only per-document review state; the Word adapter owns this on its UI thread.
public sealed class AnalysisReview
{
public Guid SessionId { get; private set; }
public long Revision { get; private set; }
public Guid SnapshotId { get; private set; }
public string Status { get; private set; } = "Choose Analyse Document to review structure.";
public bool Running { get; private set; }
public int Progress { get; private set; }
private int expectedOffset;
public void ExpectPage(int offset) {expectedOffset=offset;}
public AnalysisPage? Page { get; private set; }
public void Prepare(Guid session)
{SessionId=session;SnapshotId=Guid.Empty;Page=null;Running=true;Progress=0;Status="Waiting for a quiet moment to read the document…";}
public void Begin(Guid session,long revision,Guid snapshot)
{SessionId=session;Revision=revision;SnapshotId=snapshot;Page=null;expectedOffset=0;Progress=0;Running=true;Status="Reading document in short batches…";}
public void Stop(string reason)
{Running=false;SnapshotId=Guid.Empty;Page=null;Status=reason;}
public bool Accept(Message message)
{
if(SnapshotId==Guid.Empty||message.SessionId!=SessionId||message.Revision!=Revision||message.SnapshotId!=SnapshotId)return false;
if(message.Status=="analysis-complete"&&message.Analysis!=null&&message.Analysis.Offset==expectedOffset)
{Page=message.Analysis;Running=false;Progress=100;Status="Analysis complete — review suggestions below.";return true;}
if(!Running)return false;
if(message.Status is "ok" or "awaiting-structure")
{Progress=Math.Max(Progress,Math.Min(100,message.Progress));Status=Progress==100?"Finishing local analysis…":"Reading and analysing document: "+Progress+"%";return true;}
Stop("Analysis stopped: "+message.Status+". You can try again.");return true;
}
}