Пример #1
0
        public static void Main(string[] args)
        {
            if (args.Length < 3)
            {
                PrintUsage();
                return;
            }

            string packetSchemaPath = args[0];
            string outputType = args[1];
            string output = args[2];

            Generator generator;

            switch (outputType)
            {
                case "markdown":
                    generator = new MarkdownGenerator(output);
                    break;
                case "csharp":
                    {
                        if (args.Length < 4)
                        {
                            PrintUsage();
                            return;
                        }
                        string configurationFileName = args[3];
                        generator = new CSharpGenerator(output, configurationFileName);
                    }
                    break;
                default:
                    PrintUsage();
                    return;
            }

            // Load the schema
            var schemaLoader = new SchemaLoader(Path.GetDirectoryName(packetSchemaPath));
            Schema packetSchema = schemaLoader.Load(packetSchemaPath);

            // Generate output from the schema.
            generator.Generate(packetSchema);
        }
        public static void Main(string[] args)
        {
            var options = new Options();
            if (!Parser.Default.ParseArgumentsStrict(args, options))
            {
                return;
            }

            Generator generator;

            switch (options.Type)
            {
                case GeneratorType.MarkDown:
                    generator = new MarkdownGenerator(options.Output);
                    break;
                case GeneratorType.CSharp:
                    if (options.ConfigurationFile == null)
                    {
                        Console.Error.WriteLine("ERROR: When type is CSharp, a configuration file is required.");
                        Console.Error.WriteLine(options.Usage());
                        return;
                    }

                    generator = new CSharpGenerator(options.Output, options.ConfigurationFile);
                    break;
                case GeneratorType.Validation:
                    generator = new ValidationDocumentGenerator(options.Output);
                    break;
                default:
                    return;
            }

            // Load the schema
            var schemaLoader = new SchemaLoader(Path.GetDirectoryName(options.PacketSchema));
            Schema packetSchema = schemaLoader.Load(options.PacketSchema);

            // Generate output from the schema.
            generator.Generate(packetSchema);
        }
Пример #3
0
        private async Task <ISchema> Create(ICacheEntry cacheEntry)
        {
            cacheEntry.SetSlidingExpiration(TimeSpan.FromHours(6));

            try
            {
                var schemaBuilder = await SchemaLoader.Load();

                var resolvers = new SchemaResolvers();

                var schema = SchemaTools.MakeExecutableSchemaWithIntrospection(
                    schemaBuilder,
                    resolvers,
                    resolvers);

                return(schema);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Пример #4
0
        public void TestGenerate()
        {
            //"usage:   DomGen {schemaPath} {outputPath} {schemaNamespace}  {classNamespace} -a(dapters)"
            //"eg:      DomGen echo.xsd Schema.cs http://sce/audio Sce.Audio -a"
            string inputPath       = ".\\Resources\\test_customized.xsd";
            string schemaNamespace = "test";
            string codeNamespace   = "testCodeNamespace";
            string className       = "TestClass";

            SchemaLoader typeLoader = new SchemaLoader();

            typeLoader.Load(inputPath);

            // Normal test
            string schemaClass = SchemaGen.Generate(typeLoader, schemaNamespace, codeNamespace, className, EmptyArray <string> .Instance);

            Validate(schemaClass, schemaNamespace, codeNamespace, className, false);

            // Test with -annotatedOnly option
            string[] args = new string[] { inputPath, "", schemaNamespace, codeNamespace, "-annotatedOnly" };
            schemaClass = SchemaGen.Generate(typeLoader, schemaNamespace, codeNamespace, className, args);
            Validate(schemaClass, schemaNamespace, codeNamespace, className, true);
        }