Esempio n. 1
0
        private static int GenerateSources(
            IList <string> source,
            IList <string> classToGenerate,
            string projectAssembly           = "Generated.WASM",
            string projectGenerationLocation = "_generated",
            bool force = false
            )
        {
            try
            {
                var stopwatch = Stopwatch.StartNew();
                ValidateArguments(
                    source,
                    classToGenerate,
                    projectAssembly,
                    projectGenerationLocation
                    );
                GlobalLogger.Info($"projectAssembly: {projectAssembly}");
                GlobalLogger.Info($"projectGenerationLocation: {projectGenerationLocation}");

                GlobalLogger.Info($"classToGenerate.Length: {classToGenerate.Count}");
                foreach (var classToGenerateItem in classToGenerate)
                {
                    GlobalLogger.Info($"classToGenerateItem: {classToGenerateItem}");
                }

                GlobalLogger.Info($"sourceFile.Length: {source.Count}");
                foreach (var sourceFileItem in source)
                {
                    GlobalLogger.Info($"sourceFile: {sourceFileItem}");
                }

                projectGenerationLocation = Path.Combine(
                    ".",
                    projectGenerationLocation
                    );

                var sourceDirectory = Path.Combine(
                    ".",
                    SOURCE_FILES_DIRECTORY_NAME
                    );
                var sourceFiles = CopyAndDownloadSourceFiles(
                    source
                    );
                var generationList = classToGenerate;

                // Check for already Generated Source.
                var projectAssemblyDirectory = Path.Combine(
                    projectGenerationLocation,
                    projectAssembly
                    );
                if (Directory.Exists(
                        projectAssemblyDirectory
                        ))
                {
                    if (!force)
                    {
                        GlobalLogger.Error(
                            $"Project Assembly Directory was not empty: {projectAssemblyDirectory}"
                            );
                        GlobalLogger.Error(
                            $"Use --force to replace directory."
                            );
                        return(502);
                    }

                    GlobalLogger.Warning(
                        $"Deleting existing projectAssemblyDirectory: {projectAssemblyDirectory}"
                        );
                    Directory.Delete(
                        projectAssemblyDirectory,
                        true
                        );
                }

                var textFormatter = new NoFormattingTextFormatter();
                var writer        = new ProjectWriter(
                    projectGenerationLocation,
                    projectAssembly
                    );

                new GenerateInteropSource().Run(
                    projectAssembly,
                    sourceDirectory,
                    sourceFiles,
                    generationList,
                    writer,
                    textFormatter,
                    new Dictionary <string, string>
                {
                    { "BABYLON.PointerInfoBase | type", "int" }
                }
                    );
                stopwatch.Stop();
                GlobalLogger.Success($"Took {stopwatch.ElapsedMilliseconds}ms to Generate Source Project.");

                return(0);
            }
            catch (ArgumentException ex)
            {
                GlobalLogger.Error(
                    $"Argument failure: {ex.ParamName} -> {ex.Message}"
                    );
                return(404);
            }
            catch (InvalidSourceFileException ex)
            {
                GlobalLogger.Error(
                    $"Invalid Source File Exception: {ex.Message}"
                    );
                return(501);
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var stopwatch                 = Stopwatch.StartNew();
            var projectAssembly           = "EventHorizon.Blazor.BabylonJS.WASM";
            var projectGenerationLocation = Path.Combine(
                "..",
                "_generated"
                );

            var sourceDirectory = Path.Combine(
                ".",
                "SourceFiles"
                );
            var textFormatter = new NoFormattingTextFormatter();
            var writer        = new ProjectWriter(
                projectGenerationLocation,
                projectAssembly
                );
            var sourceFiles = new List <string>
            {
                "babylon.d.ts",
                "babylon.gui.d.ts",
            };
            var generationList = new List <string>
            {
                "Scene",
                "VertexBuffer",
                "ICameraInput",
                "AbstractActionManager",
                "ICustomAnimationFrameRequester",
                "IAction",
                "Vector3",
                "EventState",
                "Observable",
                "Container",
                "Control",
                "Button",
                "UniversalCamera",
                "ArcRotateCamera",
                "PointLight",
                "Grid",
                "StackPanel",
                "MeshBuilder",
                "StandardMaterial",
                "Texture",
                "HemisphericLight",
                "PointerInfo",
                "PointerInfoBase",
                "SceneLoader",
                "ParticleHelper",
                "Sound",
                "Tools",
            };

            // Remove any already Generated Source.
            if (Directory.Exists(Path.Combine(
                                     projectGenerationLocation,
                                     projectAssembly
                                     )))
            {
                Directory.Delete(
                    Path.Combine(
                        projectGenerationLocation,
                        projectAssembly
                        ),
                    true
                    );
            }
            GlobalLogger.Info("Removed Generation Directory");

            new GenerateSource().Run(
                projectAssembly,
                sourceDirectory,
                sourceFiles,
                generationList,
                writer,
                textFormatter,
                new Dictionary <string, string>
            {
                { "BABYLON.PointerInfoBase | type", "int" }
            }
                );
            stopwatch.Stop();
            GlobalLogger.Info("Removed Generation Directory");
            GlobalLogger.Info($"Took {stopwatch.ElapsedMilliseconds}ms to generate.");
        }