当前位置: 首页>>代码示例>>C#>>正文


C# IExecutionContext.GetNewDocument方法代码示例

本文整理汇总了C#中IExecutionContext.GetNewDocument方法的典型用法代码示例。如果您正苦于以下问题:C# IExecutionContext.GetNewDocument方法的具体用法?C# IExecutionContext.GetNewDocument怎么用?C# IExecutionContext.GetNewDocument使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IExecutionContext的用法示例。


在下文中一共展示了IExecutionContext.GetNewDocument方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Execute

        public override IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            var repositoryLocation = Repository.Discover(context.InputFolder);
            if (repositoryLocation == null)
                throw new ArgumentException("No git repository found");

            using (Repository repository = new Repository(repositoryLocation))
            {
                IEnumerable<CommitInformation> data = GetCommitInformation(repository);

                var lookup = data.ToLookup(x => x.Author);

                var newDocuments = lookup.Select(x => context.GetNewDocument(new [] {
                    new KeyValuePair<string, object>("Contributor", x.Key),
                    new KeyValuePair<string, object>("CommitInformation", x.ToArray())
                })).ToArray();  // Don't do it lazy or Commit is disposed.
                return newDocuments;
            }
        }
开发者ID:st1pps,项目名称:Wyam,代码行数:19,代码来源:GitAuthors.cs

示例2: GetCommitDocuments

 protected ImmutableArray<IDocument> GetCommitDocuments(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     using (Repository repository = new Repository(GetRepositoryLocation(context)))
     {
         return repository.Commits
             .OrderByDescending(x => x.Author.When)
             .Select(x => context.GetNewDocument(new[]
             {
                 new MetadataItem(GitKeys.Sha, x.Sha),
                 new MetadataItem(GitKeys.Parents, x.Parents.Select(y => y.Sha).ToImmutableArray()),
                 new MetadataItem(GitKeys.AuthorName, x.Author.Name),
                 new MetadataItem(GitKeys.AuthorEmail, x.Author.Email),
                 new MetadataItem(GitKeys.AuthorWhen, x.Author.When),
                 new MetadataItem(GitKeys.CommitterName, x.Committer.Name),
                 new MetadataItem(GitKeys.CommitterEmail, x.Committer.Email),
                 new MetadataItem(GitKeys.CommitterWhen, x.Committer.When),
                 new MetadataItem(GitKeys.Message, x.Message),
                 new MetadataItem(GitKeys.Entries,
                     CompareTrees(repository, x).ToImmutableDictionary(y => y.Path, y => y.Status.ToString()))
             }))
             .ToImmutableArray();
     }
 }
开发者ID:martinvobr,项目名称:Wyam,代码行数:23,代码来源:GitModule.cs

示例3: Execute

 public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
 {
     return inputs.AsParallel().SelectMany(input =>
     {
         string path = _path.GetValue(input, context);
         if (path != null)
         {
             path = Path.Combine(context.InputFolder, PathHelper.NormalizePath(path));
             return GetProjects(path)
                 .AsParallel()
                 .Where(project => project != null && (_whereProject == null || _whereProject(project.Name)))
                 .SelectMany(project =>
                 {
                     context.Trace.Verbose("Read project {0}", project.Name);
                     return project.Documents
                         .AsParallel()
                         .Where(x => !string.IsNullOrWhiteSpace(x.FilePath) && File.Exists(x.FilePath)
                             && (_whereFile == null || _whereFile(x.FilePath)) && (_extensions == null || _extensions.Contains(Path.GetExtension(x.FilePath))))
                         .Select(document => {
                             context.Trace.Verbose("Read file {0}", document.FilePath);
                             return context.GetNewDocument(document.FilePath, File.OpenRead(document.FilePath), new Dictionary<string, object>
                             {
                                 {"SourceFileRoot", Path.GetDirectoryName(document.FilePath)},
                                 {"SourceFileBase", Path.GetFileNameWithoutExtension(document.FilePath)},
                                 {"SourceFileExt", Path.GetExtension(document.FilePath)},
                                 {"SourceFileName", Path.GetFileName(document.FilePath)},
                                 {"SourceFileDir", Path.GetDirectoryName(document.FilePath)},
                                 {"SourceFilePath", document.FilePath},
                                 {"SourceFilePathBase", PathHelper.RemoveExtension(document.FilePath)},
                                 {"RelativeFilePath", PathHelper.GetRelativePath(path, document.FilePath)},
                                 {"RelativeFilePathBase", PathHelper.RemoveExtension(PathHelper.GetRelativePath(path, document.FilePath))},
                                 {"RelativeFileDir", Path.GetDirectoryName(PathHelper.GetRelativePath(path, document.FilePath))}
                             });
                         });
                 });
         }
         return (IEnumerable<IDocument>)Array.Empty<IDocument>();
     });
 }
