コード例 #1
0
        // Note: "peer" is somewhat of a misnomer, not all of the "peer" files are in the same directory as the layout file.
        internal static bool TryGetLayoutPeerFiles(IFileSystem fileSystem, string rootPath, IdentityGeneratorTemplateModel templateModel, out IReadOnlyList <IdentityGeneratorFile> layoutPeerFiles)
        {
            string viewImportsFileNameWithExtension = string.Concat(_ViewImportFileName, ".cshtml");

            if (fileSystem.FileExists(Path.Combine(rootPath, templateModel.SupportFileLocation, viewImportsFileNameWithExtension)))
            {
                layoutPeerFiles = null;
                return(false);
            }

            const string sharedDirName = "Shared";
            string       outputDirectory;

            string checkSupportFileLocation = templateModel.SupportFileLocation;

            if (checkSupportFileLocation.EndsWith("\\") || checkSupportFileLocation.EndsWith("/"))
            {
                checkSupportFileLocation = checkSupportFileLocation.Substring(0, checkSupportFileLocation.Length - 1);
            }

            if (checkSupportFileLocation.EndsWith(sharedDirName))
            {
                int directoryLengthWithoutShared = checkSupportFileLocation.Length - sharedDirName.Length;
                outputDirectory = checkSupportFileLocation.Substring(0, directoryLengthWithoutShared);
            }
            else
            {
                outputDirectory = templateModel.SupportFileLocation;
            }

            List <IdentityGeneratorFile> peerFiles = new List <IdentityGeneratorFile>();

            IdentityGeneratorFile layoutPeerViewImportsFile = new IdentityGeneratorFile()
            {
                Name            = "_ViewImports",
                SourcePath      = "SupportPages._ViewImports.cshtml",
                OutputPath      = Path.Combine(outputDirectory, viewImportsFileNameWithExtension),
                IsTemplate      = true,
                ShouldOverWrite = OverWriteCondition.Never
            };

            peerFiles.Add(layoutPeerViewImportsFile);

            IdentityGeneratorFile layoutPeerViewStart = new IdentityGeneratorFile()
            {
                Name            = "_ViewStart",
                SourcePath      = "SupportPages._ViewStart.cshtml",
                OutputPath      = Path.Combine(outputDirectory, "_ViewStart.cshtml"),
                IsTemplate      = true,
                ShowInListFiles = false,
                ShouldOverWrite = OverWriteCondition.Never
            };

            peerFiles.Add(layoutPeerViewStart);

            layoutPeerFiles = peerFiles;
            return(true);
        }
コード例 #2
0
        // Returns true if the template file exists in it's output path, or in an alt path (if any are specified)
        private bool DoesFileExist(IdentityGeneratorFile template, string projectDir)
        {
            string outputPath = Path.Combine(projectDir, template.OutputPath);

            if (_fileSystem.FileExists(outputPath))
            {
                return(true);
            }

            return(template.AltPaths.Any(altPath => _fileSystem.FileExists(Path.Combine(projectDir, altPath))));
        }
コード例 #3
0
        // Look for a cookie consent file in the same location as the layout file. If there isn't one, setup the config to add one there.
        internal static bool TryGetCookieConsentPartialFile(IFileSystem fileSystem, string rootPath, IdentityGeneratorTemplateModel templateModel, out IdentityGeneratorFile cookieConsentPartialConfig)
        {
            string layoutDir = Path.GetDirectoryName(templateModel.Layout);

            string cookieConsentCheckLocation = Path.Combine(layoutDir, _CookieConsentPartialFileName);

            if (fileSystem.FileExists(cookieConsentCheckLocation))
            {
                cookieConsentPartialConfig = null;
                return(false);
            }

            cookieConsentPartialConfig = new IdentityGeneratorFile()
            {
                Name            = "_CookieConsentPartial",
                SourcePath      = "SupportPages._CookieConsentPartial.cshtml",
                OutputPath      = Path.Combine(layoutDir, _CookieConsentPartialFileName),
                IsTemplate      = false,
                ShowInListFiles = false,
                ShouldOverWrite = OverWriteCondition.Never
            };
            return(true);
        }
コード例 #4
0
        internal static IdentityGeneratorFile[] GetFilesToGenerate(IEnumerable <string> names, IdentityGeneratorTemplateModel templateModel)
        {
            if (templateModel == null)
            {
                throw new ArgumentNullException(nameof(templateModel));
            }

            List <IdentityGeneratorFile> filesToGenerate = GetDataModelFiles(templateModel);

            if (templateModel.GenerateLayout)
            {
                IdentityGeneratorFile layout = new IdentityGeneratorFile()
                {
                    Name            = "_Layout",
                    SourcePath      = "_Layout.cshtml",
                    OutputPath      = Path.Combine(templateModel.SupportFileLocation, "_Layout.cshtml"),
                    IsTemplate      = true,
                    ShowInListFiles = false
                };
                filesToGenerate.Add(layout);
            }
            else
            {
                IdentityGeneratorFile validationScriptsPartial = new IdentityGeneratorFile()
                {
                    Name            = "_ValidationScriptsPartial",
                    SourcePath      = "Pages/_ValidationScriptsPartial.cshtml",
                    OutputPath      = "Areas/Identity/Pages/_ValidationScriptsPartial.cshtml",
                    IsTemplate      = false,
                    ShouldOverWrite = OverWriteCondition.Never
                };
                filesToGenerate.Add(validationScriptsPartial);
            }

            if (!string.IsNullOrEmpty(templateModel.Layout))
            {
                filesToGenerate.Add(ViewStart);

                // if there's a layout file, generate a _ValidationScriptsPartial.cshtml in the same place.
                IdentityGeneratorFile layoutPeerValidationScriptsPartial = new IdentityGeneratorFile()
                {
                    Name            = "_ValidationScriptsPartial",
                    SourcePath      = "Pages/_ValidationScriptsPartial.cshtml",
                    OutputPath      = Path.Combine(templateModel.SupportFileLocation, "_ValidationScriptsPartial.cshtml"),
                    IsTemplate      = false,
                    ShouldOverWrite = OverWriteCondition.Never
                };
                filesToGenerate.Add(layoutPeerValidationScriptsPartial);
            }

            if (!templateModel.UseDefaultUI)
            {
                if (names != null && names.Any())
                {
                    foreach (var name in names)
                    {
                        filesToGenerate.AddRange(_config.NamedFileConfig[name]);
                    }
                }
                else
                {
                    filesToGenerate.AddRange(_config.NamedFileConfig.SelectMany(f => f.Value));
                }
            }

            if (!templateModel.HasExistingNonEmptyWwwRoot)
            {
                filesToGenerate.AddRange(_config.NamedFileConfig["WwwRoot"]);
            }

            filesToGenerate.Add(IdentityHostingStartup);
            filesToGenerate.Add(ReadMe);

            return(filesToGenerate.Distinct(new IdentityGeneratorFileComparer()).ToArray());
        }