예제 #1
0
        private static int GenerateMappint(Mapping mapping, Options opt)
        {
            var tg = new TypeGenerator();

            var source = tg.Generate(mapping.SourceInfo.PhysicalSchema, "SourceNs");
            var target = tg.Generate(mapping.TargetInfo.PhysicalSchema, "TargetNs");

            mapping.RebuildRelationships();
            var mappings = new Dictionary <int, TypeMapping>();

            var sourceItem = mapping.SourceInfo.Roots[0];
            var targetItem = mapping.TargetInfo.Roots[0];

            var resolver = new TypeResolver();

            resolver.Resolve(mappings, source.RootType, target.RootType, sourceItem, targetItem, mapping);

            var generator = new Generator();
            var sb        = new StringBuilder();
            var writer    = new StringWriter(sb);

            generator.Generate(writer, mappings, source.RootType, target.RootType, mapping.TargetInfo.Roots[0], mapping);

            var entrypointGen = new EntryPointGenerator();

            var azureWriter = new OutputWriter();
            var codeGen     = new List <CodeGenerationResult>()
            {
                source, target
            };

            azureWriter.WriteOutput(opt.OutputDirectory, sb.ToString(), entrypointGen.Generate(source.RootType, target.RootType, codeGen), codeGen);

            return(0);
        }
        public void CanGenerateCodeForNestedMapping()
        {
            var tg = new TypeGenerator();

            var mapping = JsonConvert.DeserializeObject <Mapping>(File.ReadAllText(TestBase.TestFiles.AToXMapping));

            var source = tg.Generate(mapping.SourceInfo.PhysicalSchema, "SourceNs");
            var target = tg.Generate(mapping.TargetInfo.PhysicalSchema, "TargetNs");

            output.WriteLine(source.Code);

            mapping.RebuildRelationships();
            var mappings = new Dictionary <int, TypeMapping>();

            var sourceItem = mapping.SourceInfo.Roots[0];
            var targetItem = mapping.TargetInfo.Roots[0];

            var resolver = new TypeResolver();

            resolver.Resolve(mappings, source.RootType, target.RootType, sourceItem, targetItem, mapping);

            var generator = new Generator();
            var sb        = new StringBuilder();
            var writer    = new StringWriter(sb);

            generator.Generate(writer, mappings, source.RootType, target.RootType, mapping.TargetInfo.Roots[0], mapping);

            var entrypointGen = new EntryPointGenerator();

            var azureWriter = new OutputWriter();
            var codeGen     = new List <CodeGenerationResult>()
            {
                source, target
            };
            var basePath =
                @"I:\AzureFunctions\src\azure-webjobs-sdk-script\sample\HttpTrigger-MappingDemo"; // @"F:\temp\azure";

            azureWriter.WriteOutput(basePath, sb.ToString(), entrypointGen.Generate(source.RootType, target.RootType, codeGen), codeGen);

            Assert.True(File.Exists(Path.Combine(basePath, "bin\\Source.dll")));
            Assert.True(File.Exists(Path.Combine(basePath, "bin\\Target.dll")));
            Assert.True(File.Exists(Path.Combine(basePath, "function.json")));
            Assert.True(File.Exists(Path.Combine(basePath, "run.csx")));
        }