开发者ID:st1pps,项目名称:Wyam,代码行数:39,代码来源:ReadWorkspace.cs

示例4: Execute

        public override IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            ImmutableArray<IDocument> commitDocuments = GetCommitDocuments(inputs, context);

            // Build up the mapping (key = email, value = name/commits)
            Dictionary<string, Tuple<string, List<IDocument>>> contributors
                = new Dictionary<string, Tuple<string, List<IDocument>>>();
            foreach (IDocument commitDocument in commitDocuments)
            {
                string authorEmail = null;
                if (_authors)
                {
                    authorEmail = commitDocument.String(GitKeys.AuthorEmail);
                    Tuple<string, List<IDocument>> nameAndCommits;
                    if (!contributors.TryGetValue(authorEmail, out nameAndCommits))
                    {
                        nameAndCommits = new Tuple<string, List<IDocument>>(
                            commitDocument.String(GitKeys.AuthorName), new List<IDocument>());
                        contributors[authorEmail] = nameAndCommits;
                    }
                    nameAndCommits.Item2.Add(commitDocument);
                }
                if (_committers)
                {
                    string committerEmail = commitDocument.String(GitKeys.CommitterEmail);
                    if (committerEmail != authorEmail)
                    {
                        Tuple<string, List<IDocument>> nameAndCommits;
                        if (!contributors.TryGetValue(committerEmail, out nameAndCommits))
                        {
                            nameAndCommits = new Tuple<string, List<IDocument>>(
                                commitDocument.String(GitKeys.CommitterName), new List<IDocument>());
                            contributors[committerEmail] = nameAndCommits;
                        }
                        nameAndCommits.Item2.Add(commitDocument);
                    }
                }
            }

            // Iterate the contributors
            ImmutableArray<IDocument> contributorDocuments = 
                contributors.Select(x => context.GetNewDocument(new[]
                {
                    new MetadataItem(GitKeys.ContributorEmail, x.Key),
                    new MetadataItem(GitKeys.ContributorName, x.Value.Item1),
                    new MetadataItem(GitKeys.Commits, x.Value.Item2.ToImmutableArray())
                })).ToImmutableArray();

            // Outputting contributors as new documents
            if (string.IsNullOrEmpty(_contributorsMetadataKey))
            {
                return contributorDocuments;
            }

            // Outputting contributor information for each document (with only commits for that document)
            string repositoryLocation = GetRepositoryLocation(context);
            return inputs.AsParallel().Select(input =>
            {
                if (string.IsNullOrEmpty(input.Source))
                {
                    return input;
                }
                string relativePath = PathHelper.GetRelativePath(repositoryLocation, input.Source);
                if (string.IsNullOrEmpty(relativePath))
                {
                    return input;
                }
                ImmutableArray<IDocument> inputContributorDocuments = contributorDocuments
                    .Select(x => context.GetNewDocument(new []
                    {
                        new MetadataItem(GitKeys.ContributorEmail, x[GitKeys.ContributorEmail]),
                        new MetadataItem(GitKeys.ContributorName, x[GitKeys.ContributorName]),
                        new MetadataItem(GitKeys.Commits, x.Get<IReadOnlyList<IDocument>>(GitKeys.Commits)
                            .Where(y => y.Get<IReadOnlyDictionary<string, string>>(GitKeys.Entries).ContainsKey(relativePath))
                            .ToImmutableArray())
                    }))
                    .Where(x => x.Get<IReadOnlyList<IDocument>>(GitKeys.Commits).Count > 0)
                    .ToImmutableArray();
                return input.Clone(new[]
                {
                    new MetadataItem(_contributorsMetadataKey, inputContributorDocuments)
                });
            });
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:84,代码来源:GitContributors.cs

示例5: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            SearchIndexItem[] searchIndexItems = inputs
                .Select(x => _searchIndexItem.TryInvoke<SearchIndexItem>(x, context))
                .Where(x => x != null 
                    && !string.IsNullOrEmpty(x.Url) 
                    && !string.IsNullOrEmpty(x.Title) 
                    && !string.IsNullOrEmpty(x.Content))
                .ToArray();

            if( searchIndexItems.Length == 0 )
            {
                context.Trace.Warning("It's not possible to build the search index because no documents contain the necessary metadata.");
                return Array.Empty<IDocument>();
            }
            
            string[] stopwords = GetStopwords(context);
            string jsFileContent = BuildSearchIndex(searchIndexItems, stopwords);
            return new []{ context.GetNewDocument(jsFileContent) };
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:20,代码来源:SearchIndex.cs

