예제 #1
0
        private static void WriteProject
        (
            Project project,
            IGeneratorSettings settings,
            NameContainer nc,
            ProfileDocumentation doc
        )
        {
            var folder = Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder);
            var ns     = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension);
            var dir    = project.Extension == "Core"
                ? Path.Combine(folder, ns, settings.ClassName)
                : Path.Combine(folder, ExtensionsFolder, ns);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (!Directory.Exists(Path.Combine(dir, InterfacesFolder)))
            {
                Directory.CreateDirectory(Path.Combine(dir, InterfacesFolder));
            }

            if (!Directory.Exists(Path.Combine(dir, EnumsFolder)))
            {
                Directory.CreateDirectory(Path.Combine(dir, EnumsFolder));
            }

            foreach (var interfaceDef in project.Interfaces)
            {
                var path = Path.Combine(dir, InterfacesFolder, interfaceDef.InterfaceName + ".cs");
                InterfaceWriter.WriteInterface(interfaceDef, path, ns, settings.FunctionPrefix, doc, settings.Namespace);
            }

            foreach (var enumSignature in project.Enums)
            {
                var path = Path.Combine(dir, EnumsFolder, enumSignature.Name + ".cs");
                EnumWriter.WriteEnum(enumSignature, path, ns, settings.ConstantPrefix);
            }

            if (project.Extension == "Core")
            {
                InterfaceWriter.WriteMetaInterface
                (
                    ns,
                    Path.Combine(dir, InterfacesFolder, "I" + settings.ClassName + ".cs"),
                    settings.ClassName,
                    project.Interfaces.Select(x => x.InterfaceName)
                );

                NameContainerWriter.WriteNameContainer
                (
                    Path.Combine(dir, $"{settings.APIIdentifier}LibraryNameContainer.cs"),
                    ns,
                    settings.APIIdentifier,
                    nc
                );
            }
            else
            {
                // we expect the project file to already be created
                ProjectFileWriter.WriteProjectFile(ns, dir, settings.OutputSubfolder, settings.Namespace, project.Extension != "Core");
            }

            ClassWriter.WriteMixedModeClass(project, settings, doc);
        }
예제 #2
0
        private static async Task WriteProjectAsync
        (
            Project project,
            IGeneratorSettings settings,
            NameContainer nc,
            ProfileDocumentation doc
        )
        {
            var folder = Path.Combine(Program.Arguments.OutputPath, settings.OutputSubfolder);
            var ns     = project.Extension == "Core" ? settings.Namespace : settings.ExtensionNamespace + "." + Utilities.ConvertExtensionNameToNamespace(project.Extension);
            var dir    = project.Extension == "Core"
                ? Path.Combine(folder, ns, settings.ClassName)
                : Path.Combine(folder, ExtensionsFolder, ns);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            if (!Directory.Exists(Path.Combine(dir, InterfacesFolder)))
            {
                Directory.CreateDirectory(Path.Combine(dir, InterfacesFolder));
            }

            if (!Directory.Exists(Path.Combine(dir, EnumsFolder)))
            {
                Directory.CreateDirectory(Path.Combine(dir, EnumsFolder));
            }

            await Task.WhenAll(
                project.Interfaces.Select
                (
                    x => InterfaceWriter.WriteInterfaceAsync
                    (
                        x, Path.Combine(dir, InterfacesFolder, x.InterfaceName + ".cs"), ns, settings.FunctionPrefix, doc, settings.Namespace
                    )
                ).Concat
                (
                    project.Enums.Select(
                        x => EnumWriter.WriteEnumAsync
                        (
                            x,
                            Path.Combine(dir, EnumsFolder, x.Name + ".cs"),
                            ns,
                            settings.ConstantPrefix
                        )
                        )
                )
                );

            if (project.Extension == "Core")
            {
                await InterfaceWriter.WriteMetaInterfaceAsync
                (
                    ns,
                    Path.Combine(dir, InterfacesFolder, "I" + settings.ClassName + ".cs"),
                    settings.ClassName,
                    project.Interfaces.Select(x => x.InterfaceName)
                );

                await NameContainerWriter.WriteNameContainerAsync
                (
                    Path.Combine(dir, $"{settings.APIIdentifier}LibraryNameContainer.cs"),
                    ns,
                    settings.APIIdentifier,
                    nc
                );
            }
            else
            {
                // we expect the project file to already be created
                await ProjectFileWriter.WriteProjectFileAsync(ns, dir, settings.OutputSubfolder, settings.Namespace, project.Extension != "Core");
            }

            await ClassWriter.WriteMixedModeClassAsync(project, settings, doc);
        }