コード例 #1
0
 /// <summary>
 /// Converts the specified path into a string appropriate for use as a link using default settings from the
 /// <see cref="IReadOnlySettings" />. This version should be used inside modules to ensure
 /// consistent link generation. Note that you can optionally include the host or not depending
 /// on if you want to generate host-specific links. By default, the host is not included so that
 /// sites work the same on any server including the preview server.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <param name="path">The path to generate a link for.</param>
 /// <param name="includeHost">If set to <c>true</c> the host configured in the output settings will
 /// be included in the link, otherwise the host will be omitted and only the root path will be included (default).</param>
 /// <returns>
 /// A string representation of the path suitable for a web link.
 /// </returns>
 public static string GetLink(this IExecutionContext context, string path, bool includeHost = false) =>
 GetLink(
     context,
     path == null ? null : new FilePath(path),
     includeHost ? context.String(Keys.Host) : null,
     context.DirectoryPath(Keys.LinkRoot),
     context.Bool(Keys.LinksUseHttps),
     context.Bool(Keys.LinkHideIndexPages),
     context.Bool(Keys.LinkHideExtensions));
コード例 #2
0
 /// <summary>
 /// Converts the specified path into a string appropriate for use as a link using default settings from the
 /// <see cref="IReadOnlySettings" />. This version should be used inside modules to ensure
 /// consistent link generation. Note that you can optionally include the host or not depending
 /// on if you want to generate host-specific links. By default, the host is not included so that
 /// sites work the same on any server including the preview server.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <param name="path">The path to generate a link for.</param>
 /// <param name="includeHost">If set to <c>true</c> the host configured in the output settings will
 /// be included in the link, otherwise the host will be omitted and only the root path will be included (default).</param>
 /// <returns>
 /// A string representation of the path suitable for a web link.
 /// </returns>
 public static string GetLink(this IExecutionContext context, NormalizedPath path, bool includeHost = false) =>
 GetLink(
     context,
     path,
     includeHost ? context.String(Keys.Host) : null,
     context.DirectoryPath(Keys.LinkRoot),
     context.Bool(Keys.LinksUseHttps),
     context.Bool(Keys.LinkHideIndexPages),
     context.Bool(Keys.LinkHideExtensions),
     context.Bool(Keys.LinkLowercase));
コード例 #3
0
        /// <inheritdoc />
        public IShortcodeResult Execute(KeyValuePair <string, string>[] args, string content, IDocument document, IExecutionContext context)
        {
            ConvertingDictionary arguments = args.ToDictionary(
                context,
                "Path",
                "IncludeHost",
                "Host",
                "Root",
                "Scheme",
                "UseHttps",
                "HideIndexPages",
                "HideExtensions",
                "Lowercase");

            arguments.RequireKeys("Path");

            string path = arguments.String("Path");

            if (LinkGenerator.TryGetAbsoluteHttpUri(path, out string absoluteUri))
            {
                return(context.GetShortcodeResult(absoluteUri));
            }
            FilePath filePath = new FilePath(path);

            // Use "Host" if it's provided, otherwise use Host setting if "IncludeHost" is true
            string host = arguments.String("Host", arguments.Bool("IncludeHost") ? context.String(Keys.Host) : null);

            // Use "Root" if it's provided, otherwise LinkRoot setting
            DirectoryPath root = arguments.DirectoryPath("Root", context.DirectoryPath(Keys.LinkRoot));

            // Use "Scheme" if it's provided, otherwise if "UseHttps" is true use "https" or use LinksUseHttps setting
            string scheme = arguments.String("Scheme", arguments.ContainsKey("UseHttps")
                ? (arguments.Bool("UseHttps") ? "https" : null)
                : (context.Bool(Keys.LinksUseHttps) ? "https" : null));

            // If "HideIndexPages" is provided and true use default hide pages, otherwise use default hide pages if LinkHideIndexPages is true
            string[] hidePages = arguments.ContainsKey("HideIndexPages")
                ? (arguments.Bool("HideIndexPages") ? LinkGenerator.DefaultHidePages : null)
                : (context.Bool(Keys.LinkHideIndexPages) ? LinkGenerator.DefaultHidePages : null);

            // If "HideExtensions" is provided and true use default hide extensions, otherwise use default hide extensions if LinkHideExtensions is true
            string[] hideExtensions = arguments.ContainsKey("HideExtensions")
                ? (arguments.Bool("HideExtensions") ? LinkGenerator.DefaultHideExtensions : null)
                : (context.Bool(Keys.LinkHideExtensions) ? LinkGenerator.DefaultHideExtensions : null);

            // If "Lowercase" is provided use that, otherwise use LinkLowercase setting
            bool lowercase = arguments.ContainsKey("Lowercase")
                ? arguments.Bool("Lowercase")
                : context.Bool(Keys.LinkLowercase);

            return(context.GetShortcodeResult(LinkGenerator.GetLink(filePath, host, root, scheme, hidePages, hideExtensions, lowercase)));
        }