示例6: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?><urlset xmlns=\"http://www.sitemaps.org/schemas/sitemap/0.9\">");

            foreach (IDocument input in inputs)
            {
                // Try to get a SitemapItem
                object delegateResult = _sitemapItemOrLocation(input, context);
                SitemapItem sitemapItem = delegateResult as SitemapItem;
                if (sitemapItem == null)
                {
                    string locationDelegateResult = delegateResult as string;
                    if (!string.IsNullOrWhiteSpace(locationDelegateResult))
                    {
                        sitemapItem = new SitemapItem(locationDelegateResult);
                    }
                }

                // Add a sitemap entry if we got an item and valid location
                if (!string.IsNullOrWhiteSpace(sitemapItem?.Location))
                {
                    string location = PathHelper.ToLink(sitemapItem.Location);

                    // Apply the location formatter if there is one
                    if (_locationFormatter != null)
                    {
                        location = _locationFormatter(location);
                    }

                    // Apply the hostname if defined (and the location formatter didn't already set a hostname)
                    object hostname;
                    if (input.TryGetValue(Keys.Hostname, out hostname)
                        && !location.StartsWith("http://", StringComparison.InvariantCultureIgnoreCase))
                    {
                        location = $"{hostname.ToString().TrimEnd('/')}{PathHelper.ToRootLink(location)}";
                    }

                    // Location being null signals that this document should not be included in the sitemap
                    if (!string.IsNullOrWhiteSpace(location))
                    {
                        sb.Append("<url>");
                        sb.AppendFormat("<loc>{0}</loc>", PathHelper.ToLink(location));

                        if (sitemapItem.LastModUtc.HasValue)
                        {
                            sb.AppendFormat("<lastmod>{0}</lastmod>", sitemapItem.LastModUtc.Value.ToString("yyyy-MM-ddTHH:mm:ssZ"));
                        }

                        if (sitemapItem.ChangeFrequency.HasValue)
                        {
                            sb.AppendFormat("<changefreq>{0}</changefreq>", ChangeFrequencies[(int)sitemapItem.ChangeFrequency.Value]);
                        }

                        if (sitemapItem.Priority.HasValue)
                        {
                            sb.AppendFormat(CultureInfo.InvariantCulture, "<priority>{0}</priority>", sitemapItem.Priority.Value);
                        }

                        sb.Append("</url>");
                    }
                }
            }

            // Always output the sitemap document, even if it's empty
            sb.Append("</urlset>");
            return new[] { context.GetNewDocument(sb.ToString()) };
        }
开发者ID:martinvobr,项目名称:Wyam,代码行数:68,代码来源:Sitemap.cs

