diff options
Diffstat (limited to 'CommandLineWrapper')
10 files changed, 249 insertions, 1 deletions
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<AccountListResult> +{ + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => workspace.AccountList(); +} + +public struct AccountListResult +{ + public Dictionary<string, AccountItem> 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<HereResult> +{ + private DirectoryInfo _currentDirectory; + + public HereResultGetter(DirectoryInfo currentDirectory) + => _currentDirectory = currentDirectory; + + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => JVCSCommandInvoker.Invoke(Constants.CommandParameterGenerator.Here(), _currentDirectory.ToString()); +} + +public struct HereResult +{ + public List<HereResultItem> 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<InfoResult> +{ + private string _mappingName; + + public InfoResultGetter(string mappingName) + => _mappingName = mappingName; + + protected override Task<JVCSCommandInvoker.InvokeResult> 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<InfoHistory> 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<ShareListResult> +{ + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => workspace.ShareList(); +} + +public struct ShareListResult +{ + public List<ShareItem> 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<SeeShareResult> +{ + private string _shareId; + + public ShareSeeResultGetter(string shareId) + => _shareId = shareId; + + protected override Task<JVCSCommandInvoker.InvokeResult> 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<string, SheetMappingMetadata> Mappings { get; set; } +} + +public struct SheetMappingMetadata +{ + // TIPS + // Since SheetMappingMetadata in the serialized output of the command-line tool `jv sheet see <SHARE_ID>` + // 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<AlignJsonResult> +{ + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => workspace.SheetAlignList(); +} + +public struct AlignJsonResult +{ + public Dictionary<string, AlignTaskMapping> 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<SheetListResult> +{ + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => workspace.SheetList(); +} + +public struct SheetListResult +{ + public SheetListJsonResult Result { get; set; } +} + +public struct SheetListJsonResult +{ + public List<SheetItem> MySheets { get; set; } + public List<SheetItem> ReferenceSheets { get; set; } + public List<SheetItem> 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<StatusResult> +{ + protected override Task<JVCSCommandInvoker.InvokeResult> ExecCommand(JVCSWorkspace workspace) + => workspace.Status(); +} + +public struct StatusResult +{ + public List<string> Created { get; set; } + public List<string> Lost { get; set; } + public List<string> Erased { get; set; } + public List<MovedItem> Moved { get; set; } + public List<ModifiedItem> 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<TJsonFormat> + { + protected abstract Task<InvokeResult> ExecCommand(JVCSWorkspace workspace); + + public async Task<TJsonFormat?> 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<TJsonFormat>(trimmedOutput, options); + } + + return default(TJsonFormat); + } + } +} diff --git a/CommandLineWrapper/WorkspaceCommandGenerator/Program.cs b/CommandLineWrapper/WorkspaceCommandGenerator/Program.cs index dd00afc..e0bf373 100644 --- a/CommandLineWrapper/WorkspaceCommandGenerator/Program.cs +++ b/CommandLineWrapper/WorkspaceCommandGenerator/Program.cs @@ -71,7 +71,7 @@ namespace CommandLineWrapper.CodeGenerator var parameters = methodMatch.Groups[2].Value; // Skip methods already defined in JVCSWorkspace - if (methodName == "GetWorkspaceDirectory" || methodName == "Login") + if (methodName == "GetWorkspaceDirectory") { continue; } |
