- Added ToggleButton as an easy switch control (i.e. for settings page)

- added control id, for easier separating of controls in one form
- added automatic event selection for specific controls, to not raise an event for other controls who has invoked it
- changed Action method
- added example
This commit is contained in:
FlorianDahn
2019-08-23 14:02:24 +02:00
parent 805ffb9ec7
commit 56c7754408
9 changed files with 246 additions and 11 deletions
+11 -1
View File
@@ -15,18 +15,28 @@ namespace TelegramBotBase.Base
public int ID { get; set; }
public String ControlID
{
get
{
return "#c" + this.ID.ToString();
}
}
/// <summary>
/// Defines if the control should be rendered and invoked with actions
/// </summary>
public bool Enabled { get; set; } = true;
public virtual async Task Action(MessageResult result)
public virtual async Task Action(MessageResult result, String value = null)
{
}
public virtual async Task Render(MessageResult result)
{
+12 -1
View File
@@ -55,7 +55,7 @@ namespace TelegramBotBase.Form
return;
var handler = this.Events[__evInit].GetInvocationList().Cast<AsyncEventHandler<InitEventArgs>>();
foreach(var h in handler)
foreach (var h in handler)
{
await Async.InvokeAllAsync<InitEventArgs>(h, this, e);
}
@@ -169,6 +169,17 @@ namespace TelegramBotBase.Form
/// <returns></returns>
public async Task ActionControls(MessageResult message)
{
//Looking for the control by id, if not listened, raise event for all
if (message.RawData.StartsWith("#c"))
{
var c = this.Controls.FirstOrDefault(a => a.ControlID == message.RawData.Split('_')[0]);
if (c != null)
{
await c.Action(message, message.RawData.Split('_')[1]);
return;
}
}
foreach (var b in this.Controls)
{
if (!b.Enabled)