示例7: Execute

        public IEnumerable<IDocument> Execute(IReadOnlyList<IDocument> inputs, IExecutionContext context)
        {
            // If we're using a pattern, just use an empty document
            if (_searchPattern != null)
            {
                inputs = new[] { context.GetNewDocument((string)null) };
            }

            return inputs.AsParallel().SelectMany(input =>
            {
                string path = _searchPattern ?? _sourcePath.Invoke<string>(input, context);
                if (path != null)
                {
                    bool isPathUnderInputFolder = false;

                    if (!Path.IsPathRooted(path))
                    {
                        path = PathHelper.CombineToFullPath(context.InputFolder, path);
                        isPathUnderInputFolder = path.StartsWith(context.InputFolder);
                    }
                    
                    string fileRoot = Path.GetDirectoryName(path);
                    if (fileRoot != null && Directory.Exists(fileRoot))
                    {
                        return Directory.EnumerateFiles(fileRoot, Path.GetFileName(path), _searchOption)
                            .AsParallel()
                            .Where(x => (_predicate == null || _predicate(x)) && (_withoutExtensions == null || !_withoutExtensions.Contains(Path.GetExtension(x))))
                            .Select(file =>
                            {
                                string destination = null;

                                if(_destinationPath == null)
                                {
                                    if(file != null)
                                    {
                                        string relativePath = isPathUnderInputFolder ? PathHelper.GetRelativePath(context.InputFolder, Path.GetDirectoryName(file)) : "";
                                        destination = Path.Combine(context.OutputFolder, relativePath, Path.GetFileName(file));
                                    }
                                }
                                else
                                {
                                    destination = _destinationPath(file);
                                }

                                if (!string.IsNullOrWhiteSpace(destination))
                                {
                                    string destinationDirectory = Path.GetDirectoryName(destination);
                                    if (destinationDirectory != null && !Directory.Exists(destinationDirectory))
                                    {
                                        Directory.CreateDirectory(destinationDirectory);
                                    }
                                    SafeIOHelper.Copy(file, destination, true);
                                    context.Trace.Verbose("Copied file {0} to {1}", file, destination);
                                    return input.Clone(new MetadataItems
                                    {
                                        { Keys.SourceFilePath, file },
                                        { Keys.DestinationFilePath, destination }
                                    });
                                }

                                return null;
                            })
                            .Where(x => x != null);
                    }
                }
                return (IEnumerable<IDocument>)Array.Empty<IDocument>();
            });
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:68,代码来源:CopyFiles.cs

示例8: Execute


//.........这里部分代码省略.........
            var channel = new XElement("channel",
                new XElement("title", _feedTitle),
                new XElement("description", _feedDescription),
                new XElement("link", _siteRoot),
                new XElement(atomNamespace + "link",
                    new XAttribute("href", rssAbsolutePath),
                    new XAttribute("rel", "self")
                ),
                new XElement("lastBuildDate", DateTimeHelper.ToRssDate(DateTime.Now))
            );

            if (_language != null)
            {
                channel.Add(new XElement("language", _language));
            }

            foreach (var input in inputs)
            {
                var item = new XElement("item");

                object title;
                bool hasTitle = input.TryGetValue(_titleMetaKey, out title);
                item.Add(new XElement("title", hasTitle ? title : "Untitled"));

                string link = null;
                {
                    object linkTemp = null;
                    if (input.TryGetValue("RssItemUrl", out linkTemp))
                    {
                        link = PathHelper.ToRootLink((string)linkTemp);
                    }
                    else
                    {
                        linkTemp = null;
                        if (input.TryGetValue("RelativeFilePath", out linkTemp))
                        {
                            link = PathHelper.ToRootLink((string)linkTemp);
                            if (_linkCustomizerDelegate != null)
                                link = _linkCustomizerDelegate(link);
                        }
                    }
                }

                //foreach (var m in input.Metadata)
                //{
                //    Console.WriteLine("{0}: {1}", m.Key, m.Value);
                //}

                if (string.IsNullOrWhiteSpace(link))
                {
                    throw new ArgumentException("Required RssItemUrl or RelativeFilePath was not found in metadata in document " + input.Source);
                }

                item.Add(new XElement("link", PathHelper.ToLink(_siteRoot + link)));

                object description = null;
                bool hasDescription = input.TryGetValue(_descriptionMetaKey, out description);
                item.Add(new XElement("description", hasDescription ? description : "No description"));

                object pubDate = null;
                if (input.TryGetValue(_pubDateMetaKey, out pubDate))
                {
                    item.Add(new XElement("pubDate", DateTimeHelper.ToRssDate(DateTime.Parse((string)pubDate))));
                }

                if (_appendGuid)
                {
                    if (_assumePermalinks)
                    {
                        item.Add(new XElement("guid", link));
                    }
                    else if (string.IsNullOrWhiteSpace(input.Source))
                    {
                        context.Trace.Warning("Cannot generate RSS item guid for document " + input.Source + " because document Source is not valid.");
                    }
                    else
                    {
                        item.Add(new XElement("guid", GuidHelper.ToGuid(input.Source).ToString(), new XAttribute("isPermaLink", false)));
                    }
                }

                channel.Add(item);   
            }

            rss.Add(rssRoot);
            rssRoot.Add(channel);

            // rss.ToString() doesn't return XML declaration
            var outText = new StringBuilder();
            using (var stream = new UTF8StringWriter(outText))
            {
                rss.Save(stream);
            }

            return new IDocument[] { context.GetNewDocument(outText.ToString(), new KeyValuePair<string, object>[] {
                new KeyValuePair<string, object>("IsRssFeed", true),
                new KeyValuePair<string, object>("RelativeFilePath", _outputRssFilePath),
                new KeyValuePair<string, object>("WritePath", _outputRssFilePath)
            })};
        }
开发者ID:Chandu,项目名称:Wyam,代码行数:101,代码来源:Rss.cs


注:本文中的IExecutionContext.GetNewDocument方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。