示例#1
0
        private List <HistoryInfos> WriteCategoriesJsonFileHistory(SpRulesDataSet data)
        {
            _log.LogInformation($"Writing History Json File");

            List <HistoryInfos> infos = new List <HistoryInfos>();

            foreach (var cat in data.Categories)
            {
                if (cat.Versions.Count == 0)
                {
                    continue;
                }
                var catPath      = new CategoryPaths(_config, cat);
                var creationData = cat.Versions
                                   .OrderBy(v => v.ModifiedUtc).FirstOrDefault();

                var lastModifiedData = cat.Versions
                                       .OrderByDescending(v => v.ModifiedUtc).FirstOrDefault();
                var info = new HistoryInfos
                {
                    file               = catPath.CategoryFileRelative.Replace("\\", "/"),
                    created            = creationData.ModifiedUtc,
                    createdBy          = creationData.ModifiedByDisplayName,
                    createdByEmail     = creationData.ModifiedByEmail,
                    lastUpdated        = lastModifiedData.ModifiedUtc,
                    lastUpdatedBy      = lastModifiedData.ModifiedByName,
                    lastUpdatedByEmail = lastModifiedData.ModifiedByDisplayName
                };
                infos.Add(info);
            }

            return(infos);
        }
示例#2
0
        private void ProcessCategoryHistory(Category cat)
        {
            var catPaths = new CategoryPaths(_config, cat);

            bool isFirst  = true;
            var  versions = cat.Versions
                            .Where(v => !string.IsNullOrWhiteSpace(v.IntroText) ||
                                   !string.IsNullOrWhiteSpace(v.Content)) // filter out where we have no content
                            .OrderBy(v => v.ModifiedUtc);

            foreach (var version in versions)
            {
                var markdown = $@"---
{YamlSerializer.Serialize(new CategoryMdModel(cat))}
---
{version.IntroText}
{version.Content}

";
                using (var writer = new StreamWriter(catPaths.CategoryFileFull, false))
                {
                    writer.Write(markdown);
                    writer.Flush();
                }

                var gitComment = $"{version.VersionLabel} - {version.Comment}";
                // if the first version label isn't 1.0, the history was truncated by SharePoint. add comment.
                if (isFirst && !version.VersionLabel.StartsWith("1.0"))
                {
                    gitComment = gitComment +
                                 " Note: previous versions of this content may have been deleted by SharePoint.";
                }

                var sw = new Stopwatch();
                sw.Start();
                GitCommit(
                    _config.TargetRepository,
                    gitComment,
                    new LibGit2Sharp.Signature(version.ModifiedByName, version.ModifiedByEmail, version.ModifiedUtc),
                    new LibGit2Sharp.Signature(version.ModifiedByName, version.ModifiedByEmail, version.ModifiedUtc),
                    catPaths.CategoryFileRelative);
                sw.Stop();
                _log.LogInformation($"{version.VersionLabel} committed in {sw.Elapsed.TotalMilliseconds}ms");

                isFirst = false;
            }
        }
示例#3
0
        private void WriteCategoryPages(SpRulesDataSet data)
        {
            foreach (var cat in data.Categories)
            {
                if (!cat.Rules.Any())
                {
                    continue;
                }
                var catPaths = new CategoryPaths(_config, cat);


                if (_config.ProcessHistory)
                {
                    ProcessCategoryHistory(cat);
                }


                var html = $@"
{cat.IntroText}
{cat.Content}
";


                string markdown =
                    $@"---
{YamlSerializer.Serialize(new CategoryMdModel(cat))}
---
{ MarkdownConverter.Convert(html)}

";
                _log.LogInformation($"writing {catPaths.CategoryFileFull}");
                using (var sw = new StreamWriter(catPaths.CategoryFileFull, false))
                {
                    sw.Write(markdown);
                    sw.Flush();
                }
                if (_config.ProcessHistory)
                {
                    GitCommit(
                        _config.TargetRepository,
                        $"Extracted from Sharepoint to Git",
                        new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow),
                        new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow),
                        catPaths.CategoryFileRelative);
                }
            }
        }