Beispiel #1
0
        public virtual async Task GenerateCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration();

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings.Where(m => m.GenerationType == GenerationType.CSharp))
            {
                string generatedContextName = proxyGeneratorMapping.DestinationFileName;

                StringBuilder generatedCs = new StringBuilder();

                string generatedCSContextExtension = ".cs";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => proxyGeneratorMapping.DestinationProject.IsThisProject(p));

                IList <Project> involveableProjects = _bitCodeGeneratorOrderedProjectsProvider.GetInvolveableProjects(workspace, workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp).ToList(), proxyGeneratorMapping);

                List <DtoController> dtoControllers = new List <DtoController>();

                foreach (Project p in involveableProjects)
                {
                    dtoControllers.AddRange(await _dtoControllersProvider.GetProjectDtoControllersWithTheirOperations(p));
                }

                generatedCs.AppendLine(_contextGenerator.GenerateCSharpContext(dtoControllers, proxyGeneratorMapping));

                WriteFiles(generatedCs.ToString(), generatedContextName, generatedCSContextExtension, destProject);
            }
        }
Beispiel #2
0
        public virtual IList <BitCodeGeneratorMapping> GetBitCodeGeneratorMappings(Workspace workspace, IList <string> projectNames)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (projectNames == null)
            {
                throw new ArgumentNullException(nameof(projectNames));
            }

            HashSet <BitCodeGeneratorMapping> affectedBitCodeGeneratorMappings = new HashSet <BitCodeGeneratorMapping>();

            BitConfig bitConfig = _configurationProvider.GetConfiguration(workspace.CurrentSolution.FilePath);

            foreach (string projName in projectNames)
            {
                bitConfig.BitCodeGeneratorConfigs
                .BitCodeGeneratorMappings
                .Where(cm => cm.SourceProjects.Any(sp => sp.Name == projName))
                .ToList()
                .ForEach((sm) => affectedBitCodeGeneratorMappings.Add(sm));
            }

            return(affectedBitCodeGeneratorMappings.ToList());
        }
        public virtual IList <BitCodeGeneratorMapping> GetBitCodeGeneratorMappings(Workspace workspace, Solution solution, IList <Project> projects)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            if (solution == null)
            {
                throw new ArgumentNullException(nameof(solution));
            }

            if (projects == null)
            {
                throw new ArgumentNullException(nameof(projects));
            }

            HashSet <BitCodeGeneratorMapping> affectedBitCodeGeneratorMappings = new HashSet <BitCodeGeneratorMapping>();

            BitConfig bitConfig = _configurationProvider.GetConfiguration(workspace, solution, projects);

            foreach (Project vsProject in projects)
            {
                bitConfig.BitCodeGeneratorConfigs
                .BitCodeGeneratorMappings
                .Where(cm => cm.SourceProjects.Any(sp => sp.Name == vsProject.Name))
                .ToList()
                .ForEach((sm) => affectedBitCodeGeneratorMappings.Add(sm));
            }

            return(affectedBitCodeGeneratorMappings.ToList());
        }
        public virtual Task DeleteCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration(workspace);

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings)
            {
                string contextName = proxyGeneratorMapping.DestinationFileName;

                string jsContextExtension = ".js";
                string tsContextExtension = ".d.ts";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => p.Name == proxyGeneratorMapping.DestinationProject.Name);

                DeleteFiles(contextName, jsContextExtension, destProject);
                DeleteFiles(contextName, tsContextExtension, destProject);
            }

            return(Task.CompletedTask);
        }
        public virtual async Task GenerateCodes(Workspace workspace)
        {
            if (workspace == null)
            {
                throw new ArgumentNullException(nameof(workspace));
            }

            BitConfig bitConfig = _bitConfigProvider.GetConfiguration();

            foreach (BitCodeGeneratorMapping proxyGeneratorMapping in bitConfig.BitCodeGeneratorConfigs.BitCodeGeneratorMappings.Where(m => m.GenerationType == GenerationType.TypeScriptJayDataClient))
            {
                string generatedContextName = proxyGeneratorMapping.DestinationFileName;

                StringBuilder generatedJs = new StringBuilder();
                StringBuilder generatedTs = new StringBuilder();

                string generatedJsContextExtension = ".js";
                string generatedTsContextExtension = ".d.ts";

                Project destProject = workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp)
                                      .ExtendedSingle($"Trying to find project with name: {proxyGeneratorMapping.DestinationProject.Name}", p => proxyGeneratorMapping.DestinationProject == p);

                IList <Project> involveableProjects = _bitCodeGeneratorOrderedProjectsProvider.GetInvolveableProjects(workspace, workspace.CurrentSolution.Projects.Where(p => p.Language == LanguageNames.CSharp).ToList(), proxyGeneratorMapping);

                List <Dto> dtos = new List <Dto>();

                foreach (Project p in involveableProjects)
                {
                    dtos.AddRange(await _dtosProvider.GetProjectDtos(p, involveableProjects).ConfigureAwait(false));
                }

                List <EnumType> enumTypes = new List <EnumType>();

                foreach (Project p in involveableProjects)
                {
                    enumTypes.AddRange(await _projectEnumTypesProvider.GetProjectEnumTypes(p, involveableProjects).ConfigureAwait(false));
                }

                List <DtoController> dtoControllers = new List <DtoController>();

                foreach (Project p in involveableProjects)
                {
                    dtoControllers.AddRange(await _dtoControllersProvider.GetProjectDtoControllersWithTheirOperations(p).ConfigureAwait(false));
                }

                generatedJs.AppendLine(_dtoGenerator.GenerateJavaScriptDtos(dtos, enumTypes));
                generatedJs.AppendLine(_contextGenerator.GenerateJavaScriptContext(dtoControllers, proxyGeneratorMapping));
                generatedTs.AppendLine(_dtoGenerator.GenerateTypeScriptDtos(dtos, enumTypes, proxyGeneratorMapping.TypingsPath));
                generatedTs.AppendLine(_contextGenerator.GenerateTypeScriptContext(dtoControllers, proxyGeneratorMapping));

                WriteFiles(generatedJs.ToString(), generatedContextName, generatedJsContextExtension, destProject);

                WriteFiles(generatedTs.ToString(), generatedContextName, generatedTsContextExtension, destProject);
            }
        }