From ac769e656b122ff569c3f1534701b71e00fed586 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 27 Oct 2020 19:21:35 +0800 Subject: Split front and back end. --- Timeline.ErrorCodes.CodeGenerator/Program.cs | 77 ---------------------- .../Timeline.ErrorCodes.CodeGenerator.csproj | 16 ----- .../packages.lock.json | 24 ------- 3 files changed, 117 deletions(-) delete mode 100644 Timeline.ErrorCodes.CodeGenerator/Program.cs delete mode 100644 Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj delete mode 100644 Timeline.ErrorCodes.CodeGenerator/packages.lock.json (limited to 'Timeline.ErrorCodes.CodeGenerator') diff --git a/Timeline.ErrorCodes.CodeGenerator/Program.cs b/Timeline.ErrorCodes.CodeGenerator/Program.cs deleted file mode 100644 index 84ab5908..00000000 --- a/Timeline.ErrorCodes.CodeGenerator/Program.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Linq; -using System.Reflection; -using System.Text; - -namespace Timeline.ErrorCodes.CodeGenerator -{ - class Program - { - static void Main(string[] args) - { - string Indent(int n) - { - const string indent = " "; - return string.Concat(Enumerable.Repeat(indent, n)); - } - - StringBuilder code = new StringBuilder(); - - code.AppendLine("using static Timeline.Resources.Messages;"); - code.AppendLine(); - code.AppendLine("namespace Timeline.Models.Http"); - code.AppendLine("{"); - - int depth = 1; - - void RecursiveAddErrorCode(Type type, bool root) - { - code.AppendLine($"{Indent(depth)}public static class {(root ? "ErrorResponse" : type.Name)}"); - code.AppendLine($"{Indent(depth)}{{"); - - foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy) - .Where(fi => fi.IsLiteral && !fi.IsInitOnly && fi.FieldType == typeof(int))) - { - var path = type.FullName.Replace("+", ".").Replace("Timeline.Models.Http.ErrorCodes.", "") + "." + field.Name; - - code.AppendLine($"{Indent(depth + 1)}public static CommonResponse {field.Name}(params object?[] formatArgs)"); - code.AppendLine($"{Indent(depth + 1)}{{"); - code.AppendLine($"{Indent(depth + 2)}return new CommonResponse({"ErrorCodes." + path}, string.Format({path.Replace(".", "_")}, formatArgs));"); - code.AppendLine($"{Indent(depth + 1)}}}"); - code.AppendLine(); - code.AppendLine($"{Indent(depth + 1)}public static CommonResponse CustomMessage_{field.Name}(string message, params object?[] formatArgs)"); - code.AppendLine($"{Indent(depth + 1)}{{"); - code.AppendLine($"{Indent(depth + 2)}return new CommonResponse({"ErrorCodes." + path}, string.Format(message, formatArgs));"); - code.AppendLine($"{Indent(depth + 1)}}}"); - code.AppendLine(); - } - - depth += 1; - - foreach (var nestedType in type.GetNestedTypes()) - { - RecursiveAddErrorCode(nestedType, false); - } - - depth -= 1; - - code.AppendLine($"{Indent(depth)}}}"); - code.AppendLine(); - } - - RecursiveAddErrorCode(typeof(Timeline.Models.Http.ErrorCodes), true); - - code.AppendLine("}"); - - var generatedCode = code.ToString(); - - Console.WriteLine(generatedCode); - - TextCopy.ClipboardService.SetText(generatedCode); - var oldColor = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Green; - Console.WriteLine("Code has copied to clipboard!"); - Console.ForegroundColor = oldColor; - } - } -} diff --git a/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj b/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj deleted file mode 100644 index c8eb97f3..00000000 --- a/Timeline.ErrorCodes.CodeGenerator/Timeline.ErrorCodes.CodeGenerator.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - Exe - netcoreapp3.1 - - - - - - - - - - - diff --git a/Timeline.ErrorCodes.CodeGenerator/packages.lock.json b/Timeline.ErrorCodes.CodeGenerator/packages.lock.json deleted file mode 100644 index 69cfee1e..00000000 --- a/Timeline.ErrorCodes.CodeGenerator/packages.lock.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "version": 1, - "dependencies": { - ".NETCoreApp,Version=v3.1": { - "TextCopy": { - "type": "Direct", - "requested": "[4.2.0, )", - "resolved": "4.2.0", - "contentHash": "NY2UAFIjBJj+3aABP5tyO6ooEdkJxIGtwRNqvMQKLmyIeZiyGvM4XYbkKNntyQlhyFhhfBww05C3D/0DdimfaQ==", - "dependencies": { - "Microsoft.Extensions.DependencyInjection.Abstractions": "3.1.4" - } - }, - "Microsoft.Extensions.DependencyInjection.Abstractions": { - "type": "Transitive", - "resolved": "3.1.4", - "contentHash": "AceHamXNKDMDwIoZqEoApLp8s3935wSC3VXrPaRWa0wWOaEcYdDlo1nWQ1zLiezoDmpJzV7FqDm53E0Ty/hEMg==" - }, - "timeline.errorcodes": { - "type": "Project" - } - } - } -} \ No newline at end of file -- cgit v1.2.3