Esempio n. 1
0
        static async Task GenerateCodes()
        {
            BitSourceGeneratorBitConfigProvider bitConfigProvider = new BitSourceGeneratorBitConfigProvider(_bitConfigFilePath, BeingCompiledProjectName);

            BitConfig bitConfig = bitConfigProvider.GetConfiguration();

            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create())
            {
                workspace.SkipUnrecognizedProjects = workspace.LoadMetadataForReferencedProjects = true;

                workspace.WorkspaceFailed += MSBuildWorkspace_WorkspaceFailed;

                foreach (BitCodeGeneratorMapping mapping in bitConfigProvider.GetConfiguration().BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    foreach (BitTools.Core.Model.ProjectInfo proj in mapping.SourceProjects)
                    {
                        if (workspace.CurrentSolution.Projects.Any(p => p.Name == proj.Name))
                        {
                            continue; /*It's already loaded*/
                        }
                        string sourceProjetctPath = proj.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unsable to find {proj.Name}")).ExtendedSingle($"Trying to find source project {proj.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == proj.Name);

                        await workspace.OpenProjectAsync(sourceProjetctPath);
                    }

                    if (!workspace.CurrentSolution.Projects.Any(p => p.Name == mapping.DestinationProject.Name))
                    {
                        string DestProjetctPath = mapping.DestinationProject.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unsable to find {mapping.DestinationProject.Name}")).ExtendedSingle($"Trying to find destination project {mapping.DestinationProject.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == mapping.DestinationProject.Name);
                        await workspace.OpenProjectAsync(DestProjetctPath);
                    }
                }

                IProjectDtoControllersProvider           controllersProvider = new DefaultProjectDtoControllersProvider();
                IProjectDtosProvider                     dtosProvider        = new DefaultProjectDtosProvider(controllersProvider);
                IBitCodeGeneratorOrderedProjectsProvider bitCodeGeneratorOrderedProjectsProvider = new DefaultBitCodeGeneratorOrderedProjectsProvider();
                IProjectEnumTypesProvider                projectEnumTypesProvider = new DefaultProjectEnumTypesProvider(controllersProvider, dtosProvider);

                DefaultTypeScriptClientProxyGenerator tsGenerator = new DefaultTypeScriptClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                              bitConfigProvider, dtosProvider
                                                                                                              , new DefaultTypeScriptClientProxyDtoGenerator(), new DefaultTypeScriptClientContextGenerator(), controllersProvider, projectEnumTypesProvider);

                await tsGenerator.GenerateCodes(workspace);

                DefaultCSharpClientProxyGenerator csGenerator = new DefaultCSharpClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                      bitConfigProvider, controllersProvider, new DefaultCSharpClientContextGenerator());

                await csGenerator.GenerateCodes(workspace);
            }
        }
Esempio n. 2
0
        static async Task GenerateCodes(BitConfig bitConfig, BitSourceGeneratorBitConfigProvider bitConfigProvider)
        {
            using (MSBuildWorkspace workspace = MSBuildWorkspace.Create(new Dictionary <string, string>
            {
                { "TargetFramework", bitConfig.TargetFramework ?? "net6.0" }
            }))
            {
                workspace.SkipUnrecognizedProjects = workspace.LoadMetadataForReferencedProjects = true;

                workspace.WorkspaceFailed += MSBuildWorkspace_WorkspaceFailed;

                foreach (BitCodeGeneratorMapping mapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
                {
                    foreach (Bit.Tooling.Core.Model.ProjectInfo proj in mapping.SourceProjects.Union(new[] { mapping.DestinationProject }))
                    {
                        if (workspace.CurrentSolution.Projects.Any(p => proj == p))
                        {
                            continue; /*It's already loaded*/
                        }
                        string sourceProjetctPath = proj.Name == BeingCompiledProjectName ? ProjectPath : (AllProjectsPaths ?? throw new InvalidOperationException($"There is no solution project and we're unable to find {proj.Name}")).ExtendedSingle($"Trying to find project {proj.Name}", projPath => Path.GetFileNameWithoutExtension(projPath) == proj.Name);

                        await workspace.OpenProjectAsync(sourceProjetctPath).ConfigureAwait(false);
                    }
                }

                IProjectDtoControllersProvider           controllersProvider = new DefaultProjectDtoControllersProvider();
                IProjectDtosProvider                     dtosProvider        = new DefaultProjectDtosProvider(controllersProvider);
                IBitCodeGeneratorOrderedProjectsProvider bitCodeGeneratorOrderedProjectsProvider = new DefaultBitCodeGeneratorOrderedProjectsProvider();
                IProjectEnumTypesProvider                projectEnumTypesProvider = new DefaultProjectEnumTypesProvider(controllersProvider, dtosProvider);

                TypeScriptJayDataClientProxyGenerator typeScriptJayDataGeneratedCode = new TypeScriptJayDataClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                                 bitConfigProvider, dtosProvider
                                                                                                                                 , new TypeScriptJayDataClientProxyDtoGenerator(), new TypeScriptJayDataClientContextGenerator(), controllersProvider, projectEnumTypesProvider);

                await typeScriptJayDataGeneratedCode.GenerateCodes(workspace).ConfigureAwait(false);

                CSharpSimpleODataClientProxyGenerator csharpSimpleODataClientGeneratedCode = new CSharpSimpleODataClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                                       bitConfigProvider, controllersProvider, new CSharpSimpleODataClientContextGenerator(), new CSharpSimpleODataClientMetadataGenerator(), dtosProvider, projectEnumTypesProvider);

                await csharpSimpleODataClientGeneratedCode.GenerateCodes(workspace).ConfigureAwait(false);

                CSharpHttpClientProxyGenerator csharpHttpClientProxyGenerator = new CSharpHttpClientProxyGenerator(bitCodeGeneratorOrderedProjectsProvider,
                                                                                                                   bitConfigProvider, controllersProvider, new CSharpHttpClientContextGenerator(), dtosProvider, projectEnumTypesProvider);

                await csharpHttpClientProxyGenerator.GenerateCodes(workspace).ConfigureAwait(false);
            }
        }