添加项目文件。
This commit is contained in:
BIN
DummyPageGenerator/Data/words.db
Normal file
BIN
DummyPageGenerator/Data/words.db
Normal file
Binary file not shown.
46
DummyPageGenerator/DummyPageGenerator.csproj
Normal file
46
DummyPageGenerator/DummyPageGenerator.csproj
Normal file
@@ -0,0 +1,46 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)'=='Release'">
|
||||
<DebugSymbols>False</DebugSymbols>
|
||||
<DebugType>None</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="appsettings.Development.json" />
|
||||
<None Remove="appsettings.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
<Content Include="appsettings.json">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="10.0.0" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="9.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.1" />
|
||||
<PackageReference Include="NTDLS.DelegateThreadPooling" Version="1.5.12" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\TightWiki.Engine.Implementation\TightWiki.Engine.Implementation.csproj" />
|
||||
<ProjectReference Include="..\TightWiki.Engine\TightWiki.Engine.csproj" />
|
||||
<ProjectReference Include="..\TightWiki.Models\TightWiki.Models.csproj" />
|
||||
<ProjectReference Include="..\TightWiki.Repository\TightWiki.Repository.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
399
DummyPageGenerator/PageGenerator.cs
Normal file
399
DummyPageGenerator/PageGenerator.cs
Normal file
@@ -0,0 +1,399 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using NTDLS.Helpers;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using TightWiki.Engine.Library.Interfaces;
|
||||
using TightWiki.Library;
|
||||
using TightWiki.Models;
|
||||
using TightWiki.Models.DataModels;
|
||||
using TightWiki.Repository;
|
||||
|
||||
namespace DummyPageGenerator
|
||||
{
|
||||
internal class PageGenerator
|
||||
{
|
||||
private readonly object _lockObject = new();
|
||||
private List<Page> _pagePool;
|
||||
private readonly Random _random;
|
||||
private readonly List<string> _namespaces;
|
||||
private readonly List<string> _tags;
|
||||
private readonly List<string> _fileNames;
|
||||
private List<string> _recentPageNames = new();
|
||||
private readonly UserManager<IdentityUser> _userManager;
|
||||
private readonly List<AccountProfile> _users;
|
||||
|
||||
public List<AccountProfile> Users => _users;
|
||||
public Random Random => _random;
|
||||
|
||||
public PageGenerator(UserManager<IdentityUser> userManager)
|
||||
{
|
||||
_userManager = userManager;
|
||||
_random = new Random();
|
||||
|
||||
_namespaces = PageRepository.GetAllNamespaces();
|
||||
_tags = WordsRepository.GetRandomWords(250);
|
||||
_fileNames = WordsRepository.GetRandomWords(50);
|
||||
_pagePool = PageRepository.GetAllPages();
|
||||
|
||||
if (_namespaces.Count < 250)
|
||||
{
|
||||
_namespaces.AddRange(WordsRepository.GetRandomWords(250));
|
||||
}
|
||||
|
||||
_users = UsersRepository.GetAllUsers();
|
||||
|
||||
if (_users.Count < 1124)
|
||||
{
|
||||
for (int i = 0; i < 1124 - _users.Count; i++)
|
||||
{
|
||||
string emailAddress = WordsRepository.GetRandomWords(1).First() + "@" + WordsRepository.GetRandomWords(1).First() + ".com";
|
||||
CreateUserAndProfile(emailAddress);
|
||||
}
|
||||
|
||||
_users = UsersRepository.GetAllUsers();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetRandomUnusedAccountName()
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
var randomAccountName = string.Join(" ", WordsRepository.GetRandomWords(2));
|
||||
if (UsersRepository.DoesProfileAccountExist(Navigation.Clean(randomAccountName)) == false)
|
||||
{
|
||||
return randomAccountName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a user and the associated profile with claims and such.
|
||||
/// </summary>
|
||||
/// <param name="emailAddress"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public void CreateUserAndProfile(string emailAddress)
|
||||
{
|
||||
var user = new IdentityUser()
|
||||
{
|
||||
UserName = emailAddress,
|
||||
Email = emailAddress
|
||||
};
|
||||
|
||||
var result = _userManager.CreateAsync(user, WordsRepository.GetRandomWords(1).First() + Guid.NewGuid().ToString()).Result;
|
||||
if (!result.Succeeded)
|
||||
{
|
||||
throw new Exception(string.Join("\r\n", result.Errors.Select(o => o.Description)));
|
||||
}
|
||||
|
||||
var userId = _userManager.GetUserIdAsync(user).Result;
|
||||
var membershipConfig = ConfigurationRepository.GetConfigurationEntryValuesByGroupName("Membership");
|
||||
|
||||
UsersRepository.CreateProfile(Guid.Parse(userId), GetRandomUnusedAccountName());
|
||||
|
||||
var claimsToAdd = new List<Claim>
|
||||
{
|
||||
new (ClaimTypes.Role, membershipConfig.Value<string>("Default Signup Role").EnsureNotNull()),
|
||||
new ("timezone", membershipConfig.Value<string>("Default TimeZone").EnsureNotNull()),
|
||||
new (ClaimTypes.Country, membershipConfig.Value<string>("Default Country").EnsureNotNull()),
|
||||
new ("language", membershipConfig.Value<string>("Default Language").EnsureNotNull()),
|
||||
};
|
||||
|
||||
SecurityRepository.UpsertUserClaims(_userManager, user, claimsToAdd);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a paragraph/sentence structure.
|
||||
/// </summary>
|
||||
/// <param name="words"></param>
|
||||
/// <returns></returns>
|
||||
private string GetParagraph(int words)
|
||||
{
|
||||
using var client = new HttpClient();
|
||||
|
||||
var response = client.GetAsync($"https://textsauce.com/api/Paragraph/English/{words}").Result;
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
return response.Content.ReadAsStringAsync().Result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a paragraph/sentence structure with links and wiki markup.
|
||||
/// </summary>
|
||||
/// <param name="wordCount"></param>
|
||||
/// <returns></returns>
|
||||
private string GenerateWikiParagraph(int wordCount)
|
||||
{
|
||||
var paragraph = GetParagraph(wordCount);
|
||||
var tokens = paragraph.Split(' ');
|
||||
|
||||
int replacementCount = _random.Next(2, 10);
|
||||
|
||||
for (int r = 0; r < replacementCount; r++)
|
||||
{
|
||||
var token = tokens[_random.Next(0, tokens.Length)];
|
||||
|
||||
switch (_random.Next(0, 7))
|
||||
{
|
||||
case 2: //Dead link.
|
||||
paragraph = paragraph.Replace(token, $"[[{token}]]");
|
||||
break;
|
||||
case 4: //Wiki markup.
|
||||
paragraph = paragraph.Replace(token, AddWikiMarkup(token));
|
||||
break;
|
||||
case 6: //Good link.
|
||||
var recentPage = GetRandomRecentPageName();
|
||||
if (recentPage != null)
|
||||
{
|
||||
paragraph = paragraph.Replace(token, $"[[{recentPage}]]");
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return paragraph;
|
||||
}
|
||||
|
||||
private string? GetRandomRecentPageName()
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
if (_recentPageNames.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_recentPageNames.Count > 200) //Shuffle and limit the recent page names.
|
||||
{
|
||||
_recentPageNames = ShuffleList(_recentPageNames).Take(100).ToList();
|
||||
}
|
||||
|
||||
return _recentPageNames[_random.Next(0, _recentPageNames.Count)];
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetRandomRecentPageNames(int count)
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
if (_recentPageNames.Count > 200) //Shuffle and limit the recent page names.
|
||||
{
|
||||
_recentPageNames = ShuffleList(_recentPageNames).Take(100).ToList();
|
||||
}
|
||||
|
||||
var pageNames = new List<string>();
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
pageNames.Add(_recentPageNames[_random.Next(0, _recentPageNames.Count)]);
|
||||
}
|
||||
return pageNames;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddRecentPageName(string pageName)
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
_recentPageNames.Add(pageName);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random page on the wiki.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
public void GeneratePage(ITightEngine engine, Guid userId)
|
||||
{
|
||||
try
|
||||
{
|
||||
Console.WriteLine($"{userId} is creating a page.");
|
||||
|
||||
var ns = _namespaces[_random.Next(_namespaces.Count)];
|
||||
|
||||
var pageName = ns + " :: " + string.Join(" ", WordsRepository.GetRandomWords(3));
|
||||
|
||||
AddRecentPageName(pageName);
|
||||
|
||||
var body = new StringBuilder();
|
||||
|
||||
body.AppendLine($"##title ##Tag(" + string.Join(' ', ShuffleList(_tags).Take(_random.Next(1, 4))) + ")");
|
||||
body.AppendLine($"##toc");
|
||||
|
||||
body.AppendLine($"==Overview");
|
||||
body.AppendLine(GenerateWikiParagraph(_random.Next(50, 100)));
|
||||
body.AppendLine("\r\n");
|
||||
|
||||
body.AppendLine($"==Revision Section");
|
||||
body.AppendLine($"This is here for the workload generator to easily modify the page.");
|
||||
body.AppendLine($"PLACEHOLDER_FOR_REVISION_TEXT_BEGIN\r\nPLACEHOLDER_FOR_REVISION_TEXT_END\r\n");
|
||||
|
||||
var textWithLinks = WordsRepository.GetRandomWords(_random.Next(5, 10));
|
||||
textWithLinks.AddRange(GetRandomRecentPageNames(_random.Next(1, 2)).Select(o => $"[[{o}]]"));
|
||||
|
||||
if (_random.Next(100) >= 95)
|
||||
{
|
||||
//Add dead links (missing pages).
|
||||
textWithLinks.AddRange(WordsRepository.GetRandomWords(_random.Next(1, 2)).Select(o => $"[[{o}]]"));
|
||||
}
|
||||
|
||||
body.AppendLine($"==See Also");
|
||||
body.AppendLine(string.Join(' ', ShuffleList(textWithLinks)));
|
||||
body.AppendLine("\r\n");
|
||||
|
||||
body.AppendLine($"==Related");
|
||||
body.AppendLine($"##related");
|
||||
body.AppendLine("\r\n");
|
||||
|
||||
var page = new Page()
|
||||
{
|
||||
Name = pageName,
|
||||
Body = body.ToString(),
|
||||
CreatedByUserId = userId,
|
||||
ModifiedByUserId = userId,
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
ModifiedDate = DateTime.UtcNow,
|
||||
Description = string.Join(' ', WordsRepository.GetRandomWords(_random.Next(3, 5))),
|
||||
};
|
||||
int newPageId = TightWiki.Engine.Implementation.Helpers.UpsertPage(engine, page);
|
||||
|
||||
if (_random.Next(100) >= 70)
|
||||
{
|
||||
var fileName = _fileNames[_random.Next(_fileNames.Count)] + ".txt"; ;
|
||||
var fileData = Encoding.UTF8.GetBytes(page.Body);
|
||||
AttachFile(newPageId, userId, fileName, fileData);
|
||||
}
|
||||
|
||||
InsertPagePool(page);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private Page GetRandomPage()
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
return _pagePool[_random.Next(0, _pagePool.Count)];
|
||||
}
|
||||
}
|
||||
|
||||
private void InsertPagePool(Page page)
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
_pagePool.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifies a random page on the wiki.
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
public void ModifyRandomPages(ITightEngine engine, Guid userId)
|
||||
{
|
||||
var pageToModify = GetRandomPage();
|
||||
|
||||
Console.WriteLine($"{userId} is modifying page: {pageToModify.Id}.");
|
||||
|
||||
|
||||
AddRecentPageName(pageToModify.Name);
|
||||
|
||||
string beginTag = "PLACEHOLDER_FOR_REVISION_TEXT_BEGIN";
|
||||
string endTag = "PLACEHOLDER_FOR_REVISION_TEXT_END";
|
||||
|
||||
int beginIndex = pageToModify.Body.IndexOf(beginTag);
|
||||
int endIndex = pageToModify.Body.IndexOf(endTag);
|
||||
|
||||
if (beginIndex > 0 && endIndex > beginIndex)
|
||||
{
|
||||
string topText = pageToModify.Body.Substring(0, beginIndex + beginTag.Length);
|
||||
string bottomText = pageToModify.Body.Substring(endIndex);
|
||||
|
||||
pageToModify.Body = topText.Trim()
|
||||
+ "\r\n" + GenerateWikiParagraph(_random.Next(10, 20))
|
||||
+ "\r\n" + bottomText.Trim();
|
||||
pageToModify.ModifiedByUserId = userId;
|
||||
pageToModify.ModifiedByUserId = userId;
|
||||
TightWiki.Engine.Implementation.Helpers.UpsertPage(engine, pageToModify);
|
||||
|
||||
if (_random.Next(100) >= 90)
|
||||
{
|
||||
var fileName = _fileNames[_random.Next(_fileNames.Count)] + ".txt";
|
||||
var fileData = Encoding.UTF8.GetBytes(pageToModify.Body);
|
||||
AttachFile(pageToModify.Id, userId, fileName, fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attaches a file to a wiki page.
|
||||
/// </summary>
|
||||
/// <param name="pageId"></param>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="fileData"></param>
|
||||
private void AttachFile(int pageId, Guid userId, string fileName, byte[] fileData)
|
||||
{
|
||||
if (fileData.Length > GlobalConfiguration.MaxAttachmentFileSize)
|
||||
{
|
||||
throw new Exception("Could not save the attached file, too large");
|
||||
}
|
||||
|
||||
PageFileRepository.UpsertPageFile(new PageFileAttachment()
|
||||
{
|
||||
Data = fileData,
|
||||
CreatedDate = DateTime.UtcNow,
|
||||
PageId = pageId,
|
||||
Name = fileName,
|
||||
FileNavigation = Navigation.Clean(fileName),
|
||||
Size = fileData.Length,
|
||||
ContentType = Utility.GetMimeType(fileName)
|
||||
}, userId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a shuffled version of the input list.
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="list"></param>
|
||||
/// <returns></returns>
|
||||
private List<T> ShuffleList<T>(List<T> list)
|
||||
{
|
||||
var newList = new List<T>(list);
|
||||
var rand = new Random();
|
||||
int n = newList.Count;
|
||||
while (n > 1)
|
||||
{
|
||||
n--;
|
||||
int k = _random.Next(n + 1);
|
||||
T value = newList[k];
|
||||
newList[k] = newList[n];
|
||||
newList[n] = value;
|
||||
}
|
||||
return newList;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds some random wiki text to a word.
|
||||
/// </summary>
|
||||
/// <param name="text"></param>
|
||||
/// <returns></returns>
|
||||
private string AddWikiMarkup(string text)
|
||||
{
|
||||
switch (_random.Next(0, 5))
|
||||
{
|
||||
case 1:
|
||||
return $"//{text}//";
|
||||
case 2:
|
||||
return $"~~{text}~~";
|
||||
case 3:
|
||||
return $"__{text}__";
|
||||
case 4:
|
||||
return $"!!{text}!!";
|
||||
default:
|
||||
return text;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
120
DummyPageGenerator/Program.cs
Normal file
120
DummyPageGenerator/Program.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Dapper;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using TightWiki.Engine;
|
||||
using TightWiki.Engine.Implementation;
|
||||
using TightWiki.Engine.Library.Interfaces;
|
||||
using TightWiki.Library;
|
||||
using TightWiki.Repository;
|
||||
|
||||
namespace DummyPageGenerator
|
||||
{
|
||||
internal class Program
|
||||
{
|
||||
public class NoOpCompletionHandler : ICompletionHandler
|
||||
{
|
||||
public void Complete(ITightEngineState state)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
static void Main(string[] args)
|
||||
{
|
||||
SqlMapper.AddTypeHandler(new GuidTypeHandler());
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureAppConfiguration((context, config) =>
|
||||
{
|
||||
config.SetBasePath(AppContext.BaseDirectory)
|
||||
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
||||
})
|
||||
.UseServiceProviderFactory(new AutofacServiceProviderFactory())
|
||||
.ConfigureContainer<ContainerBuilder>(containerBuilder =>
|
||||
{
|
||||
containerBuilder.RegisterType<StandardFunctionHandler>().As<IStandardFunctionHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<ScopeFunctionHandler>().As<IScopeFunctionHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<ProcessingInstructionFunctionHandler>().As<IProcessingInstructionFunctionHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<PostProcessingFunctionHandler>().As<IPostProcessingFunctionHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<MarkupHandler>().As<IMarkupHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<HeadingHandler>().As<IHeadingHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<CommentHandler>().As<ICommentHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<EmojiHandler>().As<IEmojiHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<ExternalLinkHandler>().As<IExternalLinkHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<InternalLinkHandler>().As<IInternalLinkHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<ExceptionHandler>().As<IExceptionHandler>().SingleInstance();
|
||||
containerBuilder.RegisterType<NoOpCompletionHandler>().As<ICompletionHandler>().SingleInstance();
|
||||
|
||||
containerBuilder.RegisterType<TightEngine>();
|
||||
}).Build();
|
||||
|
||||
|
||||
var configuration = host.Services.GetRequiredService<IConfiguration>();
|
||||
var services = new ServiceCollection();
|
||||
|
||||
services.AddLogging(configure => configure.AddConsole());
|
||||
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlite(configuration.GetConnectionString("UsersConnection")));
|
||||
|
||||
ManagedDataStorage.Pages.SetConnectionString(configuration.GetConnectionString("PagesConnection"));
|
||||
ManagedDataStorage.DeletedPages.SetConnectionString(configuration.GetConnectionString("DeletedPagesConnection"));
|
||||
ManagedDataStorage.DeletedPageRevisions.SetConnectionString(configuration.GetConnectionString("DeletedPageRevisionsConnection"));
|
||||
ManagedDataStorage.Statistics.SetConnectionString(configuration.GetConnectionString("StatisticsConnection"));
|
||||
ManagedDataStorage.Emoji.SetConnectionString(configuration.GetConnectionString("EmojiConnection"));
|
||||
ManagedDataStorage.Exceptions.SetConnectionString(configuration.GetConnectionString("ExceptionsConnection"));
|
||||
WordsRepository.Words.SetConnectionString(configuration.GetConnectionString("WordsConnection"));
|
||||
ManagedDataStorage.Users.SetConnectionString(configuration.GetConnectionString("UsersConnection"));
|
||||
ManagedDataStorage.Config.SetConnectionString(configuration.GetConnectionString("ConfigConnection"));
|
||||
|
||||
// Register Identity services
|
||||
services.AddIdentity<IdentityUser, IdentityRole>()
|
||||
.AddEntityFrameworkStores<ApplicationDbContext>()
|
||||
.AddDefaultTokenProviders();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
// Resolve the services
|
||||
var signInManager = serviceProvider.GetRequiredService<SignInManager<IdentityUser>>();
|
||||
var userManager = serviceProvider.GetRequiredService<UserManager<IdentityUser>>();
|
||||
var userStore = serviceProvider.GetRequiredService<IUserStore<IdentityUser>>();
|
||||
|
||||
ConfigurationRepository.ReloadEverything();
|
||||
|
||||
var pg = new PageGenerator(userManager);
|
||||
|
||||
var pool = new NTDLS.DelegateThreadPooling.DelegateThreadPool(4, 0);
|
||||
|
||||
while (true)
|
||||
{
|
||||
var workload = pool.CreateChildPool();
|
||||
|
||||
foreach (var user in pg.Users)
|
||||
{
|
||||
workload.Enqueue(() =>
|
||||
{
|
||||
using var scope = host.Services.CreateScope();
|
||||
var engine = scope.ServiceProvider.GetRequiredService<TightEngine>();
|
||||
|
||||
//Create a new page:
|
||||
pg.GeneratePage(engine, user.UserId);
|
||||
|
||||
//Modify existing pages:
|
||||
int modifications = pg.Random.Next(0, 10);
|
||||
for (int i = 0; i < modifications; i++)
|
||||
{
|
||||
pg.ModifyRandomPages(engine, user.UserId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
workload.WaitForCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
36
DummyPageGenerator/WordsRepository.cs
Normal file
36
DummyPageGenerator/WordsRepository.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using NTDLS.SqliteDapperWrapper;
|
||||
|
||||
namespace DummyPageGenerator
|
||||
{
|
||||
public static class WordsRepository
|
||||
{
|
||||
public static ManagedDataStorageFactory Words { get; private set; } = new();
|
||||
|
||||
public static int GetWordsCount()
|
||||
=> Words.ExecuteScalar<int>("GetWordsCount.sql");
|
||||
|
||||
public static List<string> GetRandomWords(int count)
|
||||
{
|
||||
var result = new List<string>();
|
||||
|
||||
var random = new Random();
|
||||
int countOfWords = GetWordsCount();
|
||||
|
||||
while (result.Count < count)
|
||||
{
|
||||
var param = new
|
||||
{
|
||||
Offset = random.Next(countOfWords),
|
||||
};
|
||||
|
||||
var word = Words.QueryFirstOrDefault<string>("GetSingleWordAt.sql", param);
|
||||
if (word != null)
|
||||
{
|
||||
result.Add(word);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
DummyPageGenerator/appsettings.Development.json
Normal file
9
DummyPageGenerator/appsettings.Development.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"DetailedErrors": true,
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
13
DummyPageGenerator/appsettings.json
Normal file
13
DummyPageGenerator/appsettings.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"PagesConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\pages.db",
|
||||
"DeletedPagesConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\deletedpages.db",
|
||||
"DeletedPageRevisionsConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\deletedpagerevisions.db",
|
||||
"StatisticsConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\statistics.db",
|
||||
"EmojiConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\emoji.db",
|
||||
"ExceptionsConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\exceptions.db",
|
||||
"WordsConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\words.db",
|
||||
"UsersConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\users.db",
|
||||
"ConfigConnection": "Data Source=C:\\NTDLS\\TightWiki\\TightWiki\\Data\\config.db"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user