78 lines
3.2 KiB
C#
78 lines
3.2 KiB
C#
using System.Runtime.Serialization;
|
|
|
|
namespace PlotDirector.Companion.Protocol;
|
|
|
|
public static class ProtocolVersion
|
|
{
|
|
public const int Current = 1;
|
|
public const int MaxFrameBytes = 256 * 1024;
|
|
public const int MaxDocuments = 32;
|
|
public const int MaxParagraphCharacters = 2048;
|
|
public const string Capabilities = "sessions-v1,positional-selection-v1,batched-snapshot-v1";
|
|
public static bool SupportsRequiredCapabilities(string? offered)
|
|
{
|
|
var available = (offered ?? "").Split(new[]{','},StringSplitOptions.RemoveEmptyEntries);
|
|
return Capabilities.Split(',').All(required => available.Contains(required));
|
|
}
|
|
}
|
|
|
|
// Only values cross the boundary. Never add an Office reference or arbitrary object payload.
|
|
[DataContract]
|
|
public sealed class Message
|
|
{
|
|
[DataMember] public int Version { get; set; } = ProtocolVersion.Current;
|
|
[DataMember] public Guid CorrelationId { get; set; } = Guid.NewGuid();
|
|
[DataMember] public string Kind { get; set; } = "";
|
|
[DataMember] public Guid WordInstanceId { get; set; }
|
|
[DataMember] public Guid SessionId { get; set; }
|
|
[DataMember] public long Sequence { get; set; }
|
|
[DataMember] public long Revision { get; set; }
|
|
[DataMember] public Guid SnapshotId { get; set; }
|
|
[DataMember] public int Start { get; set; }
|
|
[DataMember] public int End { get; set; }
|
|
[DataMember] public DocumentDescriptor[] Documents { get; set; } = Array.Empty<DocumentDescriptor>();
|
|
[DataMember] public ParagraphFragment? Fragment { get; set; }
|
|
[DataMember] public string Capabilities { get; set; } = ProtocolVersion.Capabilities;
|
|
[DataMember] public string Status { get; set; } = "";
|
|
[DataMember] public UiMetric[] Metrics { get; set; } = Array.Empty<UiMetric>();
|
|
[DataMember] public int QueueDepth { get; set; }
|
|
[DataMember] public int? ChapterId { get; set; }
|
|
[DataMember] public int? SceneId { get; set; }
|
|
[DataMember] public string ChapterTitle { get; set; } = "";
|
|
[DataMember] public string SceneTitle { get; set; } = "";
|
|
}
|
|
|
|
[DataContract]
|
|
public sealed class DocumentDescriptor
|
|
{
|
|
[DataMember] public Guid SessionId { get; set; }
|
|
[DataMember] public Guid ManuscriptId { get; set; }
|
|
[DataMember] public int? ProjectId { get; set; }
|
|
[DataMember] public int? BookId { get; set; }
|
|
[DataMember] public long Revision { get; set; }
|
|
[DataMember] public bool IdentityPersisted { get; set; }
|
|
// Association is local metadata, not proof of server authorization.
|
|
[DataMember] public bool AssociationVerified { get; set; }
|
|
}
|
|
|
|
[DataContract]
|
|
public sealed class ParagraphFragment
|
|
{
|
|
[DataMember] public int ParagraphIndex { get; set; }
|
|
[DataMember] public int Start { get; set; }
|
|
[DataMember] public int End { get; set; }
|
|
[DataMember] public int OutlineLevel { get; set; }
|
|
[DataMember] public string Text { get; set; } = "";
|
|
[DataMember] public string[] MarkerTags { get; set; } = Array.Empty<string>();
|
|
[DataMember] public bool CompletesParagraph { get; set; }
|
|
}
|
|
|
|
public enum ProseSynchronizationMode { Automatic, OnSave, Manual }
|
|
|
|
[DataContract]
|
|
public sealed class UiMetric
|
|
{
|
|
[DataMember] public string Operation { get; set; } = "";
|
|
[DataMember] public double Milliseconds { get; set; }
|
|
}
|