コード例 #4
0
        /// <inheritdoc />
        protected override IEnumerable <Project> GetProjects(IExecutionContext context, IFile file)
        {
            StringWriter    log     = new StringWriter();
            AnalyzerManager manager = new AnalyzerManager(file.Path.Directory.FullPath, new AnalyzerManagerOptions
            {
                LogWriter = log
            });

            AnalyzerResult[] results = manager.Projects.Values
                                       .Select(analyzer =>
            {
                if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
                {
                    analyzer.AddBinaryLogger();
                }
                return(ReadWorkspace.CompileProjectAndTrace(analyzer, log));
            })
                                       .Where(x => x != null)
                                       .ToArray();

            AdhocWorkspace workspace = new AdhocWorkspace();

            foreach (AnalyzerResult result in results)
            {
                result.AddToWorkspace(workspace);
            }
            return(workspace.CurrentSolution.Projects);
        }
コード例 #5
0
        private Compilation AddSolutionReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation)
        {
            IEnumerable <IFile> solutionFiles = context.FileSystem.GetInputFiles(_solutionGlobs)
                                                .Where(x => x.Path.Extension == ".sln" && x.Exists);

            foreach (IFile solutionFile in solutionFiles)
            {
                Trace.Verbose($"Creating workspace solution for {solutionFile.Path.FullPath}");
                StringWriter    log     = new StringWriter();
                AnalyzerManager manager = new AnalyzerManager(
                    solutionFile.Path.FullPath,
                    new AnalyzerManagerOptions
                {
                    LogWriter = log
                });
                foreach (ProjectAnalyzer analyzer in manager.Projects.Values)
                {
                    if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
                    {
                        analyzer.WithBinaryLog();
                    }
                    ReadWorkspace.CompileProjectAndTrace(analyzer, log);
                }
                Workspace workspace = manager.GetWorkspace();
                compilation = AddProjectReferences(workspace.CurrentSolution.Projects, symbols, compilation);
            }
            return(compilation);
        }
コード例 #6
0
 /// <summary>
 /// Gets a link for the root of the site using the host and root path specified in the settings.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <returns>A link for the root of the site.</returns>
 public static string GetLink(this IExecutionContext context) =>
 GetLink(
     context,
     (NormalizedPath)null,
     context.String(Keys.Host),
     context.DirectoryPath(Keys.LinkRoot),
     context.Bool(Keys.LinksUseHttps),
     false,
     false);
コード例 #7
0
        /// <summary>
        /// Converts the specified path into a string appropriate for use as a link using default settings from the
        /// <see cref="IReadOnlySettings" />. This version should be used inside modules to ensure
        /// consistent link generation. Note that you can optionally include the host or not depending
        /// on if you want to generate host-specific links. By default, the host is not included so that
        /// sites work the same on any server including the preview server.
        /// </summary>
        /// <param name="context">The execution context.</param>
        /// <param name="path">The path to generate a link for.</param>
        /// <param name="includeHost">If set to <c>true</c> the host configured in the output settings will
        /// be included in the link, otherwise the host will be omitted and only the root path will be included (default).</param>
        /// <returns>
        /// A string representation of the path suitable for a web link.
        /// </returns>
        public static string GetLink(this IExecutionContext context, string path, bool includeHost = false)
        {
            // Return the actual URI if it's absolute
            if (path != null && LinkGenerator.TryGetAbsoluteHttpUri(path, out string absoluteUri))
            {
                return(absoluteUri);
            }

            // Otherwise process the path as a FilePath
            return(GetLink(
                       context,
                       path == null ? null : new FilePath(path),
                       includeHost ? context.String(Keys.Host) : null,
                       context.DirectoryPath(Keys.LinkRoot),
                       context.Bool(Keys.LinksUseHttps),
                       context.Bool(Keys.LinkHideIndexPages),
                       context.Bool(Keys.LinkHideExtensions),
                       context.Bool(Keys.LinkLowercase)));
        }
