From 7d59c15b0efd2aa5a27aef356a265f850a2e7e2f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Tue, 13 Jan 2026 06:24:07 +0800 Subject: Add JSON result getters for command outputs --- .../JsonResults/Implements/AccountListResult.cs | 18 +++++++++++ .../JsonResults/Implements/HereResult.cs | 30 ++++++++++++++++++ .../JsonResults/Implements/InfoResult.cs | 30 ++++++++++++++++++ .../JsonResults/Implements/ShareListResult.cs | 21 ++++++++++++ .../JsonResults/Implements/ShareSeeResult.cs | 37 ++++++++++++++++++++++ .../Implements/SheetAlignTasksResult.cs | 19 +++++++++++ .../JsonResults/Implements/SheetListResult.cs | 26 +++++++++++++++ .../JsonResults/Implements/StatusResult.cs | 36 +++++++++++++++++++++ CommandLineWrapper/JsonResults/JsonResultGetter.cs | 31 ++++++++++++++++++ 9 files changed, 248 insertions(+) create mode 100644 CommandLineWrapper/JsonResults/Implements/AccountListResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/HereResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/InfoResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/ShareListResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/ShareSeeResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/SheetAlignTasksResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/SheetListResult.cs create mode 100644 CommandLineWrapper/JsonResults/Implements/StatusResult.cs create mode 100644 CommandLineWrapper/JsonResults/JsonResultGetter.cs (limited to 'CommandLineWrapper/JsonResults') diff --git a/CommandLineWrapper/JsonResults/Implements/AccountListResult.cs b/CommandLineWrapper/JsonResults/Implements/AccountListResult.cs new file mode 100644 index 0000000..600b839 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/AccountListResult.cs @@ -0,0 +1,18 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class AccountListResultGetter : JsonResultGetter +{ + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.AccountList(); +} + +public struct AccountListResult +{ + public Dictionary Result { get; set; } +} + +public struct AccountItem +{ + public bool HasPrivateKey { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/HereResult.cs b/CommandLineWrapper/JsonResults/Implements/HereResult.cs new file mode 100644 index 0000000..b3086a1 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/HereResult.cs @@ -0,0 +1,30 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class HereResultGetter : JsonResultGetter +{ + private DirectoryInfo _currentDirectory; + + public HereResultGetter(DirectoryInfo currentDirectory) + => _currentDirectory = currentDirectory; + + protected override Task ExecCommand(JVCSWorkspace workspace) + => JVCSCommandInvoker.Invoke(Constants.CommandParameterGenerator.Here(), _currentDirectory.ToString()); +} + +public struct HereResult +{ + public List Items { get; set; } +} + +public struct HereResultItem +{ + public string Mapping { get; set; } + public string Name { get; set; } + public string CurrentVersion { get; set; } + public long Size { get; set; } + public bool IsDir { get; set; } + public bool Exist { get; set; } + public bool Modified { get; set; } + public string Holder { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/InfoResult.cs b/CommandLineWrapper/JsonResults/Implements/InfoResult.cs new file mode 100644 index 0000000..ecef724 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/InfoResult.cs @@ -0,0 +1,30 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class InfoResultGetter : JsonResultGetter +{ + private string _mappingName; + + public InfoResultGetter(string mappingName) + => _mappingName = mappingName; + + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.Info(_mappingName); +} + +public struct InfoResult +{ + public string Mapping { get; set; } + public string InRef { get; set; } + public string Vfid { get; set; } + public List Histories { get; set; } +} + +public struct InfoHistory +{ + public string Version { get; set; } + public string VersionCreator { get; set; } + public string VersionDescription { get; set; } + public bool IsCurrentVersion { get; set; } + public bool IsRefVersion { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/ShareListResult.cs b/CommandLineWrapper/JsonResults/Implements/ShareListResult.cs new file mode 100644 index 0000000..4736b81 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/ShareListResult.cs @@ -0,0 +1,21 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class ShareListResultGetter : JsonResultGetter +{ + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.ShareList(); +} + +public struct ShareListResult +{ + public List ShareList { get; set; } +} + +public struct ShareItem +{ + public string ShareId { get; set; } + public string Sharer { get; set; } + public string Description { get; set; } + public int FileCount { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/ShareSeeResult.cs b/CommandLineWrapper/JsonResults/Implements/ShareSeeResult.cs new file mode 100644 index 0000000..c965b25 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/ShareSeeResult.cs @@ -0,0 +1,37 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; +using System.Text.Json.Serialization; + +public class ShareSeeResultGetter : JsonResultGetter +{ + private string _shareId; + + public ShareSeeResultGetter(string shareId) + => _shareId = shareId; + + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.ShareSee(_shareId); +} + +public struct SeeShareResult +{ + public string ShareId { get; set; } + public string Sharer { get; set; } + public string Description { get; set; } + public Dictionary Mappings { get; set; } +} + +public struct SheetMappingMetadata +{ + // TIPS + // Since SheetMappingMetadata in the serialized output of the command-line tool `jv sheet see ` + // comes directly from the version control repository, + // its property names use the original lowercase snake_case naming, + // so JsonPropertyName must be explicitly specified for mapping. + + [JsonPropertyName("id")] + public string Id { get; set; } + + [JsonPropertyName("ver")] + public string Version { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/SheetAlignTasksResult.cs b/CommandLineWrapper/JsonResults/Implements/SheetAlignTasksResult.cs new file mode 100644 index 0000000..5539d19 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/SheetAlignTasksResult.cs @@ -0,0 +1,19 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class SheetAlignTasksResultGetter : JsonResultGetter +{ + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.SheetAlignList(); +} + +public struct AlignJsonResult +{ + public Dictionary AlignTasks { get; set; } +} + +public struct AlignTaskMapping +{ + public string LocalMapping { get; set; } + public string RemoteMapping { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/SheetListResult.cs b/CommandLineWrapper/JsonResults/Implements/SheetListResult.cs new file mode 100644 index 0000000..1fa9f0b --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/SheetListResult.cs @@ -0,0 +1,26 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class SheetListResultGetter : JsonResultGetter +{ + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.SheetList(); +} + +public struct SheetListResult +{ + public SheetListJsonResult Result { get; set; } +} + +public struct SheetListJsonResult +{ + public List MySheets { get; set; } + public List ReferenceSheets { get; set; } + public List OtherSheets { get; set; } +} + +public struct SheetItem +{ + public string Name { get; set; } + public string Holder { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/Implements/StatusResult.cs b/CommandLineWrapper/JsonResults/Implements/StatusResult.cs new file mode 100644 index 0000000..aba2c25 --- /dev/null +++ b/CommandLineWrapper/JsonResults/Implements/StatusResult.cs @@ -0,0 +1,36 @@ +using CommandLineWrapper; +using CommandLineWrapper.JsonResults; + +public class StatusResultGetter : JsonResultGetter +{ + protected override Task ExecCommand(JVCSWorkspace workspace) + => workspace.Status(); +} + +public struct StatusResult +{ + public List Created { get; set; } + public List Lost { get; set; } + public List Erased { get; set; } + public List Moved { get; set; } + public List Modified { get; set; } +} + +public enum ModifiedType +{ + Modified, + ModifiedButBaseVersionMismatch, + ModifiedButNotHeld, +} + +public struct MovedItem +{ + public string From { get; set; } + public string To { get; set; } +} + +public struct ModifiedItem +{ + public string Path { get; set; } + public ModifiedType ModificationType { get; set; } +} diff --git a/CommandLineWrapper/JsonResults/JsonResultGetter.cs b/CommandLineWrapper/JsonResults/JsonResultGetter.cs new file mode 100644 index 0000000..e1bf607 --- /dev/null +++ b/CommandLineWrapper/JsonResults/JsonResultGetter.cs @@ -0,0 +1,31 @@ +using static JVCSCommandInvoker; + +namespace CommandLineWrapper.JsonResults +{ + public abstract class JsonResultGetter + { + protected abstract Task ExecCommand(JVCSWorkspace workspace); + + public async Task Get(JVCSWorkspace workspace) + { + var result = await ExecCommand(workspace); + var output = result.StandardOutput; + + string trimmedOutput = output?.Trim() ?? "{}"; + if (!string.IsNullOrEmpty(trimmedOutput) && trimmedOutput.StartsWith("{") && trimmedOutput.EndsWith("}")) + { + var options = new System.Text.Json.JsonSerializerOptions + { + PropertyNameCaseInsensitive = true, + PropertyNamingPolicy = null, + }; + + options.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); + + return System.Text.Json.JsonSerializer.Deserialize(trimmedOutput, options); + } + + return default(TJsonFormat); + } + } +} -- cgit