コード例 #1
0
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            if (!ValidateOptions())
            {
                ShowHelpMessage();
                return(1);
            }

            var bundlePath          = GenerateBundle();
            var schemaBundle        = SchemaBundle.LoadBundle(File.ReadAllText(bundlePath));
            var store               = new DetailsStore(schemaBundle, options.SerializationOverrides);
            var workerGenerationJob = new WorkerGenerationJob(options.NativeOutputDirectory, options, fileSystem);
            var singleJob           = new SingleGenerationJob(options.NativeOutputDirectory, store, fileSystem);

            var runner = new JobRunner(fileSystem);

            runner.Run(singleJob, workerGenerationJob);
            return(0);
        }
コード例 #2
0
        public void OneTimeSetup()
        {
            var json      = JsonParsingTests.GetBundleContents();
            var overrides = new List <string>
            {
                "global::Improbable.Gdk.Tests.SomeType;global::UserCode.SerializationExtensions.Type"
            };

            store = new DetailsStore(SchemaBundle.LoadBundle(json), overrides);
        }
コード例 #3
0
        private static DetailsStore GetDetailsFromBundle(string bundleName)
        {
            var bundleResourceName =
                $"CodeGenerationLib.Tests.Model.SchemaBundleV1.Resources.{bundleName}.json";

            var assembly = Assembly.GetExecutingAssembly();
            var resource = assembly.GetManifestResourceStream(bundleResourceName);
            var json     = new StreamReader(resource).ReadToEnd();

            return(new DetailsStore(SchemaBundle.LoadBundle(json), new List <string>(), null));
        }
コード例 #4
0
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            if (!ValidateOptions())
            {
                ShowHelpMessage();
                return(1);
            }

            var bundlePath   = GenerateBundle();
            var schemaBundle = SchemaBundle.LoadBundle(File.ReadAllText(bundlePath));
            var fileTree     = new FileTree(options.SchemaInputDirs);
            var store        = new DetailsStore(schemaBundle, options.SerializationOverrides, fileTree);

            var jobs = AppDomain.CurrentDomain
                       .GetAssemblies()
                       .SelectMany(assembly =>
            {
                try
                {
                    return(assembly.GetTypes());
                }
                catch (ReflectionTypeLoadException e)
                {
                    Console.Error.WriteLine($"Failed to load assembly {assembly.FullName} with error {e}");
                    return(Enumerable.Empty <Type>());
                }
            })
                       .Where(type => typeof(CodegenJob).IsAssignableFrom(type))
                       .Where(type => !type.IsAbstract)
                       .Where(type => !type.GetCustomAttributes(typeof(IgnoreCodegenJobAttribute)).Any())
                       .Select(type =>
                               (CodegenJob)Activator.CreateInstance(type, options.NativeOutputDirectory, fileSystem, store))
                       .ToArray();

            new JobRunner(fileSystem).Run(jobs);
            return(0);
        }
コード例 #5
0
            public static CodegenStub GetCleanInstance()
            {
                var json = JsonParsingTests.GetBundleContents();

                return(new CodegenStub("", new MockFileSystem(), new DetailsStore(SchemaBundle.LoadBundle(json), new List <string>(), new MockFileTree()), false));
            }
コード例 #6
0
        public int Run()
        {
            if (options.ShouldShowHelp)
            {
                ShowHelpMessage();
                return(0);
            }

            var optionErrors = options.GetValidationErrors().ToList();

            foreach (var optionError in optionErrors)
            {
                Console.WriteLine(optionError);
            }

            if (optionErrors.Any())
            {
                ShowHelpMessage();
                return(1);
            }

            logger.Info("Starting code generation.");

            logger.Info("Gathering schema information.");
            var bundlePath = GenerateBundle();

            logger.Info("Loading schema bundle from json.");
            var schemaBundle = SchemaBundle.LoadBundle(File.ReadAllText(bundlePath));

            logger.Info("Setting up schema file tree.");
            var fileTree = new FileTree(options.SchemaInputDirs);

            logger.Info("Initialising DetailsStore.");
            var store = new DetailsStore(schemaBundle, options.SerializationOverrides, fileTree);

            logger.Info("Setting up code generation jobs.");
            var jobs = AppDomain.CurrentDomain
                       .GetAssemblies()
                       .SelectMany(assembly =>
            {
                try
                {
                    return(assembly.GetTypes());
                }
                catch (ReflectionTypeLoadException e)
                {
                    logger.Error(e, $"Failed to load assembly {assembly.FullName}.");
                    return(Enumerable.Empty <Type>());
                }
            })
                       .Where(type => typeof(CodegenJob).IsAssignableFrom(type))
                       .Where(type => !type.IsAbstract)
                       .Where(type => !type.GetCustomAttributes(typeof(IgnoreCodegenJobAttribute)).Any())
                       .Select(type =>
            {
                logger.Info($"Creating instance of {type}.");
                return((CodegenJob)Activator.CreateInstance(type, options.NativeOutputDirectory, fileSystem, store, options.Force));
            })
                       .ToArray();

            logger.Info("Calling JobRunner.");
            new JobRunner(fileSystem).Run(jobs);

            logger.Info("Finished code generation.");
            return(0);
        }
コード例 #7
0
 public void ParsingSchemaBundle_does_not_throw()
 {
     Assert.DoesNotThrow(() => SchemaBundle.LoadBundle(GetBundleContents()));
 }