Moving experiment files to external class library for use in production systems
This commit is contained in:
+37
@@ -0,0 +1,37 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
|
||||
public class EndsWithAction : IExternalAction
|
||||
{
|
||||
public string SearchForString { get; set; }
|
||||
|
||||
public Action<FormBase, string> SetProperty { get; set; }
|
||||
|
||||
Func<String, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
|
||||
public EndsWithAction(string searchFor, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
SearchForString = searchFor;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data) => raw_data.EndsWith(SearchForString);
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(mr.RawData, ur, mr);
|
||||
|
||||
}
|
||||
|
||||
public static class EndsWithAction_Extensions
|
||||
{
|
||||
public static void AddEndsWithAction(this ExternalActionManager manager, string value, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new EndsWithAction(value, action));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+94
@@ -0,0 +1,94 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
public class GuidAction : IExternalAction
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
Guid? _lastValue { get; set; }
|
||||
|
||||
Func<Guid, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public GuidAction(string method, Func<Guid, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
Guid g;
|
||||
|
||||
if (Guid.TryParse(cd.Value, out g))
|
||||
_lastValue = g;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
|
||||
public static CallbackData GetCallback(string method, Guid guid) => new CallbackData(method, guid.ToString());
|
||||
|
||||
}
|
||||
|
||||
public class GuidAction<TForm> : IExternalAction
|
||||
where TForm : FormBase
|
||||
{
|
||||
public string Method { get; set; }
|
||||
|
||||
Guid? _lastValue { get; set; }
|
||||
|
||||
Func<Guid, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
public GuidAction(string method, Func<Guid, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
Method = method;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data)
|
||||
{
|
||||
var cd = CallbackData.Deserialize(raw_data);
|
||||
|
||||
if (cd == null)
|
||||
return false;
|
||||
|
||||
if (cd.Method != Method)
|
||||
return false;
|
||||
|
||||
Guid g;
|
||||
|
||||
if (Guid.TryParse(cd.Value, out g))
|
||||
_lastValue = g;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(_lastValue.Value, ur, mr);
|
||||
|
||||
|
||||
public static CallbackData GetCallback(string method, Guid guid) => new CallbackData(method, guid.ToString());
|
||||
|
||||
}
|
||||
|
||||
public static class GuidAction_Extensions
|
||||
{
|
||||
|
||||
public static void AddGuidAction(this ExternalActionManager manager, string method, Func<Guid, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new GuidAction(method, action));
|
||||
}
|
||||
}
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
using TelegramBotBase.Base;
|
||||
using TelegramBotBase.Form;
|
||||
|
||||
namespace TelegramBotBase.Experiments.ActionManager.Actions
|
||||
{
|
||||
|
||||
public class StartWithAction : IExternalAction
|
||||
{
|
||||
public string SearchForString { get; set; }
|
||||
|
||||
public Action<FormBase, string> SetProperty { get; set; }
|
||||
|
||||
Func<String, UpdateResult, MessageResult, Task> Action;
|
||||
|
||||
|
||||
public StartWithAction(string searchFor, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
SearchForString = searchFor;
|
||||
Action = action;
|
||||
}
|
||||
|
||||
public bool DoesFit(string raw_data) => raw_data.StartsWith(SearchForString);
|
||||
|
||||
|
||||
public async Task DoAction(UpdateResult ur, MessageResult mr) => await Action(mr.RawData, ur, mr);
|
||||
|
||||
}
|
||||
|
||||
public static class StartWithAction_Extensions
|
||||
{
|
||||
public static void AddStartsWithAction(this ExternalActionManager manager, string value, Func<String, UpdateResult, MessageResult, Task> action)
|
||||
{
|
||||
manager.Add(new StartWithAction(value, action));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user