添加项目文件。
This commit is contained in:
70
TightWiki.Engine.Implementation/Utility/BGFGStyle.cs
Normal file
70
TightWiki.Engine.Implementation/Utility/BGFGStyle.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
namespace TightWiki.Engine.Implementation.Utility
|
||||
{
|
||||
public class BGFGStyle
|
||||
{
|
||||
public string ForegroundStyle { get; set; } = String.Empty;
|
||||
public string BackgroundStyle { get; set; } = String.Empty;
|
||||
|
||||
public BGFGStyle(string foregroundStyle, string backgroundStyle)
|
||||
{
|
||||
ForegroundStyle = foregroundStyle;
|
||||
BackgroundStyle = backgroundStyle;
|
||||
}
|
||||
|
||||
public BGFGStyle Swap()
|
||||
{
|
||||
return new BGFGStyle(BackgroundStyle, ForegroundStyle);
|
||||
}
|
||||
|
||||
public BGFGStyle()
|
||||
{
|
||||
}
|
||||
|
||||
public static readonly Dictionary<string, BGFGStyle> ForegroundStyles = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "primary", new BGFGStyle("text-primary", "") },
|
||||
{ "secondary", new BGFGStyle("text-secondary", "") },
|
||||
{ "success", new BGFGStyle("text-success", "") },
|
||||
{ "danger", new BGFGStyle("text-danger", "") },
|
||||
{ "warning", new BGFGStyle("text-warning", "") },
|
||||
{ "info", new BGFGStyle("text-info", "") },
|
||||
{ "light", new BGFGStyle("text-light", "") },
|
||||
{ "dark", new BGFGStyle("text-dark", "") },
|
||||
{ "muted", new BGFGStyle("text-muted", "") },
|
||||
{ "white", new BGFGStyle("text-white", "bg-dark") }
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, BGFGStyle> BackgroundStyles = new(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
{ "muted", new BGFGStyle("text-muted", "") },
|
||||
{ "primary", new BGFGStyle("text-white", "bg-primary") },
|
||||
{ "secondary", new BGFGStyle("text-white", "bg-secondary") },
|
||||
{ "info", new BGFGStyle("text-white", "bg-info") },
|
||||
{ "success", new BGFGStyle("text-white", "bg-success") },
|
||||
{ "warning", new BGFGStyle("bg-warning", "") },
|
||||
{ "danger", new BGFGStyle("text-white", "bg-danger") },
|
||||
{ "light", new BGFGStyle("text-black", "bg-light") },
|
||||
{ "dark", new BGFGStyle("text-white", "bg-dark") }
|
||||
};
|
||||
|
||||
public static BGFGStyle GetBackgroundStyle(string style)
|
||||
{
|
||||
if (BackgroundStyles.TryGetValue(style, out var html))
|
||||
{
|
||||
return html;
|
||||
}
|
||||
|
||||
return new BGFGStyle();
|
||||
}
|
||||
|
||||
public static BGFGStyle GetForegroundStyle(string style)
|
||||
{
|
||||
if (ForegroundStyles.TryGetValue(style, out var html))
|
||||
{
|
||||
return html;
|
||||
}
|
||||
|
||||
return new BGFGStyle();
|
||||
}
|
||||
}
|
||||
}
|
||||
50
TightWiki.Engine.Implementation/Utility/Differentiator.cs
Normal file
50
TightWiki.Engine.Implementation/Utility/Differentiator.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using System.Text;
|
||||
|
||||
namespace TightWiki.Engine.Implementation.Utility
|
||||
{
|
||||
public static class Differentiator
|
||||
{
|
||||
/// <summary>
|
||||
/// This leaves a lot to be desired.
|
||||
/// </summary>
|
||||
/// <param name="thisRev"></param>
|
||||
/// <param name="prevRev"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetComparisonSummary(string thisRev, string prevRev)
|
||||
{
|
||||
var summary = new StringBuilder();
|
||||
|
||||
var thisRevLines = thisRev.Split('\n');
|
||||
var prevRevLines = prevRev.Split('\n');
|
||||
int thisRevLineCount = thisRevLines.Length;
|
||||
int prevRevLinesCount = prevRevLines.Length;
|
||||
|
||||
int linesAdded = prevRevLines.Except(thisRevLines).Count();
|
||||
int linesDeleted = thisRevLines.Except(prevRevLines).Count();
|
||||
|
||||
if (thisRevLineCount != prevRevLinesCount)
|
||||
{
|
||||
summary.Append($"{Math.Abs(thisRevLineCount - prevRevLinesCount):N0} lines changed.");
|
||||
}
|
||||
|
||||
if (linesAdded > 0)
|
||||
{
|
||||
if (summary.Length > 0) summary.Append(' ');
|
||||
summary.Append($"{linesAdded:N0} lines added.");
|
||||
}
|
||||
|
||||
if (linesDeleted > 0)
|
||||
{
|
||||
if (summary.Length > 0) summary.Append(' ');
|
||||
summary.Append($"{linesDeleted:N0} lines deleted.");
|
||||
}
|
||||
|
||||
if (summary.Length == 0)
|
||||
{
|
||||
summary.Append($"No changes detected.");
|
||||
}
|
||||
|
||||
return summary.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
54
TightWiki.Engine.Implementation/Utility/SearchCloud.cs
Normal file
54
TightWiki.Engine.Implementation/Utility/SearchCloud.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System.Text;
|
||||
using TightWiki.Models;
|
||||
using TightWiki.Models.DataModels;
|
||||
using TightWiki.Repository;
|
||||
|
||||
namespace TightWiki.Engine.Implementation.Utility
|
||||
{
|
||||
public class SearchCloud
|
||||
{
|
||||
public static string Build(List<string> searchTokens, int? maxCount = null)
|
||||
{
|
||||
var pages = PageRepository.PageSearch(searchTokens).OrderByDescending(o => o.Score).ToList();
|
||||
|
||||
if (maxCount > 0)
|
||||
{
|
||||
pages = pages.Take((int)maxCount).ToList();
|
||||
}
|
||||
|
||||
int pageCount = pages.Count;
|
||||
int fontSize = 7;
|
||||
int sizeStep = (pageCount > fontSize ? pageCount : (fontSize * 2)) / fontSize;
|
||||
int pageIndex = 0;
|
||||
|
||||
var pageList = new List<TagCloudItem>();
|
||||
|
||||
foreach (var page in pages)
|
||||
{
|
||||
pageList.Add(new TagCloudItem(page.Name, pageIndex, "<font size=\"" + fontSize + $"\"><a href=\"{GlobalConfiguration.BasePath}/" + page.Navigation + "\">" + page.Name + "</a></font>"));
|
||||
|
||||
if ((pageIndex % sizeStep) == 0)
|
||||
{
|
||||
fontSize--;
|
||||
}
|
||||
|
||||
pageIndex++;
|
||||
}
|
||||
|
||||
var cloudHtml = new StringBuilder();
|
||||
|
||||
pageList.Sort(TagCloudItem.CompareItem);
|
||||
|
||||
cloudHtml.Append("<table align=\"center\" border=\"0\" width=\"100%\"><tr><td><p align=\"justify\">");
|
||||
|
||||
foreach (TagCloudItem tag in pageList)
|
||||
{
|
||||
cloudHtml.Append(tag.HTML + " ");
|
||||
}
|
||||
|
||||
cloudHtml.Append("</p></td></tr></table>");
|
||||
|
||||
return cloudHtml.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
55
TightWiki.Engine.Implementation/Utility/TagCloud.cs
Normal file
55
TightWiki.Engine.Implementation/Utility/TagCloud.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Text;
|
||||
using TightWiki.Library;
|
||||
using TightWiki.Models;
|
||||
using TightWiki.Models.DataModels;
|
||||
using TightWiki.Repository;
|
||||
|
||||
namespace TightWiki.Engine.Implementation.Utility
|
||||
{
|
||||
public static class TagCloud
|
||||
{
|
||||
public static string Build(string seedTag, int? maxCount)
|
||||
{
|
||||
var tags = PageRepository.GetAssociatedTags(seedTag).OrderByDescending(o => o.PageCount).ToList();
|
||||
|
||||
if (maxCount > 0)
|
||||
{
|
||||
tags = tags.Take((int)maxCount).ToList();
|
||||
}
|
||||
|
||||
int tagCount = tags.Count;
|
||||
int fontSize = 7;
|
||||
int sizeStep = (tagCount > fontSize ? tagCount : (fontSize * 2)) / fontSize;
|
||||
int tagIndex = 0;
|
||||
|
||||
var tagList = new List<TagCloudItem>();
|
||||
|
||||
foreach (var tag in tags)
|
||||
{
|
||||
tagList.Add(new TagCloudItem(tag.Tag, tagIndex, "<font size=\"" + fontSize + $"\"><a href=\"{GlobalConfiguration.BasePath}/Tag/Browse/" + NamespaceNavigation.CleanAndValidate(tag.Tag) + "\">" + tag.Tag + "</a></font>"));
|
||||
|
||||
if ((tagIndex % sizeStep) == 0)
|
||||
{
|
||||
fontSize--;
|
||||
}
|
||||
|
||||
tagIndex++;
|
||||
}
|
||||
|
||||
var cloudHtml = new StringBuilder();
|
||||
|
||||
tagList.Sort(TagCloudItem.CompareItem);
|
||||
|
||||
cloudHtml.Append("<table align=\"center\" border=\"0\" width=\"100%\"><tr><td><p align=\"justify\">");
|
||||
|
||||
foreach (TagCloudItem tag in tagList)
|
||||
{
|
||||
cloudHtml.Append(tag.HTML + " ");
|
||||
}
|
||||
|
||||
cloudHtml.Append("</p></td></tr></table>");
|
||||
|
||||
return cloudHtml.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user