Exemplo n.º 1
0
        public string Process(string templateFile, string referenceList, string projectFile)
        {
            var options = new Options
            {
                TemplateFileName   = templateFile,
                CurrentNamespace   = Path.GetFileNameWithoutExtension(templateFile),
                CurrentAssembly    = Path.GetFileNameWithoutExtension(projectFile).Replace(".React", ".Entities"),
                AssemblyReferences = (from r in referenceList.Split(';')
                                      where r.Contains(".Entities")
                                      let reactDirectory = FindReactDirectory(r)
                                                           select new AssemblyReference
                {
                    AssemblyName = Path.GetFileNameWithoutExtension(r),
                    AssemblyFullPath = r,
                    ReactDirectory = reactDirectory,
                    AllTypescriptFiles = new DirectoryInfo(reactDirectory).EnumerateFiles("*.ts", SearchOption.AllDirectories)
                                         .Concat(new DirectoryInfo(reactDirectory).EnumerateFiles("*.t4s", SearchOption.AllDirectories))
                                         .Select(a => a.FullName)
                                         .Where(fn => !fn.Contains(@"\obj\") && !fn.Contains(@"\bin\"))  //Makes problem when deploying
                                         .ToList(),
                }).ToDictionary(a => a.AssemblyName)
            };

            return(EntityDeclarationGenerator.Process(options));
        }
Exemplo n.º 2
0
        public string Process(string templateFile, string referenceList, string projectFile)
        {
            var options = new Options
            {
                TemplateFileName   = templateFile,
                CurrentNamespace   = Path.GetFileNameWithoutExtension(templateFile),
                CurrentAssembly    = Path.GetFileNameWithoutExtension(projectFile).Replace(".React", ".Entities"),
                AssemblyReferences = (from r in referenceList.Split(';')
                                      where r.Contains(".Entities")
                                      let reactDirectory = ReactDirectoryCache.GetOrAdd(r, FindReactDirectory)
                                                           select new AssemblyReference
                {
                    AssemblyName = Path.GetFileNameWithoutExtension(r),
                    AssemblyFullPath = r,
                    ReactDirectory = reactDirectory,
                    AllTypescriptFiles = AllFilesCache.GetOrAdd(reactDirectory, GetAllTypescriptFiles),
                }).ToDictionary(a => a.AssemblyName)
            };

            return(EntityDeclarationGenerator.Process(options));
        }
Exemplo n.º 3
0
        public static int Main(string[] args)
        {
            Stopwatch sw = Stopwatch.StartNew();

            string intermediateAssembly = args[0];

            string[] references = File.ReadAllLines(args[1]);
            string[] content    = File.ReadAllLines(args[2]);

            var log = Console.Out;

            log.WriteLine("Starting SignumTSGenerator");

            bool hasPdb = File.Exists(Path.ChangeExtension(intermediateAssembly, ".pdb"));

            AssemblyDefinition reactAssembly = AssemblyDefinition.ReadAssembly(intermediateAssembly, new ReaderParameters
            {
                ReadingMode          = ReadingMode.Deferred,
                ReadSymbols          = hasPdb,
                InMemory             = true,
                SymbolReaderProvider = hasPdb ? new PdbReaderProvider() : null
            });


            if (AlreadyProcessed(reactAssembly))
            {
                log.WriteLine("SignumTSGenerator already processed: {0}", intermediateAssembly);
                return(0);
            }

            PreloadingAssemblyResolver resolver = new PreloadingAssemblyResolver(references);

            var assemblyReferences = (from r in references
                                      where r.Contains(".Entities")
                                      let reactDirectory = FindReactDirectory(r)
                                                           select new AssemblyReference
            {
                AssemblyName = Path.GetFileNameWithoutExtension(r),
                AssemblyFullPath = r,
                ReactDirectory = reactDirectory,
                AllTypescriptFiles = GetAllTypescriptFiles(reactDirectory),
            }).ToDictionary(a => a.AssemblyName);

            var entitiesAssembly          = Path.GetFileNameWithoutExtension(intermediateAssembly).Replace(".React", ".Entities");
            var entitiesAssemblyReference = assemblyReferences.GetOrThrow(entitiesAssembly);
            var entitiesModule            = ModuleDefinition.ReadModule(entitiesAssemblyReference.AssemblyFullPath, new ReaderParameters {
                AssemblyResolver = resolver
            });
            var options = new AssemblyOptions
            {
                CurrentAssembly    = entitiesAssembly,
                AssemblyReferences = assemblyReferences,
                AllReferences      = references.ToDictionary(a => Path.GetFileNameWithoutExtension(a)),
                ModuleDefinition   = entitiesModule,
                Resolver           = resolver,
            };


            var currentDir = Directory.GetCurrentDirectory();
            var files      = content
                             .Where(file => Path.GetExtension(file) == ".t4s")
                             .Select(file => Path.Combine(currentDir, file))
                             .ToList();

            bool hasErrors = false;

            foreach (var file in files)
            {
                try
                {
                    string result = EntityDeclarationGenerator.Process(options, file, Path.GetFileNameWithoutExtension(file));

                    var targetFile = Path.ChangeExtension(file, ".ts");
                    if (File.Exists(targetFile) && File.ReadAllText(targetFile) == result)
                    {
                        log.WriteLine($"Skipping {targetFile} (Up to date)");
                    }
                    else
                    {
                        log.WriteLine($"Writing {targetFile}");
                        File.WriteAllText(targetFile, result);
                    }
                }
                catch (Exception ex)
                {
                    hasErrors = true;
                    log.WriteLine($"Error in {file}");
                    log.WriteLine(ex.Message);
                }
            }

            MarkAsProcessed(reactAssembly, resolver);

            reactAssembly.Write(intermediateAssembly, new WriterParameters
            {
                WriteSymbols         = hasPdb,
                SymbolWriterProvider = hasPdb ? new PdbWriterProvider() : null
            });

            log.WriteLine($"SignumTSGenerator finished in {sw.ElapsedMilliseconds.ToString()}ms");

            Console.WriteLine();

            return(hasErrors ? -1 : 0);
        }
Exemplo n.º 4
0
        public static int Main(string[] args)
        {
            var log = Console.Out;

            Stopwatch sw = Stopwatch.StartNew();

            string intermediateAssembly = args[0];

            string[] references = File.ReadAllLines(args[1]);
            string[] content    = File.ReadAllLines(args[2]);

            log.WriteLine("Starting SignumTSGenerator");

            var assemblyReferences = (from r in references
                                      where r.Contains(".Entities")
                                      let reactDirectory = FindReactDirectory(r)
                                                           select new AssemblyReference
            {
                AssemblyName = Path.GetFileNameWithoutExtension(r),
                AssemblyFullPath = r,
                ReactDirectory = reactDirectory,
                AllTypescriptFiles = GetAllTypescriptFiles(reactDirectory),
            }).ToDictionary(a => a.AssemblyName);

            var entitiesAssembly          = Path.GetFileNameWithoutExtension(intermediateAssembly).Replace(".React", ".Entities");
            var entitiesAssemblyReference = assemblyReferences.GetOrThrow(entitiesAssembly);

            var currentDir = Directory.GetCurrentDirectory();
            var files      = content
                             .Where(file => Path.GetExtension(file) == ".t4s")
                             .Select(file => Path.Combine(currentDir, file))
                             .ToList();

            var upToDateContent = string.Join("\r\n",
                                              new[] { entitiesAssemblyReference.AssemblyFullPath }
                                              .Concat(files)
                                              .OrderBy(a => a)
                                              .Select(f => File.GetLastWriteTimeUtc(f).ToString("o") + " " + Path.GetFileName(f)));

            var signumUpToDatePath = Path.Combine(Path.GetDirectoryName(args[1]), "SignumUpToDate.txt");

            if (File.Exists(signumUpToDatePath) && File.ReadAllText(signumUpToDatePath) == upToDateContent)
            {
                log.WriteLine($"SignumTSGenerator already processed ({sw.ElapsedMilliseconds.ToString()}ms)");
                return(0);
            }

            var entityResolver = new PreloadingAssemblyResolver(references);
            var entitiesModule = ModuleDefinition.ReadModule(entitiesAssemblyReference.AssemblyFullPath, new ReaderParameters
            {
                AssemblyResolver = entityResolver
            });

            var options = new AssemblyOptions
            {
                CurrentAssembly    = entitiesAssembly,
                AssemblyReferences = assemblyReferences,
                AllReferences      = references.ToDictionary(a => Path.GetFileNameWithoutExtension(a)),
                ModuleDefinition   = entitiesModule,
                Resolver           = entityResolver,
            };

            bool hasErrors = false;

            foreach (var file in files)
            {
                try
                {
                    string result = EntityDeclarationGenerator.Process(options, file, Path.GetFileNameWithoutExtension(file));

                    var targetFile = Path.ChangeExtension(file, ".ts");
                    if (File.Exists(targetFile) && File.ReadAllText(targetFile) == result)
                    {
                        log.WriteLine($"Skipping {targetFile} (Up to date)");
                    }
                    else
                    {
                        log.WriteLine($"Writing {targetFile}");
                        File.WriteAllText(targetFile, result);
                    }
                }
                catch (Exception ex)
                {
                    hasErrors = true;
                    log.WriteLine($"{file}:error STSG0001:{ex.Message}");
                    log.WriteLine(ex.Message);
                }
            }

            if (hasErrors)
            {
                log.WriteLine($"SignumTSGenerator finished with errors ({sw.ElapsedMilliseconds.ToString()}ms)");
                Console.WriteLine();
                return(0);
            }
            else
            {
                File.WriteAllText(signumUpToDatePath, upToDateContent);
                log.WriteLine($"SignumTSGenerator finished ({sw.ElapsedMilliseconds.ToString()}ms)");
                Console.WriteLine();
                return(0);
            }
        }