123123
This commit is contained in:
@@ -47,7 +47,8 @@ namespace DummyPageGenerator
|
||||
{
|
||||
for (int i = 0; i < 1124 - _users.Count; i++)
|
||||
{
|
||||
string emailAddress = WordsRepository.GetRandomWords(1).First() + "@" + WordsRepository.GetRandomWords(1).First() + ".com";
|
||||
string emailAddress = WordsRepository.GetRandomWords(1).First() + "@" +
|
||||
WordsRepository.GetRandomWords(1).First() + ".com";
|
||||
CreateUserAndProfile(emailAddress);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ namespace DummyPageGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a user and the associated profile with claims and such.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="emailAddress"></param>
|
||||
/// <exception cref="Exception"></exception>
|
||||
@@ -80,7 +81,8 @@ namespace DummyPageGenerator
|
||||
Email = emailAddress
|
||||
};
|
||||
|
||||
var result = _userManager.CreateAsync(user, WordsRepository.GetRandomWords(1).First() + Guid.NewGuid().ToString()).Result;
|
||||
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)));
|
||||
@@ -92,18 +94,18 @@ namespace DummyPageGenerator
|
||||
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()),
|
||||
};
|
||||
{
|
||||
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>
|
||||
@@ -118,7 +120,7 @@ namespace DummyPageGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a paragraph/sentence structure with links and wiki markup.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="wordCount"></param>
|
||||
/// <returns></returns>
|
||||
@@ -135,18 +137,19 @@ namespace DummyPageGenerator
|
||||
|
||||
switch (_random.Next(0, 7))
|
||||
{
|
||||
case 2: //Dead link.
|
||||
case 2:
|
||||
paragraph = paragraph.Replace(token, $"[[{token}]]");
|
||||
break;
|
||||
case 4: //Wiki markup.
|
||||
case 4:
|
||||
paragraph = paragraph.Replace(token, AddWikiMarkup(token));
|
||||
break;
|
||||
case 6: //Good link.
|
||||
case 6:
|
||||
var recentPage = GetRandomRecentPageName();
|
||||
if (recentPage != null)
|
||||
{
|
||||
paragraph = paragraph.Replace(token, $"[[{recentPage}]]");
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -163,7 +166,7 @@ namespace DummyPageGenerator
|
||||
return null;
|
||||
}
|
||||
|
||||
if (_recentPageNames.Count > 200) //Shuffle and limit the recent page names.
|
||||
if (_recentPageNames.Count > 200)
|
||||
{
|
||||
_recentPageNames = ShuffleList(_recentPageNames).Take(100).ToList();
|
||||
}
|
||||
@@ -176,7 +179,7 @@ namespace DummyPageGenerator
|
||||
{
|
||||
lock (_pagePool)
|
||||
{
|
||||
if (_recentPageNames.Count > 200) //Shuffle and limit the recent page names.
|
||||
if (_recentPageNames.Count > 200)
|
||||
{
|
||||
_recentPageNames = ShuffleList(_recentPageNames).Take(100).ToList();
|
||||
}
|
||||
@@ -186,6 +189,7 @@ namespace DummyPageGenerator
|
||||
{
|
||||
pageNames.Add(_recentPageNames[_random.Next(0, _recentPageNames.Count)]);
|
||||
}
|
||||
|
||||
return pageNames;
|
||||
}
|
||||
}
|
||||
@@ -199,8 +203,9 @@ namespace DummyPageGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a random page on the wiki.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="engine"></param>
|
||||
/// <param name="userId"></param>
|
||||
public void GeneratePage(IZelEngine engine, Guid userId)
|
||||
{
|
||||
@@ -216,7 +221,8 @@ namespace DummyPageGenerator
|
||||
|
||||
var body = new StringBuilder();
|
||||
|
||||
body.AppendLine($"##title ##Tag(" + string.Join(' ', ShuffleList(_tags).Take(_random.Next(1, 4))) + ")");
|
||||
body.AppendLine($"##title ##Tag(" + string.Join(' ', ShuffleList(_tags).Take(_random.Next(1, 4))) +
|
||||
")");
|
||||
body.AppendLine($"##toc");
|
||||
|
||||
body.AppendLine($"==Overview");
|
||||
@@ -232,7 +238,6 @@ namespace DummyPageGenerator
|
||||
|
||||
if (_random.Next(100) >= 95)
|
||||
{
|
||||
//Add dead links (missing pages).
|
||||
textWithLinks.AddRange(WordsRepository.GetRandomWords(_random.Next(1, 2)).Select(o => $"[[{o}]]"));
|
||||
}
|
||||
|
||||
@@ -258,7 +263,8 @@ namespace DummyPageGenerator
|
||||
|
||||
if (_random.Next(100) >= 70)
|
||||
{
|
||||
var fileName = _fileNames[_random.Next(_fileNames.Count)] + ".txt"; ;
|
||||
var fileName = _fileNames[_random.Next(_fileNames.Count)] + ".txt";
|
||||
;
|
||||
var fileData = Encoding.UTF8.GetBytes(page.Body);
|
||||
AttachFile(newPageId, userId, fileName, fileData);
|
||||
}
|
||||
@@ -288,7 +294,7 @@ namespace DummyPageGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modifies a random page on the wiki.
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
public void ModifyRandomPages(IZelEngine engine, Guid userId)
|
||||
@@ -312,8 +318,8 @@ namespace DummyPageGenerator
|
||||
string bottomText = pageToModify.Body.Substring(endIndex);
|
||||
|
||||
pageToModify.Body = topText.Trim()
|
||||
+ "\r\n" + GenerateWikiParagraph(_random.Next(10, 20))
|
||||
+ "\r\n" + bottomText.Trim();
|
||||
+ "\r\n" + GenerateWikiParagraph(_random.Next(10, 20))
|
||||
+ "\r\n" + bottomText.Trim();
|
||||
pageToModify.ModifiedByUserId = userId;
|
||||
pageToModify.ModifiedByUserId = userId;
|
||||
Helpers.UpsertPage(engine, pageToModify);
|
||||
@@ -328,12 +334,13 @@ namespace DummyPageGenerator
|
||||
}
|
||||
|
||||
/// <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>
|
||||
/// <exception cref="Exception"></exception>
|
||||
private void AttachFile(int pageId, Guid userId, string fileName, byte[] fileData)
|
||||
{
|
||||
if (fileData.Length > GlobalConfiguration.MaxAttachmentFileSize)
|
||||
@@ -372,6 +379,7 @@ namespace DummyPageGenerator
|
||||
newList[k] = newList[n];
|
||||
newList[n] = value;
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
@@ -397,4 +405,4 @@ namespace DummyPageGenerator
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user