Exemplo n.º 1
0
        public static void GenerateCode(
            IReadOnlyCollection <string> specificationFiles,
            string baseDirectory,
            bool useNestedNamespaces,
            [CanBeNull] string baseNamespace,
            [CanBeNull] GitRepository repository)
        {
            foreach (var specificationFile in specificationFiles)
            {
                var tool = ToolSerializer.Load(specificationFile);
                // for formatting and ordering of properties
                ToolSerializer.Save(tool);
                ApplyRuntimeInformation(tool, repository);

                var generationDirectory = useNestedNamespaces ? Path.Combine(baseDirectory, tool.Name) : baseDirectory;
                var generationFile      = Path.Combine(generationDirectory, $"{Path.GetFileNameWithoutExtension(tool.DefinitionFile)}.Generated.cs");
                FileSystemTasks.EnsureExistingDirectory(generationDirectory);

                var @namespace =
                    !useNestedNamespaces
                        ? baseNamespace
                        : string.IsNullOrEmpty(baseNamespace)
                            ? tool.Name
                            : $"{baseNamespace}.{tool.Name}";

                using (var fileStream = File.Open(generationFile, FileMode.Create))
                    using (var streamWriter = new StreamWriter(fileStream))
                    {
                        ToolGenerator.Run(tool, @namespace, streamWriter);
                    }

                Logger.Info($"Generated code from '{Path.GetFileName(tool.DefinitionFile)}'.");
            }
        }
Exemplo n.º 2
0
        public static void GenerateCode(
            string specificationFile,
            Func <Tool, string> outputFileProvider = null,
            Func <Tool, string> namespaceProvider  = null,
            Func <Tool, string> sourceFileProvider = null)
        {
            var tool = ToolSerializer.Load(specificationFile);

            // for formatting and ordering of properties
            ToolSerializer.Save(tool, specificationFile);

            tool.SpecificationFile = specificationFile;
            tool.SourceFile        = sourceFileProvider?.Invoke(tool);
            tool.Namespace         = namespaceProvider?.Invoke(tool);
            ApplyRuntimeInformation(tool, specificationFile, sourceFileProvider, namespaceProvider);

            GenerateCode(tool, outputFileProvider?.Invoke(tool) ?? tool.DefaultOutputFile);
        }
Exemplo n.º 3
0
        public static void GenerateCode(
            IReadOnlyCollection <string> specificationFiles,
            Func <Tool, string> outputFileProvider = null,
            Func <Tool, string> namespaceProvider  = null,
            Func <Tool, string> sourceFileProvider = null)
        {
            foreach (var specificationFile in specificationFiles)
            {
                var tool = ToolSerializer.Load(specificationFile);
                // for formatting and ordering of properties
                ToolSerializer.Save(tool, specificationFile);

                tool.SpecificationFile = specificationFile;
                tool.SourceFile        = sourceFileProvider?.Invoke(tool);
                tool.Namespace         = namespaceProvider?.Invoke(tool);
                ApplyRuntimeInformation(tool, specificationFile, sourceFileProvider, namespaceProvider);

                var outputFile = outputFileProvider?.Invoke(tool) ??
                                 Path.Combine(Path.GetDirectoryName(tool.SpecificationFile).NotNull(), tool.DefaultOutputFileName);

                GenerateCode(tool, outputFile);
            }
        }