mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-10 15:20:48 -05:00
implement RSS feed in auto messages for issue #53
modified automessages to use async mesthods instead of synchronous
This commit is contained in:
@ -1,20 +1,24 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace SharedLibraryCore.Helpers
|
||||
{
|
||||
public class MessageToken
|
||||
{
|
||||
public string Name { get; private set; }
|
||||
Func<Server, string> Value;
|
||||
public MessageToken(string Name, Func<Server, string> Value)
|
||||
private readonly Func<Server, Task<object>> _asyncValue;
|
||||
|
||||
|
||||
public MessageToken(string Name, Func<Server, Task<object>> Value)
|
||||
{
|
||||
this.Name = Name;
|
||||
this.Value = Value;
|
||||
_asyncValue = Value;
|
||||
}
|
||||
|
||||
public string Process(Server server)
|
||||
|
||||
public Task<object> ProcessAsync(Server server)
|
||||
{
|
||||
return this.Value(server);
|
||||
return _asyncValue(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -183,7 +183,7 @@ namespace SharedLibraryCore
|
||||
return CurrentLocalization.LocalizationIndex[$"GLOBAL_PERMISSION_{perm.ToString().ToUpper()}"];
|
||||
}
|
||||
|
||||
public static String ProcessMessageToken(this Server server, IList<Helpers.MessageToken> tokens, String str)
|
||||
public async static Task<string> ProcessMessageToken(this Server server, IList<Helpers.MessageToken> tokens, String str)
|
||||
{
|
||||
MatchCollection RegexMatches = Regex.Matches(str, @"\{\{[A-Z]+\}\}", RegexOptions.IgnoreCase);
|
||||
foreach (Match M in RegexMatches)
|
||||
@ -195,7 +195,7 @@ namespace SharedLibraryCore
|
||||
|
||||
if (found != null)
|
||||
{
|
||||
str = str.Replace(Match, found.Process(server));
|
||||
str = str.Replace(Match, (await found.ProcessAsync(server)).ToString());
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user