Пример #1
0
        private static List <LogKeyValueItem> ScaffoldSrc(DomainProjectOptions domainProjectOptions)
        {
            if (domainProjectOptions == null)
            {
                throw new ArgumentNullException(nameof(domainProjectOptions));
            }

            if (!Directory.Exists(domainProjectOptions.PathForSrcGenerate.FullName))
            {
                Directory.CreateDirectory(domainProjectOptions.PathForSrcGenerate.FullName);
            }

            var logItems = new List <LogKeyValueItem>();

            if (domainProjectOptions.PathForSrcGenerate.Exists && domainProjectOptions.ProjectSrcCsProj.Exists)
            {
                var element = XElement.Load(domainProjectOptions.ProjectSrcCsProj.FullName);
                var originalNullableValue = SolutionAndProjectHelper.GetBoolFromNullableString(SolutionAndProjectHelper.GetNullableValueFromProject(element));

                bool hasUpdates = false;
                if (domainProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes != originalNullableValue)
                {
                    var newNullableValue = SolutionAndProjectHelper.GetNullableStringFromBool(domainProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes);
                    SolutionAndProjectHelper.SetNullableValueForProject(element, newNullableValue);
                    element.Save(domainProjectOptions.ProjectSrcCsProj.FullName);
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileUpdate", "#", $"Update domain csproj - Nullable value={newNullableValue}"));
                    hasUpdates = true;
                }

                if (!hasUpdates)
                {
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileSkip", "#", "No updates for domain csproj"));
                }
            }
            else
            {
                var projectReferences = new List <FileInfo>();
                if (domainProjectOptions.ApiProjectSrcCsProj != null)
                {
                    projectReferences.Add(domainProjectOptions.ApiProjectSrcCsProj);
                }

                logItems.Add(SolutionAndProjectHelper.ScaffoldProjFile(
                                 domainProjectOptions.ProjectSrcCsProj,
                                 false,
                                 false,
                                 domainProjectOptions.ProjectName,
                                 domainProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes,
                                 new List <string> {
                    "Microsoft.AspNetCore.App"
                },
                                 null,
                                 projectReferences,
                                 false));
            }

            ScaffoldBasicFileDomainRegistration(domainProjectOptions);

            return(logItems);
        }
Пример #2
0
        private static List <LogKeyValueItem> ScaffoldSrc(ApiProjectOptions apiProjectOptions)
        {
            if (apiProjectOptions == null)
            {
                throw new ArgumentNullException(nameof(apiProjectOptions));
            }

            if (!Directory.Exists(apiProjectOptions.PathForSrcGenerate.FullName))
            {
                Directory.CreateDirectory(apiProjectOptions.PathForSrcGenerate.FullName);
            }

            var logItems = new List <LogKeyValueItem>();

            if (apiProjectOptions.PathForSrcGenerate.Exists && apiProjectOptions.ProjectSrcCsProj.Exists)
            {
                var element = XElement.Load(apiProjectOptions.ProjectSrcCsProj.FullName);
                var originalNullableValue = SolutionAndProjectHelper.GetBoolFromNullableString(SolutionAndProjectHelper.GetNullableValueFromProject(element));

                bool hasUpdates = false;
                if (apiProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes != originalNullableValue)
                {
                    var newNullableValue = SolutionAndProjectHelper.GetNullableStringFromBool(apiProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes);
                    SolutionAndProjectHelper.SetNullableValueForProject(element, newNullableValue);
                    element.Save(apiProjectOptions.ProjectSrcCsProj.FullName);
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileUpdate", "#", $"Update API csproj - Nullable value={newNullableValue}"));
                    hasUpdates = true;
                }

                if (!hasUpdates)
                {
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileSkip", "#", "No updates for API csproj"));
                }
            }
            else
            {
                logItems.Add(SolutionAndProjectHelper.ScaffoldProjFile(
                                 apiProjectOptions.ProjectSrcCsProj,
                                 false,
                                 false,
                                 apiProjectOptions.ProjectName,
                                 apiProjectOptions.ApiOptions.Generator.UseNullableReferenceTypes,
                                 new List <string> {
                    "Microsoft.AspNetCore.App"
                },
                                 NugetPackageReferenceHelper.CreateForApiProject(),
                                 null,
                                 true));
            }

            ScaffoldBasicFileApiGenerated(apiProjectOptions);
            DeleteLegacyScaffoldBasicFileResultFactory(apiProjectOptions);
            DeleteLegacyScaffoldBasicFilePagination(apiProjectOptions);

            return(logItems);
        }
        private List <LogKeyValueItem> ScaffoldSrc()
        {
            if (!Directory.Exists(projectOptions.PathForSrcGenerate.FullName))
            {
                Directory.CreateDirectory(projectOptions.PathForSrcGenerate.FullName);
            }

            var logItems = new List <LogKeyValueItem>();

            if (projectOptions.PathForSrcGenerate.Exists && projectOptions.ProjectSrcCsProj.Exists)
            {
                var element = XElement.Load(projectOptions.ProjectSrcCsProj.FullName);
                var originalNullableValue = SolutionAndProjectHelper.GetBoolFromNullableString(SolutionAndProjectHelper.GetNullableValueFromProject(element));

                bool hasUpdates = false;
                if (projectOptions.ApiOptions.Generator.UseNullableReferenceTypes != originalNullableValue)
                {
                    var newNullableValue = SolutionAndProjectHelper.GetNullableStringFromBool(projectOptions.ApiOptions.Generator.UseNullableReferenceTypes);
                    SolutionAndProjectHelper.SetNullableValueForProject(element, newNullableValue);
                    element.Save(projectOptions.ProjectSrcCsProj.FullName);
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileUpdate", "#", $"Update API csproj - Nullable value={newNullableValue}"));
                    hasUpdates = true;
                }

                if (!hasUpdates)
                {
                    logItems.Add(new LogKeyValueItem(LogCategoryType.Debug, "FileSkip", "#", "No updates for API csproj"));
                }
            }
            else
            {
                logItems.Add(SolutionAndProjectHelper.ScaffoldProjFile(
                                 projectOptions.ProjectSrcCsProj,
                                 createAsWeb: false,
                                 createAsTestProject: false,
                                 projectOptions.ProjectName,
                                 "netcoreapp3.1",
                                 projectOptions.ApiOptions.Generator.UseNullableReferenceTypes,
                                 new List <string> {
                    "Microsoft.AspNetCore.App"
                },
                                 NugetPackageReferenceHelper.CreateForApiProject(),
                                 projectReferences: null,
                                 includeApiSpecification: true));
            }

            ScaffoldBasicFileApiGenerated();
            DeleteLegacyScaffoldBasicFileResultFactory();
            DeleteLegacyScaffoldBasicFilePagination();

            return(logItems);
        }