コード例 #8
0
 /// <summary>
 /// Converts the path into a string appropriate for use as a link, overriding one or more
 /// settings from the <see cref="IReadOnlySettings" />.
 /// </summary>
 /// <param name="context">The execution context.</param>
 /// <param name="path">The path to generate a link for.</param>
 /// <param name="host">The host to use for the link.</param>
 /// <param name="root">The root of the link. The value of this parameter is prepended to the path.</param>
 /// <param name="useHttps">If set to <c>true</c>, HTTPS will be used as the scheme for the link.</param>
 /// <param name="hideIndexPages">If set to <c>true</c>, "index.htm" and "index.html" file
 /// names will be hidden.</param>
 /// <param name="hideExtensions">If set to <c>true</c>, extensions will be hidden.</param>
 /// <returns>
 /// A string representation of the path suitable for a web link with the specified
 /// root and hidden file name or extension.
 /// </returns>
 public static string GetLink(
     this IExecutionContext context,
     NormalizedPath path,
     string host,
     DirectoryPath root,
     bool useHttps,
     bool hideIndexPages,
     bool hideExtensions) =>
 GetLink(
     context,
     path,
     host,
     root,
     useHttps,
     hideIndexPages,
     hideExtensions,
     context.Bool(Keys.LinkLowercase));
コード例 #9
0
ファイル: ReadProject.cs プロジェクト: walexzzy/Wyam
        /// <inheritdoc />
        protected override IEnumerable <Project> GetProjects(IExecutionContext context, IFile file)
        {
            StringWriter    log     = new StringWriter();
            AnalyzerManager manager = new AnalyzerManager(new AnalyzerManagerOptions
            {
                LogWriter = log
            });
            ProjectAnalyzer analyzer = manager.GetProject(file.Path.FullPath);

            if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
            {
                analyzer.WithBinaryLog();
            }
            CompileProjectAndTrace(analyzer, log);
            AdhocWorkspace workspace = analyzer.GetWorkspace();

            return(workspace.CurrentSolution.Projects);
        }
コード例 #10
0
        private Compilation AddProjectReferences(IExecutionContext context, List <ISymbol> symbols, Compilation compilation)
        {
            // Generate a single Workspace and add all of the projects to it
            StringWriter    log     = new StringWriter();
            AnalyzerManager manager = new AnalyzerManager(new AnalyzerManagerOptions
            {
                LogWriter = log
            });
            AdhocWorkspace      workspace    = new AdhocWorkspace();
            IEnumerable <IFile> projectFiles = context.FileSystem.GetInputFiles(_projectGlobs)
                                               .Where(x => x.Path.Extension == ".csproj" && x.Exists);
            List <Project> projects = new List <Project>();

            foreach (IFile projectFile in projectFiles)
            {
                Project project = workspace.CurrentSolution.Projects.FirstOrDefault(x => new FilePath(x.FilePath).Equals(projectFile.Path));
                if (project != null)
                {
                    Trace.Verbose($"Project {projectFile.Path.FullPath} was already in the workspace");
                }
                else
                {
                    Trace.Verbose($"Creating workspace project for {projectFile.Path.FullPath}");
                    ProjectAnalyzer analyzer = manager.GetProject(projectFile.Path.FullPath);
                    if (context.Bool(CodeAnalysisKeys.OutputBuildLog))
                    {
                        analyzer.AddBinaryLogger();
                    }
                    AnalyzerResult result = ReadWorkspace.CompileProjectAndTrace(analyzer, log);
                    if (result != null)
                    {
                        project = result.AddToWorkspace(workspace);
                        if (!project.Documents.Any())
                        {
                            Trace.Warning($"Project at {projectFile.Path.FullPath} contains no documents, which may be an error (check previous log output for any MSBuild warnings)");
                        }
                    }
                }
                projects.Add(project);
            }
            compilation = AddProjectReferences(projects, symbols, compilation);
            return(compilation);
        }