|
1 |
| -using System; |
2 |
| -using System.IO; |
3 |
| -using System.Linq; |
4 |
| -using System.Linq.Expressions; |
5 |
| -using System.Reflection; |
6 |
| -using LazyCoder.Runner.Writer; |
7 |
| -using LazyCoder.Typescript; |
8 |
| - |
9 |
| -namespace LazyCoder.Runner |
10 |
| -{ |
11 |
| - public class Runner |
12 |
| - { |
13 |
| - public static int Run(string dll, |
14 |
| - string outputDirectory |
15 |
| - ) |
16 |
| - { |
17 |
| - dll = Path.GetFullPath(dll); |
18 |
| - var loadedTypes = new AssemblyReader().Read(dll); |
19 |
| - var coderTypes = GetCoderTypes(dll); |
20 |
| - Console.Out.WriteLine("Found: " + string.Join(", ", coderTypes.Select(x => x.Name))); |
21 |
| - foreach (var coderType in coderTypes) |
22 |
| - { |
23 |
| - Console.Out.WriteLine("Start Coder " + coderType.Name); |
24 |
| - var ctor = (Func<ICoder>)Expression.Lambda(Expression.New(coderType)).Compile(); |
25 |
| - var coder = ctor(); |
26 |
| - var tsFiles = coder.Rewrite(loadedTypes).ToArray(); |
27 |
| - Console.Out.WriteLine($"Gonna create {tsFiles.Length} files"); |
28 |
| - |
29 |
| - Directory.CreateDirectory(Path.GetFullPath(outputDirectory)); |
30 |
| - foreach (var tsFile in tsFiles) WriteFile(outputDirectory, tsFile); |
31 |
| - |
32 |
| - Console.Out.WriteLine($"Coder {coderType.Name} finished"); |
33 |
| - } |
34 |
| - |
35 |
| - return 0; |
36 |
| - } |
37 |
| - |
38 |
| - private static void WriteFile(string outputDirectory, |
39 |
| - TsFile tsFile) |
40 |
| - { |
41 |
| - var directory = Path.Combine(Path.GetFullPath(outputDirectory), tsFile.Directory); |
42 |
| - Directory.CreateDirectory(directory); |
43 |
| - var writerContext = new WriterContext(); |
44 |
| - writerContext.Write(tsFile); |
45 |
| - var content = writerContext.GetResult(); |
46 |
| - File.WriteAllText(Path.Combine(directory, tsFile.Name + ".ts"), content); |
47 |
| - } |
48 |
| - |
49 |
| - private static Type[] GetCoderTypes(string dll) |
50 |
| - { |
51 |
| - return Assembly.LoadFile(dll) |
52 |
| - .GetTypes() |
53 |
| - .Where(x => x.GetInterfaces() |
54 |
| - .Any(y => y == typeof(ICoder))) |
55 |
| - .ToArray(); |
56 |
| - } |
57 |
| - } |
58 |
| -} |
| 1 | +using System; |
| 2 | +using System.IO; |
| 3 | +using System.Linq; |
| 4 | +using System.Linq.Expressions; |
| 5 | +using System.Reflection; |
| 6 | +using LazyCoder.Runner.Writer; |
| 7 | +using LazyCoder.Typescript; |
| 8 | + |
| 9 | +namespace LazyCoder.Runner |
| 10 | +{ |
| 11 | + public class Runner |
| 12 | + { |
| 13 | + public static int Run(string dll, |
| 14 | + string outputDirectory |
| 15 | + ) |
| 16 | + { |
| 17 | + dll = Path.GetFullPath(dll); |
| 18 | + var loadedTypes = new AssemblyReader().Read(dll); |
| 19 | + var csAstTypes = CsAstFactory.Create(loadedTypes); |
| 20 | + var coderTypes = GetCoderTypes(dll); |
| 21 | + Console.Out.WriteLine("Found: " + string.Join(", ", coderTypes.Select(x => x.Name))); |
| 22 | + foreach (var coderType in coderTypes) |
| 23 | + { |
| 24 | + Console.Out.WriteLine("Start Coder " + coderType.Name); |
| 25 | + var ctor = (Func<ICoder>)Expression.Lambda(Expression.New(coderType)).Compile(); |
| 26 | + var coder = ctor(); |
| 27 | + var tsFiles = coder.Rewrite(csAstTypes).ToArray(); |
| 28 | + Console.Out.WriteLine($"Gonna create {tsFiles.Length} files"); |
| 29 | + |
| 30 | + Directory.CreateDirectory(Path.GetFullPath(outputDirectory)); |
| 31 | + foreach (var tsFile in tsFiles) WriteFile(outputDirectory, tsFile); |
| 32 | + |
| 33 | + Console.Out.WriteLine($"Coder {coderType.Name} finished"); |
| 34 | + } |
| 35 | + |
| 36 | + return 0; |
| 37 | + } |
| 38 | + |
| 39 | + private static void WriteFile(string outputDirectory, |
| 40 | + TsFile tsFile) |
| 41 | + { |
| 42 | + var directory = Path.Combine(Path.GetFullPath(outputDirectory), tsFile.Directory); |
| 43 | + Directory.CreateDirectory(directory); |
| 44 | + var writerContext = new WriterContext(); |
| 45 | + writerContext.Write(tsFile); |
| 46 | + var content = writerContext.GetResult(); |
| 47 | + File.WriteAllText(Path.Combine(directory, tsFile.Name + ".ts"), content); |
| 48 | + } |
| 49 | + |
| 50 | + private static Type[] GetCoderTypes(string dll) |
| 51 | + { |
| 52 | + return Assembly.LoadFile(dll) |
| 53 | + .GetTypes() |
| 54 | + .Where(x => x.GetInterfaces() |
| 55 | + .Any(y => y == typeof(ICoder))) |
| 56 | + .ToArray(); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments